Skip to content
Snippets Groups Projects
Commit 6d8d88a6 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

**bugfix**: A RUNTIME parent does not display DEBUG child's metric

parent eb9ec669
No related branches found
No related tags found
No related merge requests found
# v2.14.13 # v2.14.13
* **bugfix**: A RUNTIME parent does not display DEBUG child's metric
...@@ -35,6 +35,9 @@ INHERIT is the default state for all other metrics than root, ...@@ -35,6 +35,9 @@ INHERIT is the default state for all other metrics than root,
for root the default is RUNTIME. Root metric cannot be set to INHERIT, for root the default is RUNTIME. Root metric cannot be set to INHERIT,
as it would not make sense. as it would not make sense.
Also, if parent is RUNTIME and child is DEBUG, the metrics reported by the child won't be included
in parent metric data.
You can switch the metric anytime by assigning a correct value to You can switch the metric anytime by assigning a correct value to
it's ``level`` property, or by specifying it's metric level during a call to ``getMetric()``. it's ``level`` property, or by specifying it's metric level during a call to ``getMetric()``.
......
__version__ = '2.14.13_a1' __version__ = '2.14.13'
...@@ -117,7 +117,8 @@ class Metric: ...@@ -117,7 +117,8 @@ class Metric:
def to_metric_data(self) -> MetricDataCollection: def to_metric_data(self) -> MetricDataCollection:
output = MetricDataCollection() output = MetricDataCollection()
for child in self.children: for child in self.children:
output += child.to_metric_data() if child.level <= self.level:
output += child.to_metric_data()
output.prefix_with(self.name) output.prefix_with(self.name)
if self.enable_timestamp: if self.enable_timestamp:
...@@ -219,7 +220,8 @@ class EmbeddedSubmetrics(LeafMetric): ...@@ -219,7 +220,8 @@ class EmbeddedSubmetrics(LeafMetric):
if self.embedded_submetrics_enabled: if self.embedded_submetrics_enabled:
v = MetricDataCollection() v = MetricDataCollection()
for child in self.children: for child in self.children:
v = v + child.to_metric_data() if child.level <= self.level:
v = v + child.to_metric_data()
return v return v
else: else:
return super().to_metric_data() return super().to_metric_data()
...@@ -239,3 +241,7 @@ class EmbeddedSubmetrics(LeafMetric): ...@@ -239,3 +241,7 @@ class EmbeddedSubmetrics(LeafMetric):
return self.__class__(self.name, self, MetricLevel.INHERIT, *self.args, labels=labels, return self.__class__(self.name, self, MetricLevel.INHERIT, *self.args, labels=labels,
**self.kwargs) **self.kwargs)
from .registry import register_metric
register_metric(Metric)
...@@ -20,6 +20,15 @@ def choose(postfix: str, mdc: MetricDataCollection, labels=None) -> MetricData: ...@@ -20,6 +20,15 @@ def choose(postfix: str, mdc: MetricDataCollection, labels=None) -> MetricData:
class TestMetric(unittest.TestCase): class TestMetric(unittest.TestCase):
def test_child_metrics(self):
"""A RUNTIME parent does not display DEBUG child's metric"""
parent = getMetric('test.child.metric', metric_level=MetricLevel.RUNTIME)
child = getMetric('test.child.metric.kid', 'int', metric_level=MetricLevel.DEBUG)
child.runtime(2)
data = parent.to_metric_data()
kid = choose('.kid', data)
self.assertIsNone(kid)
def test_uptime_metric(self): def test_uptime_metric(self):
up_metric = getMetric('uptime.metric', 'uptime') up_metric = getMetric('uptime.metric', 'uptime')
time.sleep(1) time.sleep(1)
...@@ -250,6 +259,8 @@ class TestMetric(unittest.TestCase): ...@@ -250,6 +259,8 @@ class TestMetric(unittest.TestCase):
counter.to_metric_data())) counter.to_metric_data()))
def test_base_metric(self): def test_base_metric(self):
root_metric = getMetric()
root_metric.level = MetricLevel.DEBUG
metric2 = getMetric('root.test.FloatValue', 'float', MetricLevel.DEBUG, enable_timestamp=False) metric2 = getMetric('root.test.FloatValue', 'float', MetricLevel.DEBUG, enable_timestamp=False)
metric2.runtime(2.0) metric2.runtime(2.0)
metric2.debug(1.0) metric2.debug(1.0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment