Skip to content

Commit

Permalink
add test for same name for rules and connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
ekneg54 committed Oct 19, 2023
1 parent 7af46a4 commit 978f086
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
15 changes: 13 additions & 2 deletions logprep/abc/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions logprep/processor/base/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/component/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/processor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"

0 comments on commit 978f086

Please sign in to comment.