diff --git a/logprep/abc/connector.py b/logprep/abc/connector.py index b2aea14dc..20f5dcb6c 100644 --- a/logprep/abc/connector.py +++ b/logprep/abc/connector.py @@ -36,9 +36,20 @@ class Metrics(Component.Metrics): ) """Time in seconds that it took to process an event""" - number_of_warnings: int = 0 + number_of_warnings: CounterMetric = field( + factory=lambda: CounterMetric( + description="Number of errors that occurred while processing events", + name="number_of_warnings", + ) + ) """Number of warnings that occurred while processing events""" - number_of_errors: int = 0 + + number_of_errors: CounterMetric = field( + factory=lambda: CounterMetric( + description="Number of errors that occurred while processing events", + name="number_of_errors", + ) + ) """Number of errors that occurred while processing events""" __slots__ = ["metrics"] diff --git a/logprep/processor/base/rule.py b/logprep/processor/base/rule.py index 6ea150096..d945c2e91 100644 --- a/logprep/processor/base/rule.py +++ b/logprep/processor/base/rule.py @@ -224,10 +224,10 @@ class Metrics(Component.Metrics): number_of_warnings: CounterMetric = field( factory=lambda: CounterMetric( description="Number of errors that occurred while processing events", - name="number_of_errors", + name="number_of_warnings", ) ) - """Number of errors that occurred while processing events""" + """Number of warnings that occurred while processing events""" number_of_errors: CounterMetric = field( factory=lambda: CounterMetric( diff --git a/tests/unit/component/base.py b/tests/unit/component/base.py index 06529d551..8cba0375a 100644 --- a/tests/unit/component/base.py +++ b/tests/unit/component/base.py @@ -75,6 +75,9 @@ def test_custom_metrics_adds_custom_prefix_to_metrics_name(self): "_prefix", "processing_time_per_event", "number_of_processed_events", + "number_of_failed_events", + "number_of_warnings", + "number_of_errors", ] metric_attributes = asdict( self.object.metrics, diff --git a/tests/unit/processor/base.py b/tests/unit/processor/base.py index 3f59855d6..0f7e92cde 100644 --- a/tests/unit/processor/base.py +++ b/tests/unit/processor/base.py @@ -4,17 +4,15 @@ import itertools import json -import re from copy import deepcopy -from functools import partial from logging import getLogger from pathlib import Path -from typing import Callable from unittest import mock import pytest import requests import responses +from attrs import asdict from ruamel.yaml import YAML from logprep.abc.processor import Processor @@ -278,3 +276,11 @@ def test_raises_http_error(self): def test_rule_has_metric(self, metric_name, metric_class): metric_instance = getattr(self.object.rules[0].metrics, metric_name) assert isinstance(metric_instance, metric_class) + + def test_no_metrics_with_same_name(self): + metric_attributes = asdict( + self.object.rules[0].metrics, filter=self.asdict_filter, recurse=False + ) + pairs = itertools.combinations(metric_attributes.values(), 2) + for metric1, metric2 in pairs: + assert metric1.name != metric2.name, f"{metric1.name} == {metric2.name}"