Skip to content

Commit c5ee60a

Browse files
committed
feat(metrics): store dimensions alongside metrics in store_data
In d6e5521b we added a metrics.json to dump all emitted metrics, but we don't add the dimensions to easily parse and know to know to what they refer. This patch changes the format of the metrics.json to add two keys: metrics, contanining the old dict of metrics, and dimensions, contiaining the dict of dimensions. We're not storing all other properties as they are the same across all tests on the same executor and they can be fetched from test_result.json already, under "user_properties". Signed-off-by: Riccardo Mancini <[email protected]>
1 parent 1dac3b6 commit c5ee60a

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

tests/host_tools/metrics.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,25 @@ class MetricsWrapper:
5757
"""A convenient metrics logger"""
5858

5959
def __init__(self, logger):
60-
self.data = {}
60+
self.metrics = {}
61+
self.dimensions = {}
6162
self.logger = logger
6263

63-
def set_dimensions(self, *args, **kwargs):
64+
def set_dimensions(self, *dimensions, **kwargs):
6465
"""Set dimensions"""
6566
if self.logger:
66-
self.logger.set_dimensions(*args, **kwargs)
67+
self.logger.set_dimensions(*dimensions, **kwargs)
68+
69+
self.dimensions = {}
70+
for dimension_dict in dimensions:
71+
for k, v in dimension_dict.items():
72+
self.dimensions[k] = v
6773

6874
def put_metric(self, name, data, unit):
6975
"""Put a datapoint with given dimensions"""
70-
if name not in self.data:
71-
self.data[name] = {"unit": unit, "values": []}
72-
self.data[name]["values"].append(data)
76+
if name not in self.metrics:
77+
self.metrics[name] = {"unit": unit, "values": []}
78+
self.metrics[name]["values"].append(data)
7379

7480
if self.logger:
7581
self.logger.put_metric(name, data, unit)
@@ -88,7 +94,13 @@ def store_data(self, dir_path):
8894
"""Store data into a file"""
8995
metrics_path = Path(dir_path / "metrics.json")
9096
with open(metrics_path, "w", encoding="utf-8") as f:
91-
json.dump(self.data, f)
97+
json.dump(
98+
{
99+
"metrics": self.metrics,
100+
"dimensions": self.dimensions,
101+
},
102+
f,
103+
)
92104

93105

94106
def get_metrics_logger():

0 commit comments

Comments
 (0)