Skip to content

Commit cec2a6d

Browse files
committed
Added updates based on code review
- test scenario labels updated - pep8 compliance changes - changed some var to more descriptive names
1 parent d447c4e commit cec2a6d

File tree

7 files changed

+66
-64
lines changed

7 files changed

+66
-64
lines changed

roles/telemetry_chargeback/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ These variables are used internally by the role and typically do not need to be
5151
| `cloudkitty_loki_totals_metrics_suffix` | `-loki_metrics_totals.yml` | Suffix for metric totals computed from Loki-retrieved JSON (retrieve_loki_data task). |
5252
| `cloudkitty_synth_script` | `{{ role_path }}/files/gen_synth_loki_data.py` | Path to the synthetic data generation script. |
5353
| `cloudkitty_data_template` | `{{ role_path }}/templates/loki_data_templ.j2` | Path to the Jinja2 template for Loki data format. |
54-
| `cloudkitty_totals_script` | `{{ role_path }}/files/gen_synth_loki_metrics_totals.py` | Path to the metric totals calculation script. |
54+
| `cloudkitty_summary_script` | `{{ role_path }}/files/gen_db_summary.py` | Path to the summary script (gen_db_summary.py). |
5555

5656
### Loki / OpenShift Variables (vars/main.yml)
5757

roles/telemetry_chargeback/files/gen_db_summary.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ def _extract_from_loki_json(data: dict) -> list[tuple[str, str]]:
4444
continue
4545
ts_str = val[0]
4646
log_str = val[1]
47-
if not isinstance(ts_str, str) or not isinstance(log_str, str):
48-
continue
49-
if not _is_valid_timestep(ts_str):
47+
if not _is_valid_timestep(ts_str) or not isinstance(log_str, str):
5048
continue
49+
5150
try:
5251
entry = json.loads(log_str)
5352
if isinstance(entry, dict) and _has_required_keys(entry):

roles/telemetry_chargeback/files/gen_synth_loki_data.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import argparse
44
import json
5+
import sys
56
import yaml
67
from datetime import datetime, timezone, timedelta
78
from pathlib import Path
@@ -108,8 +109,8 @@ def generate_loki_data(
108109
end_time: datetime,
109110
time_step_seconds: int,
110111
config: Dict[str, Any],
111-
project_id: Union[str, int, None] = None,
112-
user_id: Union[str, int, None] = None,
112+
project: Union[str, int, None] = None,
113+
user: Union[str, int, None] = None,
113114
reverse_timestamps: bool = False,
114115
):
115116
"""
@@ -122,9 +123,9 @@ def generate_loki_data(
122123
end_time (datetime): The end time for data generation.
123124
time_step_seconds (int): The duration of each log entry in seconds.
124125
config (Dict[str, Any]): Configuration dictionary loaded from file.
125-
project_id: Optional value to inject as groupby.project_id in every
126+
project: Optional value to inject as groupby.project in every
126127
log entry in the output (overrides test_* file value when set).
127-
user_id: Optional value to inject as groupby.user_id in every
128+
user: Optional value to inject as groupby.user in every
128129
log entry in the output (overrides test_* file value when set).
129130
reverse_timestamps (bool): If True, reverse the order of timestamps
130131
in the JSON output (youngest first, oldest last).
@@ -324,10 +325,10 @@ def tojson_preserve_order(obj):
324325
log_type_with_dates = log_type_data.copy()
325326
log_type_with_dates["groupby"] = log_type_data["groupby"].copy()
326327
log_type_with_dates["groupby"].update(date_fields)
327-
if project_id is not None:
328-
log_type_with_dates["groupby"]["project_id"] = project_id
329-
if user_id is not None:
330-
log_type_with_dates["groupby"]["user_id"] = user_id
328+
if project is not None:
329+
log_type_with_dates["groupby"]["project"] = project
330+
if user is not None:
331+
log_type_with_dates["groupby"]["user"] = user
331332
# Select qty and price based on step index distribution
332333
log_type_with_dates["qty"] = _get_value_for_step(
333334
log_type_data["qty"], idx, num_steps
@@ -408,15 +409,15 @@ def main():
408409
type=str,
409410
default=None,
410411
metavar="ID",
411-
help="Optional alphanumeric value to use as groupby.project_id in "
412+
help="Optional alphanumeric value to use as groupby.project in "
412413
"every log entry in the output (overrides value from test file)."
413414
)
414415
parser.add_argument(
415416
"-u", "--user-id",
416417
type=str,
417418
default=None,
418419
metavar="ID",
419-
help="Optional alphanumeric value to use as groupby.user_id in "
420+
help="Optional alphanumeric value to use as groupby.user in "
420421
"every log entry in the output (overrides value from test file)."
421422
)
422423

@@ -464,8 +465,8 @@ def main():
464465
end_time=end_time_utc,
465466
time_step_seconds=step_seconds,
466467
config=config,
467-
project_id=args.project_id,
468-
user_id=args.user_id,
468+
project=args.project_id,
469+
user=args.user_id,
469470
reverse_timestamps=args.reverse,
470471
)
471472
except FileNotFoundError:

roles/telemetry_chargeback/files/test_dyn_basic.yml

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ generation:
99
# Log type definitions (single "type" = identifier and value pushed to output)
1010
log_types:
1111
- type: ceilometer_image_size
12-
unit: MiB
1312
description: "Size of ceilometer image"
13+
unit: MiB
14+
factor: 1/1048576
1415
qty:
1516
- 20.6
1617
- 25.0
@@ -23,103 +24,104 @@ log_types:
2324
- 0.07
2425
- 0.10
2526
groupby:
26-
id: null
27-
user_id: null
28-
project_id: null
29-
tenant_id: tenant-01
27+
resource: null
28+
user: null
29+
project: null
30+
tenant: tenant-01
3031
metadata:
3132
container_format: bare
3233
disk_format: qcow2
3334

34-
- type: ceilometer_cpu_num
35-
unit: scalar
35+
- type: ceilometer_cpu
3636
description: "max number of cpus used in time step"
37+
unit: instance
38+
alt_name: instance
3739
qty:
3840
- 1.0
3941
price:
4042
- 0.3
4143
groupby:
42-
id: null
43-
user_id: null
44-
project_id: null
45-
tenant_id: tenant-02
46-
metadata:
47-
flavor_name: m1.tiny
48-
flavor_id: "1"
49-
vcpus: ""
44+
resource: null
45+
user: null
46+
project: null
47+
tenant: tenant-02
48+
flavor_name: null
49+
flavor_id: null
50+
mutate: NUMBOOL
5051

5152
- type: ceilometer_ip_floating
52-
unit: ip
5353
description: null
54+
unit: ip
5455
qty:
5556
- 0.0
5657
price:
5758
- 0.50
5859
groupby:
59-
id: null
60-
user_id: null
61-
project_id: null
62-
tenant_id: tenant-01
60+
resource: null
61+
user: null
62+
project: null
63+
tenant: tenant-01
6364
metadata:
6465
state: null
66+
mutate: NUMBOOL
6567

6668
- type: ceilometer_disk_ephemeral_size
67-
unit: GiB
6869
description: "Max at each timestep"
70+
unit: GiB
6971
qty:
7072
- 0.0
7173
price:
7274
- 0.0
7375
groupby:
74-
id: null
75-
user_id: null
76-
project_id: null
77-
tenant_id: tenant-01
76+
resource: null
77+
user: null
78+
project: null
79+
tenant: tenant-01
7880
metadata:
7981
type: null
8082

81-
- type: ceilometer-disk-root_size
82-
unit: GiB
83+
- type: ceilometer_disk_root_size
8384
description: null
85+
unit: GiB
8486
qty:
8587
- 0.0
8688
price:
8789
- 0.0
8890
groupby:
89-
id: null
90-
user_id: null
91-
project_id: null
92-
tenant_id: tenant-02
91+
resource: null
92+
user: null
93+
project: null
94+
tenant: tenant-02
9395
metadata:
94-
disk_format: null
96+
type: null
9597

9698
- type: ceilometer_network_outgoing_bytes
97-
unit: B
9899
description: null
100+
unit: B
99101
qty:
100102
- 0.0
101103
price:
102104
- 0.0
103105
groupby:
104-
id: null
105-
user_id: null
106-
project_id: null
107-
tenant_id: tenant-01
106+
resource: null
107+
user: null
108+
project: null
109+
tenant: tenant-01
108110
metadata:
109111
vm_instance: null
110112

111113
- type: ceilometer_network_incoming_bytes
112-
unit: B
113114
description: null
115+
unit: B
114116
qty:
115117
- 0.0
116118
price:
117119
- 0.0
118120
groupby:
119-
id: null
120-
user_id: null
121-
project_id: null
122-
tenant_id: tenant-02
121+
resource: null
122+
user: null
123+
project: null
124+
tenant: tenant-02
123125
metadata:
124126
vm_instance: null
125127

roles/telemetry_chargeback/tasks/gen_synth_loki_data.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
- name: "Generate chargeback rating from synthetic data file {{ item }}"
2727
ansible.builtin.command:
2828
cmd: >
29-
python3 "{{ cloudkitty_totals_script }}"
29+
python3 "{{ cloudkitty_summary_script }}"
3030
-j "{{ cloudkitty_data_file }}"
3131
-o "{{ cloudkitty_synth_totals_file }}"
3232
--debug "{{ cloudkitty_debug_dir }}"

roles/telemetry_chargeback/tasks/retrieve_loki_data.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
- name: "Generate chargeback stats from Loki-retrieved data file: {{ item }}"
6464
ansible.builtin.command:
6565
cmd: >
66-
python3 "{{ cloudkitty_totals_script }}"
66+
python3 "{{ cloudkitty_summary_script }}"
6767
-j "{{ artifacts_dir_zuul }}/{{ item }}{{ cloudkitty_loki_data_suffix }}"
6868
-o "{{ artifacts_dir_zuul }}/{{ item }}{{ cloudkitty_loki_totals_metrics_suffix }}"
6969
--debug "{{ cloudkitty_debug_dir }}"

roles/telemetry_chargeback/vars/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ cloudkitty_debug: false
88
cloudkitty_scenario_dir: "{{ role_path }}/files"
99
cloudkitty_synth_data_suffix: "-synth_data.json"
1010
cloudkitty_loki_data_suffix: "-loki_data.json"
11-
cloudkitty_synth_totals_metrics_suffix: "-synth_metrics_totals.yml"
12-
cloudkitty_loki_totals_metrics_suffix: "-loki_metrics_totals.yml"
13-
cloudkitty_loki_totals_suffix: "-loki_totals.yml"
11+
cloudkitty_synth_totals_metrics_suffix: "-synth_metrics_summary.yml"
12+
cloudkitty_loki_totals_metrics_suffix: "-loki_metrics_summary.yml"
13+
cloudkitty_loki_totals_suffix: "-rating.yml"
1414

1515
cloudkitty_synth_script: "{{ role_path }}/files/gen_synth_loki_data.py"
1616
cloudkitty_data_template: "{{ role_path }}/templates/loki_data_templ.j2"
17-
cloudkitty_totals_script: "{{ role_path }}/files/gen_db_summary.py"
17+
cloudkitty_summary_script: "{{ role_path }}/files/gen_db_summary.py"
1818

1919
# Cloudkitty certificates
2020
cert_secret_name: "cert-cloudkitty-client-internal"

0 commit comments

Comments
 (0)