Skip to content

Commit

Permalink
fixes #26 salt_aborted metric lacks a state label
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasmhughes committed Feb 22, 2024
1 parent 0f6a9cf commit a9458a9
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 46 deletions.
1 change: 1 addition & 0 deletions changelog/26.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix salt_aborted metric lacking a state label
25 changes: 20 additions & 5 deletions src/saltext/prometheus/returners/prometheus_textfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,31 @@ def returner(ret):
gauge_show_failed_states.labels(*label_values).set(1)

if opts["abort_state_ids"]:
labels = []
label_values = []
if opts["add_state_name"]:
labels.append("state")
label_values.append(prom_state)
if not isinstance(opts["abort_state_ids"], list):
opts["abort_state_ids"] = [item.strip() for item in opts["abort_state_ids"].split(",")]

gauge_salt_aborted = Gauge(
"salt_aborted", "Flag to show that a specific abort state failed", registry=registry
)
gauge_salt_aborted.set(0)
aborted_value = 0
for state_id, state_return in ret["return"].items():
if not state_return["result"] and state_return.get("__id__") in opts["abort_state_ids"]:
gauge_salt_aborted.set(1)
aborted_value = 1
labels.append("state_id")
label_values.append(state_id.split("_|-")[1])

gauge_salt_aborted = Gauge(
"salt_aborted",
"Flag to show that a specific abort state failed",
labels,
registry=registry,
)
if label_values:
gauge_salt_aborted.labels(*label_values).set(aborted_value)
else:
gauge_salt_aborted.set(aborted_value)

if opts["add_state_name"]:
old_name, ext = os.path.splitext(opts["filename"])
Expand Down
Loading

0 comments on commit a9458a9

Please sign in to comment.