Python module that provides helpers for functional testing of metrics with testsuite; see Functional service tests (testsuite) for an introduction.
Classes | |
| class | Histogram |
| Represents the value of a HIST_RATE (a.k.a. More... | |
| class | Metric |
| Metric type that contains the labels: dict[str, str] and value: int. More... | |
| class | _MetricsJSONEncoder |
| class | MetricsSnapshot |
| Snapshot of captured metrics that mimics the dict interface. More... | |
Functions | |
| Mapping[str, Set[Metric]] | _apply_common_prefix_labels (Mapping[str, Set[Metric]] values, str common_prefix, Mapping[str, str]|None common_labels) |
| dict[str, Set[Metric]] | _drop_empty_paths (Mapping[str, Set[Metric]] values) |
| str|None | _strip_prefix_segment (str path, str prefix) |
| bool | _is_zero_rate_or_histogram (Metric metric) |
| bool | _type_eq (MetricType lhs, MetricType rhs) |
| tuple[tuple[str, str],...] | _get_labels_tuple (Metric metric) |
| Returns labels as a tuple of sorted items. | |
| str | _format_metric_line (str path, Metric metric, *, MetricType|None forced_type=None) |
| Formats a single metric line as "path: (labels) TYPE VALUE", skipping the labels part (and the extra space) entirely if there are no labels. | |
| set[str] | stringify_snapshot_for_diff (Mapping[str, Set[Metric]] values, *, Mapping[str, Set[Metric]] other) |
| Renders a snapshot as a set of "path: (labels) TYPE VALUE" strings (the same format as MetricsSnapshot.pretty_print), suitable for use with a generic set-based diff (e.g. | |
| MetricType | _resolve_type (str path, Metric metric, MetricsSnapshot other_snapshot) |
| float | _do_compute_percentile (Histogram hist, float percent) |
| bool | _is_histogram_dict (Any node) |
| set[Metric] | _collect_layered_metrics (Any node, dict[str, str] labels) |
| MetricValue | _parse_metric_value (Any value) |
| _FlattenedSnapshot | _flatten_snapshot (values, bool ignore_zeros) |
| str | _diff_metric_snapshots (_FlattenedSnapshot lhs, _FlattenedSnapshot rhs, bool ignore_zeros) |
Variables | |
| T = TypeVar('T') | |
| Any | _MISSING = object() |
| str | _LABEL_SEPARATOR = ' = ' |
| TypeAlias | _FlattenedSnapshot = Set[tuple[str, Metric]] |
|
protected |
Definition at line 542 of file metrics.py.
|
protected |
Definition at line 670 of file metrics.py.
|
protected |
Definition at line 711 of file metrics.py.
|
protected |
Definition at line 641 of file metrics.py.
Definition at line 560 of file metrics.py.
|
protected |
Definition at line 702 of file metrics.py.
|
protected |
Formats a single metric line as "path: (labels) TYPE VALUE", skipping the labels part (and the extra space) entirely if there are no labels.
forced_type overrides metric's own type, if given
Definition at line 599 of file metrics.py.
|
protected |
Returns labels as a tuple of sorted items.
Definition at line 594 of file metrics.py.
|
protected |
Definition at line 663 of file metrics.py.
|
protected |
Definition at line 584 of file metrics.py.
|
protected |
Definition at line 684 of file metrics.py.
|
protected |
Definition at line 632 of file metrics.py.
|
protected |
Definition at line 564 of file metrics.py.
|
protected |
Definition at line 590 of file metrics.py.
| set[str] stringify_snapshot_for_diff | ( | Mapping[str, Set[Metric]] | values, |
| * | , | ||
| Mapping[str, Set[Metric]] | other ) |
Renders a snapshot as a set of "path: (labels) TYPE VALUE" strings (the same format as MetricsSnapshot.pretty_print), suitable for use with a generic set-based diff (e.g.
testsuite's CompareVisitor machinery).
A metric with an UNSPECIFIED type has its type resolved from the matching (by path and labels) metric in other, if any, mirroring the wildcard-matching behavior of Metric.__eq__.
Definition at line 608 of file metrics.py.
|
protected |
Definition at line 699 of file metrics.py.
|
protected |
Definition at line 667 of file metrics.py.
|
protected |
Definition at line 76 of file metrics.py.
| pytest_userver.metrics.T = TypeVar('T') |
Definition at line 75 of file metrics.py.