Skip to content

Commit 039fde0

Browse files
committed
feat(tpu_observability): use custom labels for distribution metrics in tpu_info verification
1 parent 07e9e96 commit 039fde0

2 files changed

Lines changed: 45 additions & 5 deletions

File tree

dags/tpu_observability/tpu_info_metric.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ def parse_from_tpu_info(
8181
"""
8282
pass
8383

84+
def get_labels(
85+
self, tpu_info_metric_output: list[tpu_info.Table]
86+
) -> list[str] | None:
87+
"""Gets labels for the metric values.
88+
89+
Default returns None, which implies using default device labels.
90+
"""
91+
return None
92+
93+
8494

8595
class _BaseSimplePointStrategy(BaseMetricStrategy):
8696
"""Base strategy for parsing single numeric data points from Cloud Monitoring.
@@ -325,6 +335,30 @@ def parse_from_tpu_info(
325335

326336
return tpu_info_data_values
327337

338+
def get_labels(
339+
self, tpu_info_metric_output: list[tpu_info.Table]
340+
) -> list[str] | None:
341+
"""Parses labels for percentiles from `tpu-info` output tables."""
342+
parsed_values_by_group: dict[str, dict[str, float]] = {}
343+
table_name = self._tpu_info_table_name
344+
group_key = self._tpu_info_group_by_key
345+
346+
for metric_table in tpu_info_metric_output:
347+
if metric_table.name == table_name:
348+
for row_dict in metric_table.body:
349+
group_value = row_dict.get(group_key, "summary")
350+
351+
if group_value not in parsed_values_by_group:
352+
parsed_values_by_group[group_value] = {}
353+
354+
labels = []
355+
for group_value in sorted(parsed_values_by_group.keys()):
356+
for p in self.percentiles_to_check:
357+
labels.append(f"{group_value} {p.name}")
358+
359+
return labels
360+
361+
328362

329363
class MemoryUsedStrategy(_BaseSimplePointStrategy):
330364
"""Strategy for verifying Used HBM Memory."""

dags/tpu_observability/tpu_info_metrics_dag.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def compare_metric_values(
6161
pod_name: str,
6262
metric_display_name: str,
6363
tolerance_percent: float,
64+
labels: list[str] | None = None,
6465
):
6566
"""Compares two lists of metric values and checks if they are within a tolerance range."""
6667
if len(cmd_values) != len(monitoring_values):
@@ -76,15 +77,15 @@ def compare_metric_values(
7677
metric_display_name,
7778
)
7879
logging.info(
79-
"%-12s%-15s%-17s%-12s%-15s%-10s",
80-
"Device",
80+
"%-20s%-15s%-17s%-12s%-15s%-10s",
81+
"Label" if labels else "Device",
8182
"TPU-Info Val",
8283
"Monitoring Val",
8384
"Difference",
8485
"Allowed Diff",
8586
"Result",
8687
)
87-
logging.info("-" * 85)
88+
logging.info("-" * 95)
8889

8990
all_passed = True
9091
for i, (log_val, mon_val) in enumerate(zip(cmd_values, monitoring_values)):
@@ -93,9 +94,10 @@ def compare_metric_values(
9394
passed = diff <= allowed_diff
9495
if not passed:
9596
all_passed = False
97+
label = labels[i] if labels else f"Device {i}"
9698
logging.info(
97-
"%-12s%-15.2f%-17.2f%-12.2f%-15.2f%-10s",
98-
f"Device {i}",
99+
"%-20s%-15.2f%-17.2f%-12.2f%-15.2f%-10s",
100+
label,
99101
log_val,
100102
mon_val,
101103
diff,
@@ -114,6 +116,7 @@ def compare_metric_values(
114116
)
115117

116118

119+
117120
@task
118121
def get_tpu_info_metric_from_pod(
119122
node_pool: node_pool.Info,
@@ -172,14 +175,17 @@ def run_metric_verification(
172175
metric_strategy.dag_id_suffix,
173176
)
174177

178+
labels = metric_strategy.get_labels(tpu_info_output)
175179
compare_metric_values(
176180
cmd_values,
177181
monitoring_values,
178182
pod_name,
179183
metric_display_name=metric_strategy.dag_id_suffix,
180184
tolerance_percent=tolerance_for_metric,
185+
labels=labels,
181186
)
182187

188+
183189
return True
184190

185191

0 commit comments

Comments
 (0)