-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
45 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,44 @@ | ||
# pylint: disable=missing-docstring | ||
# pylint: disable=no-self-use | ||
# pylint: disable=protected-access | ||
from typing import List | ||
|
||
import numpy as np | ||
from prometheus_client import REGISTRY | ||
from prometheus_client.registry import Collector | ||
from prometheus_client import CollectorRegistry, Counter, generate_latest | ||
|
||
from logprep.metrics.metrics import CounterMetric, MetricType | ||
import logprep.metrics.metrics as metrics | ||
from logprep.metrics.metrics import CounterMetric | ||
|
||
custom_registry = CollectorRegistry() | ||
|
||
metrics.LOGPREP_REGISTRY = custom_registry | ||
|
||
|
||
class TestsMetrics: | ||
def test_converts_enum_to_prometheus_metric(self): | ||
def test_init_tracker_creates_metric(self): | ||
metric = CounterMetric( | ||
name="testmetric", | ||
type=MetricType.COUNTER, | ||
description="empty description", | ||
labels={"A": "a"}, | ||
) | ||
assert issubclass(metric.type, Collector) | ||
metric.init_tracker() | ||
assert isinstance(metric.tracker, Counter) | ||
|
||
def test_counter_metric_sets_labels(self): | ||
metric = CounterMetric( | ||
type=MetricType.COUNTER, | ||
name="bla", | ||
description="empty description", | ||
labels={"pipeline": "pipeline-1"}, | ||
) | ||
metric.init_tracker() | ||
assert metric.tracker._labelnames == ("pipeline",) | ||
assert ("pipeline-1",) in metric.tracker._metrics | ||
|
||
def test_counter_metric_increments_correctly(self): | ||
metric = CounterMetric( | ||
type=MetricType.COUNTER, | ||
name="bla", | ||
description="empty description", | ||
labels={"pipeline": "1"}, | ||
) | ||
metric.init_tracker() | ||
metric += 1 | ||
assert list(REGISTRY.collect())[-1].samples[-2].value == 1 | ||
assert metric is not None | ||
metric_output = generate_latest(custom_registry).decode("utf-8") | ||
assert 'logprep_bla_total{pipeline="1"} 1.0' in metric_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters