Skip to content

Commit 1f50031

Browse files
seedspiritclaude
andcommitted
refactor(BA-5878): clarify legacy-direction in ValueType label helpers
The two helpers were named "to_live_stat_label" / "from_legacy_live_stat_label", which obscured their actual asymmetry: only the encoder produces the legacy "stats.<name>" form, while the decoder accepts both legacy and current shapes. Rename them to: - ValueType.to_legacy_live_stat_label — encoder, legacy emission - ValueType.from_live_stat_label — decoder, accepts either form and document the "stats." prefix as the legacy convention so the removeprefix branch reads as historical compatibility, not generic parsing. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent c45735f commit 1f50031

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/ai/backend/common/clients/prometheus/fixed_query_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def _render_stats_query(
211211
group_by: str,
212212
) -> str:
213213
stat_fn = f"{bucket.value_type.value}_over_time"
214-
stat_label = bucket.value_type.to_live_stat_label()
214+
stat_label = bucket.value_type.to_legacy_live_stat_label()
215215
parts: list[str] = []
216216
if bucket.gauge_metrics or bucket.gauge_metric_patterns:
217217
gauge_regex = _metric_name_regex(bucket.gauge_metrics, bucket.gauge_metric_patterns)

src/ai/backend/common/clients/prometheus/metric_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def from_prometheus_response(cls, response: PrometheusResponse) -> Self:
201201
container_metric_name = cast(str, info.container_metric_name)
202202
value_type_str = cast(str, info.value_type)
203203
try:
204-
value_type = ValueType.from_legacy_live_stat_label(value_type_str)
204+
value_type = ValueType.from_live_stat_label(value_type_str)
205205
kernel_id = KernelId(UUID(kernel_id_str))
206206
except ValueError:
207207
continue

src/ai/backend/common/clients/prometheus/types.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ class ValueType(StrEnum):
1212
AVG = "avg"
1313

1414
@classmethod
15-
def from_legacy_live_stat_label(cls, value: str) -> "ValueType":
16-
if value.startswith("stats."):
15+
def from_live_stat_label(cls, value: str) -> "ValueType":
16+
if value.startswith(
17+
"stats."
18+
): # Legacy live_stat labels were prefixed with "stats." (e.g. "stats.max", "stats.avg")
1719
return cls(value.removeprefix("stats."))
1820
return cls(value)
1921

20-
def to_live_stat_label(self) -> str:
22+
def to_legacy_live_stat_label(self) -> str:
2123
match self:
2224
case ValueType.MAX | ValueType.AVG:
2325
return f"stats.{self.value}"

0 commit comments

Comments
 (0)