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

API rename

parent 0a9a9189
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
* a bug fixed in `satella.instrumentation.metrics.json`
* added counting total amount of calls and total time
* removed `StringMetric`, as it is not readily Prometheus-exportable
* `PercentileMetric` renamed to `QuantileMetric`
# v2.3.2
......
......@@ -14,7 +14,7 @@ modules or classes. It can be in one of 3 states:
* DEBUG
* INHERIT
By default, it runs in _runtime_ mode. This means that statistics
By default, it runs in *RUNTIME* mode. This means that statistics
are collected only from metrics of this
instrument that are set to at least RUNTIME. If a user wants to
dig deeper, it can switch the instrument to
......@@ -25,8 +25,8 @@ parent, traversing the tree if required.
INHERIT is the default state for all other metrics than root,
for root the default is RUNTIME.
You can switch the metric anytime by calling it's ``switch_level``
method, or by specifying it's metric level during a call to ``getMetric()``.
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()``.
Note that a decision to accept/reject a ``handle()``-provided value happens
when ``handle()`` is called, based on current level. If you change
......@@ -52,10 +52,10 @@ are available:
.. autoclass:: satella.instrumentation.metrics.metric_types.ClicksPerTimeUnitMetric
* percentile - a metric that counts a rolling window of values,
* quantile - a metric that counts a rolling window of values,
and provides for a way to calculate percentiles
.. autoclass:: satella.instrumentation.metrics.metric_types.PercentileMetric
.. autoclass:: satella.instrumentation.metrics.metric_types.QuantileMetric
Third parameter is optional. If set, all child metrics created
during this metric's instantiation will receive such metric level.
......
from .base import Metric, LeafMetric, RUNTIME, DISABLED, INHERIT, DEBUG, EmbeddedSubmetrics
from .cps import ClicksPerTimeUnitMetric
from .simple import IntegerMetric, FloatMetric
from .percentile import PercentileMetric
from .quantile import QuantileMetric
from .registry import register_metric, METRIC_NAMES_TO_CLASSES
__all__ = ['Metric', 'LeafMetric', 'EmbeddedSubmetrics', 'RUNTIME', 'DEBUG', 'INHERIT',
'DISABLED', 'ClicksPerTimeUnitMetric', 'IntegerMetric', 'FloatMetric',
'PercentileMetric', 'register_metric', 'METRIC_NAMES_TO_CLASSES']
'QuantileMetric', 'register_metric', 'METRIC_NAMES_TO_CLASSES']
......@@ -34,7 +34,7 @@ def percentile(n: tp.List[float], percent: float) -> float:
@register_metric
class PercentileMetric(EmbeddedSubmetrics):
class QuantileMetric(EmbeddedSubmetrics):
"""
A metric that can register some values, sequentially, and then calculate percentiles from it
......@@ -44,7 +44,7 @@ class PercentileMetric(EmbeddedSubmetrics):
:param count_calls: whether to count total amount of calls and total time
"""
CLASS_NAME = 'percentile'
CLASS_NAME = 'quantile'
def __init__(self, name, root_metric: 'Metric' = None, metric_level: str = None,
last_calls: int = 100, percentiles: tp.Sequence[float] = (0.5, 0.95),
......
......@@ -12,8 +12,8 @@ class TestMetric(unittest.TestCase):
def tearDown(self):
getMetric('').reset()
def test_percentile_children(self):
metric = getMetric('my_metric', 'percentile', percentiles=[0.5])
def test_quantile_children(self):
metric = getMetric('my_metric', 'quantile', quantiles=[0.5])
metric.runtime(10.0, label='value')
metric.runtime(20.0, label='wtf')
metr = metric.to_json()
......@@ -21,8 +21,8 @@ class TestMetric(unittest.TestCase):
self.assertEqual(metr['count']['_'], 2)
self.assertEqual(metr['total']['_'], 30.0)
def test_percentile(self):
metric = getMetric('root.test.ExecutionTime', 'percentile', percentiles=[0.5, 0.95],
def test_quantile(self):
metric = getMetric('root.test.ExecutionTime', 'quantile', quantiles=[0.5, 0.95],
count_calls=False)
for i in range(9):
metric.runtime(10.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