From fc0dde6e88cec8645cf17377eef78ad359d97379 Mon Sep 17 00:00:00 2001 From: jenkins Date: Fri, 7 Aug 2026 20:07:33 -0300 Subject: [PATCH] monitoring(testing): retain scalar branch labels --- .../tests/test_monitoring_query_capacity.py | 20 ++++++ .../vmalert-atlas-availability.yaml | 63 +++++++++++++++++-- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/scripts/tests/test_monitoring_query_capacity.py b/scripts/tests/test_monitoring_query_capacity.py index 05b366f49..0aef20cb6 100644 --- a/scripts/tests/test_monitoring_query_capacity.py +++ b/scripts/tests/test_monitoring_query_capacity.py @@ -164,6 +164,26 @@ def test_quality_rollups_do_not_run_every_minute() -> None: assert quality["eval_offset"] == "1m" +def test_quality_scalar_rollups_infer_legacy_branch_labels() -> None: + """Attach build branches to publishers that still omit the label.""" + manifest = _documents( + REPO_ROOT / "services/monitoring/vmalert-atlas-availability.yaml" + )[0] + quality = yaml.safe_load(manifest["data"]["platform-quality.yaml"])["groups"][0] + rules = {rule["record"]: rule["expr"] for rule in quality["rules"]} + + for record in ( + "platform_quality:suite_coverage_percent:latest_1h", + "platform_quality:suite_source_files_total:latest_1h", + "platform_quality:suite_source_lines_over_500_total:latest_1h", + ): + expression = rules[record] + assert 'branch=""' in expression + assert "group_left(branch)" in expression + assert "platform_quality_gate_build_info" in expression + assert '"branch", "unknown"' in expression + + def test_vmalert_reloads_updated_rule_files() -> None: """Make Flux ConfigMap updates take effect without manual pod revision bumps.""" manifests = _documents( diff --git a/services/monitoring/vmalert-atlas-availability.yaml b/services/monitoring/vmalert-atlas-availability.yaml index 0bdabcea9..17db8e7f5 100644 --- a/services/monitoring/vmalert-atlas-availability.yaml +++ b/services/monitoring/vmalert-atlas-availability.yaml @@ -219,25 +219,78 @@ data: - record: platform_quality:suite_coverage_percent:latest_1h expr: | max by (suite, branch) ( - platform_quality_gate_workspace_line_coverage_percent{exported_job="platform-quality-ci",suite!=""} + {__name__=~"platform_quality_gate_workspace_line_coverage_percent|.*_quality_gate_coverage_percent",exported_job="platform-quality-ci",suite!="",branch!=""} ) or on (suite, branch) - max by (suite, branch) ( - {__name__=~".*_quality_gate_coverage_percent",exported_job="platform-quality-ci",suite!=""} + ( + max by (suite) ( + {__name__=~"platform_quality_gate_workspace_line_coverage_percent|.*_quality_gate_coverage_percent",exported_job="platform-quality-ci",suite!="",branch=""} + ) + * on (suite) group_left(branch) + max by (suite, branch) (platform_quality_gate_build_info{exported_job="platform-quality-ci",suite!="",branch!=""}) + ) + or on (suite, branch) + ( + label_replace( + max by (suite) ( + {__name__=~"platform_quality_gate_workspace_line_coverage_percent|.*_quality_gate_coverage_percent",exported_job="platform-quality-ci",suite!="",branch=""} + ), + "branch", "unknown", "__name__", ".*" + ) + unless on (suite) + max by (suite) (platform_quality_gate_build_info{exported_job="platform-quality-ci",suite!="",branch!=""}) ) labels: rollup: hourly - record: platform_quality:suite_source_files_total:latest_1h expr: | max by (suite, branch) ( - platform_quality_gate_source_files_total{exported_job="platform-quality-ci",suite!=""} + platform_quality_gate_source_files_total{exported_job="platform-quality-ci",suite!="",branch!=""} + ) + or on (suite, branch) + ( + max by (suite) ( + platform_quality_gate_source_files_total{exported_job="platform-quality-ci",suite!="",branch=""} + ) + * on (suite) group_left(branch) + max by (suite, branch) (platform_quality_gate_build_info{exported_job="platform-quality-ci",suite!="",branch!=""}) + ) + or on (suite, branch) + ( + label_replace( + max by (suite) ( + platform_quality_gate_source_files_total{exported_job="platform-quality-ci",suite!="",branch=""} + ), + "branch", "unknown", "__name__", ".*" + ) + unless on (suite) + max by (suite) (platform_quality_gate_build_info{exported_job="platform-quality-ci",suite!="",branch!=""}) ) labels: rollup: hourly - record: platform_quality:suite_source_lines_over_500_total:latest_1h expr: | max by (suite, branch) ( - platform_quality_gate_source_lines_over_500_total{exported_job="platform-quality-ci",suite!=""} + platform_quality_gate_source_lines_over_500_total{exported_job="platform-quality-ci",suite!="",branch!=""} + ) + or on (suite, branch) + ( + max by (suite) ( + platform_quality_gate_source_lines_over_500_total{exported_job="platform-quality-ci",suite!="",branch=""} + ) + * on (suite) group_left(branch) + max by (suite, branch) (platform_quality_gate_build_info{exported_job="platform-quality-ci",suite!="",branch!=""}) + ) + or on (suite, branch) + ( + label_replace( + max by (suite) ( + platform_quality_gate_source_lines_over_500_total{exported_job="platform-quality-ci",suite!="",branch=""} + ), + "branch", "unknown", "__name__", ".*" + ) + unless on (suite) + max by (suite) (platform_quality_gate_build_info{exported_job="platform-quality-ci",suite!="",branch!=""}) ) labels: rollup: hourly