A helper class for computing metric differences.
- See also
- ClientMonitor.metrics_diff
Example with await monitor_client.metrics_diff():
async def test_diff_metrics(service_client, monitor_client: pytest_userver.client.ClientMonitor):
async with monitor_client.metrics_diff(prefix='sample-metrics') as differ:
response = await service_client.get('/metrics')
assert response.status == 200
assert differ.value_at('foo') == 1
Definition at line 541 of file client.py.
|
| pytest_userver.metrics.MetricsSnapshot | baseline (self) |
| None | baseline (self, pytest_userver.metrics.MetricsSnapshot value) |
| pytest_userver.metrics.MetricsSnapshot | current (self) |
| None | current (self, pytest_userver.metrics.MetricsSnapshot value) |
| pytest_userver.metrics.MetricsSnapshot | diff (self) |
| pytest_userver.metrics.MetricValue | value_at (self, str|None subpath=None, dict[str, str]|None add_labels=None) |
| pytest_userver.metrics.MetricValue|T | value_at (self, str|None subpath, dict[str, str]|None add_labels, *, T default) |
| pytest_userver.metrics.MetricValue|Any | value_at (self, str|None subpath=None, dict[str, str]|None add_labels=None, *, Any default=_MISSING) |
| | Returns a single metric value at the specified path, prepending the path provided at construction.
|
| pytest_userver.metrics.MetricsSnapshot | fetch (self) |
| | Returns metric values from the service without mutating the differ.
|
| None | fetch_baseline (self) |
| | Fetches metric values from the service and stores them as self.baseline.
|
| None | fetch_current (self) |
| | Fetches metric values from the service and stores them as self.current, updating self.diff accordingly.
|
| MetricsDiffer | __aenter__ (self) |
| None | __aexit__ (self, exc_type, exc, exc_tb) |
| pytest_userver.metrics.MetricValue | Any pytest_userver.client.MetricsDiffer.value_at |
( |
| self, |
|
|
str | None | subpath = None, |
|
|
dict[str, str] | None | add_labels = None, |
|
|
* | , |
|
|
Any | default = _MISSING ) |
Returns a single metric value at the specified path, prepending the path provided at construction.
If a dict of labels is provided, does an exact match of labels, prepending the labels provided at construction.
If default is provided, it is returned instead of asserting when the metric is not found.
- Parameters
-
| subpath | Suffix of the metric path; the path provided at construction is prepended |
| add_labels | Labels that the metric must have in addition to the labels provided at construction |
| default | An optional default value in case the metric is missing |
- Exceptions
-
| AssertionError | if not one metric by path and no default is given |
Definition at line 626 of file client.py.