Add tier label to all Prometheus metrics #3
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ldraney/pal-e-dora-exporter!3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "2-add-tier-label-to-all-prometheus-metrics"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds a
tierlabel ("1", "2", or "3") to all six Prometheus metric families emitted by the DORA exporter. Tier assignment is driven by a YAML config file (tiers.yaml) loaded via theDORA_TIERS_FILEenvironment variable. Repos not listed default to tier 3. Matching strips the owner prefix so "forgejo_admin/pal-e-docs" resolves to the "pal-e-docs" entry.Changes
src/config.py-- AddedDORA_TIERS_FILEenv var,load_tiers()YAML parser, andConfig.tier_for_repo()lookup methodsrc/collectors/forgejo.py-- Added"tier"to label lists onpr_merges_total,pr_lead_time_seconds,pr_review_count; collectors storeConfigref and pass tier to all.labels()callssrc/collectors/woodpecker.py-- Added"tier"to label lists ondeployments_total,deployment_duration_seconds,deployment_last_success_timestamp; same config/tier patterntiers.yaml-- Initial tier mapping (tier 1: platform-critical repos, tier 2: tooling repos, tier 3: default)requirements.txt-- Addedpyyaml>=6.0tests/test_tiers.py-- 11 unit tests covering YAML parsing, owner-prefix stripping, default tier fallback, and metric label verificationTest Plan
python -m pytest tests/test_tiers.py -v-- all 11 tests passruff check src/ tests/andruff format --check src/ tests/-- cleanDORA_TIERS_FILE=/path/to/tiers.yamland verify/metricsoutput includestier="1",tier="2",tier="3"labelsReview Checklist
Related Notes
None -- no pal-e-docs notes for this change.
Related
Closes #2
Parent issue: ldraney/DORA#1
QA Review -- PR #3
Summary
Clean, focused PR. Adds
tierlabel to all 6 Prometheus metric families via a YAML config loaded fromDORA_TIERS_FILEenv var. Owner prefix stripping handles theowner/repovsrepomismatch correctly.Findings
No blocking issues.
Observations (non-blocking):
main.pychanges are format-only -- ruff reformatted twoasyncio.create_task()calls. No functional change. Acceptable since the repo should stay consistently formatted.load_tiers()usesopen()without encoding --with open(file_path) as f:relies on system default encoding. YAML files are UTF-8 by convention andyaml.safe_loadhandles bytes, so this is fine in practice. Could addencoding="utf-8"for explicitness but not required.Test coverage is thorough -- 11 tests covering: YAML parsing (all tiers, partial, empty, missing file), owner prefix stripping, default tier fallback, no-config-file fallback, and metric label presence on all 6 metrics. Good boundary coverage.
tiers.yamlmatches the spec -- Tier 1 and Tier 2 lists match what was specified in the issue. No tier_3 section needed since unlisted repos default to 3.No breaking changes -- Metric names unchanged,
tieris additive to existing label sets. Existing Grafana queries using{repo="..."}will continue to work; they just gain a new label dimension.Checklist
tierlabel present on all 6 metric families (3 Forgejo + 3 Woodpecker)forgejo_admin/pal-e-platform)DORA_TIERS_FILEenv var optional (graceful fallback when unset)pyyamladded to requirements.txtVERDICT: APPROVE
PR #3 Review
DOMAIN REVIEW
Stack: Python / FastAPI / Prometheus client / PyYAML / pytest
Tier label coverage -- all 6 metric families updated:
dora_pr_merges_totalsrc/collectors/forgejo.pydora_pr_lead_time_secondssrc/collectors/forgejo.pydora_pr_review_countsrc/collectors/forgejo.pydora_deployments_totalsrc/collectors/woodpecker.pydora_deployment_duration_secondssrc/collectors/woodpecker.pydora_deployment_last_success_timestampsrc/collectors/woodpecker.pyConfig design is solid:
DORA_TIERS_FILEenv var for external config -- not hardcodedload_tiers()parses YAML withtier_1/tier_2/tier_3keys into flat{repo: tier}mappingtier_for_repo()strips owner prefix viarsplit("/", 1)[-1]-- handles both"owner/repo"and"repo"forms correctly"3"viaDEFAULT_TIERconstant -- safe fallbackBackwards compatibility:
Adding a label is technically a breaking change for Prometheus, but the impact is minimal here. Each repo maps to exactly one tier, so there is no cardinality explosion. Existing PromQL aggregations using
sum()orrate()without explicit label matchers will continue to work. Queries with exact label matchers like{repo="foo"}also work sincetieris additive. Any Grafana dashboards filtering byrepowill be unaffected. This is safe to ship.Test coverage -- 11 tests across 3 test classes:
TestLoadTiers(4): YAML parsing, missing file, empty file, partial tiersTestTierForRepo(5): owner-prefix stripping, tier 1/2 lookup, unknown repo defaults, no tiers file scenarioTestCollectorTierLabels(2): structural verification that all 6 metric definitions include"tier"in_labelnamesTests cover the critical paths: config parsing, lookup logic, default behavior, and metric label verification.
Python/PEP compliance:
dict[str, str])DEFAULT_TIERas module-level constant rather than magic stringBLOCKERS
None.
NITS
src/main.pyformatting changes -- Lines 60-67 are pure reformatting ofasyncio.create_task()calls, unrelated to the tier feature. Harmless (likely ruff autoformat) but technically scope creep. Not blocking.from datetime import datetimecleanup inforgejo.pyline 177 -- Thetimezoneimport was removed. This appears correct (method usesfromisoformat()which handles timezone suffixes natively in Python 3.11+), but confirm the target Python version is >= 3.11.tiers.yamlat repo root -- Consider adding a comment or README note clarifying this is a reference/default config, and production should setDORA_TIERS_FILEto point to a deployed config (e.g., via ConfigMap or volume mount). Currently the file is self-documenting with its header comment, which is adequate.Duplicate repo name collision -- If two repos in different orgs share the same name (e.g.,
ldraney/utilsandforgejo_admin/utils), they would collide to the same tier. The current owner-stripping design makes this intentional, but worth documenting as a known limitation if multi-org support grows.SOP COMPLIANCE
ldraney/DORA#1) includedPROCESS OBSERVATIONS
tiers.yamlschema (what keys are valid, what values mean) is documented in code docstrings but not in a README. Consider adding a section to the project README for operator reference.VERDICT: APPROVED