fix(prometheus): keep/drop patterns split on any whitespace, and a *_time_seconds value reads as a moment (#6423)
CI / lint (push) Successful in 2s
CI / unit (push) Successful in 1m46s
CI / integration (push) Successful in 1m48s
CI / publish (push) Successful in 19s

A pasted drop list whose line breaks had become spaces was stored as one
pattern that matched nothing, so Home Assistant's two 526-series
bookkeeping families filled the 1,000-series cap. No metric name holds
whitespace, so patterns now split on spaces and tabs as well as lines
and commas.

Home Assistant names its Unix times *_time_seconds (e.g.
homeassistant_last_updated_time_seconds), which read as "20751d 21h".
is_moment() takes both suffixes, for the value shown and the chart axis.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 19:01:21 -04:00
co-authored by Claude Opus 5.5
parent 057c95c45e
commit 57b2aafd1a
5 changed files with 29 additions and 10 deletions
+3
View File
@@ -72,6 +72,9 @@ def test_series_are_grouped_by_metric_with_their_labels_and_units():
("target=S", "fresh", ["fresh", "late"])]
assert groups[2]["rows"][0]["resource"] == "A:target=S,state=fresh"
assert shown_value("x_timestamp_seconds", 0) == {"text": "never", "moment": None}
# Home Assistant names its Unix times *_time_seconds (#6423): a moment, not "20751d 21h".
assert shown_value("homeassistant_last_updated_time_seconds", 1792964340.0) == {
"text": "", "moment": datetime.fromtimestamp(1792964340.0, timezone.utc)}
assert shown_value("jobs_per_sec", 0.25)["text"] == "0.25/s"
assert shown_value("job_seconds", 90)["text"] == "1m 30s"
assert shown_value("anything", None)["text"] == "—"
+4
View File
@@ -73,6 +73,10 @@ def test_names():
assert resource_for("T", ()) == "T"
assert resource_for("T", (("a", "1"), ("b", "x"))) == "T:a=1,b=x"
assert patterns("a_*, b_*\n\n a_* \nc") == ["a_*", "b_*", "c"]
# A paste that turned its line breaks into spaces (#6423): no metric name
# holds whitespace, so each word is a pattern.
assert patterns("ha_last_updated_time_seconds ha_entity_available\tha_entity_info") == [
"ha_last_updated_time_seconds", "ha_entity_available", "ha_entity_info"]
def test_labels_read_back_as_stored_even_with_a_comma_in_a_value():