Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store units in results #938

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions esrally/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,16 +732,17 @@ def get_raw(self, name, task=None, operation_type=None, sample_type=None, node_n
"""
return self._get(name, task, operation_type, sample_type, node_name, mapper)

def get_unit(self, name, task=None):
def get_unit(self, name, task=None, node_name=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see this used in the PR, was it just added in case we need to use it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I added it in 11364ad.

"""
Gets the unit for the given metric name.

:param name: The metric name to query.
:param task The task name to query. Optional.
:param node_name The name of the node where this metric was gathered. Optional.
:return: The corresponding unit for the given metric name or None if no metric record is available.
"""
# does not make too much sense to ask for a sample type here
return self._first_or_none(self._get(name, task, None, None, None, lambda doc: doc["unit"]))
return self._first_or_none(self._get(name, task, None, None, node_name, lambda doc: doc["unit"]))

def _get(self, name, task, operation_type, sample_type, node_name, mapper):
raise NotImplementedError("abstract method")
Expand Down Expand Up @@ -1772,11 +1773,13 @@ def single_latency(self, task, metric_name="latency"):
mean = self.store.get_mean(metric_name,
task=task,
sample_type=sample_type)
unit = self.store.get_unit(metric_name, task=task)
stats = collections.OrderedDict()
for k, v in percentiles.items():
# safely encode so we don't have any dots in field names
stats[encode_float_key(k)] = v
stats["mean"] = mean
stats["unit"] = unit
return stats
else:
return {}
Expand Down Expand Up @@ -1917,9 +1920,10 @@ def __call__(self):

def add(self, result, raw_metric_key, summary_metric_key):
metric_value = self.store.get_one(raw_metric_key, node_name=self.node_name)
metric_unit = self.store.get_unit(raw_metric_key, node_name=self.node_name)
if metric_value:
self.logger.debug("Adding record for [%s] with value [%s].", raw_metric_key, str(metric_value))
result.add_node_metrics(self.node_name, summary_metric_key, metric_value)
result.add_node_metrics(self.node_name, summary_metric_key, metric_value, metric_unit)
else:
self.logger.debug("Skipping incomplete [%s] record.", raw_metric_key)

Expand All @@ -1931,12 +1935,14 @@ def __init__(self, d=None):
def v(self, d, k, default=None):
return d.get(k, default) if d else default

def add_node_metrics(self, node, name, value):
def add_node_metrics(self, node, name, value, unit):
metric = {
"node": node,
"name": name,
"value": value
}
if unit:
metric["unit"] = unit
self.node_metrics.append(metric)

def as_flat_list(self):
Expand Down
9 changes: 6 additions & 3 deletions tests/metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,8 +1581,10 @@ def test_calculate_global_stats(self):
opm = stats.metrics("index #1")
self.assertEqual(collections.OrderedDict(
[("min", 500), ("mean", 1125), ("median", 1000), ("max", 2000), ("unit", "docs/s")]), opm["throughput"])
self.assertEqual(collections.OrderedDict([("50_0", 220), ("100_0", 225), ("mean", 215)]), opm["latency"])
self.assertEqual(collections.OrderedDict([("50_0", 200), ("100_0", 210), ("mean", 200)]), opm["service_time"])
self.assertEqual(collections.OrderedDict(
[("50_0", 220), ("100_0", 225), ("mean", 215), ("unit", "ms")]), opm["latency"])
self.assertEqual(collections.OrderedDict(
[("50_0", 200), ("100_0", 210), ("mean", 200), ("unit", "ms")]), opm["service_time"])
self.assertAlmostEqual(0.3333333333333333, opm["error_rate"])

self.assertEqual(1, len(stats.ml_processing_time))
Expand Down Expand Up @@ -1625,7 +1627,8 @@ def test_calculate_system_stats(self):
{
"node": "rally-node-0",
"name": "index_size",
"value": 2048
"value": 2048,
"unit": "bytes"
}
], stats.node_metrics)

Expand Down