Repository navigation
Let health metrics override component attributes - #35
Conversation
The reporter identifies a status dashboard component by its name and the attributes of the environment (for example `region: EU-DE`). A service that is published as one global component therefore never matched: the component is registered with `region: Global` and the environment attribute always injected the region. Add an optional `component_attributes` map to a health metric definition. It is merged over the environment attributes when the component is built, so a service can replace `region` or add an attribute for itself. The global services (console, otc, helpcenter, architecture center, community, financial dashboard) need it to be resolvable again. Attributes that are not overridden keep their environment value; an unknown attribute is appended.
There was a problem hiding this comment.
Summary
The change adds an optional component_attributes map to ServiceHealthDef so a health metric can override a single environment attribute (e.g. region: Global) when resolving its Status Dashboard component. The merge is implemented in merge_component_attributes (src/sd.rs:112), wired into the reporter (src/bin/reporter.rs:118), threaded through AppState::process_config (src/types.rs:247), and covered by three unit tests plus a regenerated JSON schema and docs.
All three ServiceHealthDef construction sites (types, the AppState builder, and the common.rs test helper) are updated consistently, and the new field is #[serde(default)] so existing configs keep parsing. The merge logic is correct: same-name override replaces, missing name is appended, and the result is sorted for determinism. The subset-based matching in find_component_id is unchanged and works with the merged attributes. Overall this is a clean, well-tested change — approve.
Findings
Warning
- Override attributes that the target component doesn't have silently break matching (
src/bin/reporter.rs:118,find_component_idinsrc/sd.rs).find_component_idrequires the config attributes to be a subset of the cached component's attributes. Because the merge replaces/appends an override rather than validating it, a misconfiguredcomponent_attributes(e.g. an override value or name the live component does not actually expose) will not match any component and the incident will be dropped withcomponent not found in cache even after refresh— the exact failure mode this PR is trying to fix, now with an extra, less obvious cause. Consider a startup log/debug line that emits the final merged attribute set per component so a mismatch can be spotted quickly against theGET /v2/componentsresponse. (The PR already validates against the live API, so this is a maintainability aid, not a blocker.)
Suggestion
- Inconsistent ordering in
merge_component_attributes(src/sd.rs:112). WhenoverridesisNonethe function returns the environment attributes unsorted; whenSome, it sorts the result. Functionally irrelevant (matching compares individual attributes, never the whole vec), but the asymmetry is a bit surprising. You couldsort()before the earlyreturntoo for consistency. - Non-deterministic input order (
src/bin/reporter.rs):env_attrsis built by iteratingenv.attributes(aHashMap), so its order varies per run. This is currently harmless because both the merge output (when overridden) and the cache key are sorted, andfind_component_idcompares per-attribute. No action needed, just noting it relies on the sorted-key guarantee.
CI (build/test) was still queued at review time, so these findings are based on static reading only.
The build from stackmon/metrics-processor#35 understands `component_attributes`, which the aligned config already declares for the global components.
Builds from stackmon/metrics-processor#35, which lets a health metric override the component attributes it is looked up with. The config that uses the field is in #300; either order deploys without changing the current behaviour.
The reporter matches a status dashboard component by its name and the attributes of the environment, so services published as one global component (
region: Global) never matched and their incidents were dropped withcomponent not found in cache even after refresh.A health metric definition accepts an optional
component_attributesmap now. It is merged over the environment attributes when the component is resolved: an attribute with the same name replaces the environment value, a missing one is appended.Verified with
cargo fmt -- --check,cargo clippy -- -D warnings,cargo test --all-targets(three unit tests cover the merge) and the regenerateddoc/schemas/config-schema.json. Replaying the reporter's matching against the liveGET /v2/componentsof both sites resolves the affected services to their components once the config uses the field.