Skip to content

Commit

Permalink
Fix failed metric names.
Browse files Browse the repository at this point in the history
Previously, the failed metric had "collector" twice in its name.
Eg: "ipmidcmicollector_collector_failed"

This change aims to remove the duplication.
Previous example becomes "ipmidcmi_collector_failed"

The label is also changed similarly to reflect the new name.

Unit test was also modified to reflect this change.
  • Loading branch information
dashmage committed Dec 1, 2023
1 parent ae32c80 commit 8a6afe2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 8 additions & 4 deletions prometheus_hardware_exporter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ def failed_metrics(self) -> Iterable[Metric]:
Yields:
metrics: the internal metrics
"""
name = self.__class__.__name__
# if `__class_.__name__` is "IpmiDcmiCollector"
# then `name` becomes "ipmidcmi"
suffix = "collector"
class_name = self.__class__.__name__.lower()
name = class_name[: -len(suffix)] if class_name.endswith(suffix) else class_name
metric = GaugeMetricFamily(
name=f"{name.lower()}_collector_failed",
documentation=f"{name} Collector failed to fetch metrics",
name=f"{name}_collector_failed",
documentation=f"{name} collector failed to fetch metrics",
labels=["collector"],
)
metric.add_metric(
labels=[self.__class__.__name__],
labels=[name],
value=1,
)
yield metric
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,18 +1297,18 @@ def test_collector_fetch_failed(self):
for collector_cls, expected_name, expected_labels in [
(
MegaRAIDCollector,
"megaraidcollector_collector_failed",
{"collector": "MegaRAIDCollector"},
"megaraid_collector_failed",
{"collector": "megaraid"},
),
(
RedfishCollector,
"redfishcollector_collector_failed",
{"collector": "RedfishCollector"},
"redfish_collector_failed",
{"collector": "redfish"},
),
(
IpmiSensorsCollector,
"ipmisensorscollector_collector_failed",
{"collector": "IpmiSensorsCollector"},
"ipmisensors_collector_failed",
{"collector": "ipmisensors"},
),
]:
collector = collector_cls(Mock())
Expand Down

0 comments on commit 8a6afe2

Please sign in to comment.