Skip to content

Enforce module identity across metric alerts - #79

Merged
Amygos merged 2 commits into
mainfrom
module-alert-rules-phase1
Aug 31, 2026
Merged

Amygos merged 2 commits into
mainfrom
module-alert-rules-phase1

Conversation

@Amygos

@Amygos Amygos commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

Summary

This is the first implementation phase for provider-published Prometheus
alert rules.

Derive module_id and target_type from each provider's Redis key and
field, preventing provider-supplied labels from overriding authoritative
target identity.

Malformed target fields are isolated so they do not prevent valid sibling
fields from being materialized. Conflicting identity labels are replaced
and reported with their Redis provenance.

Alertmanager grouping and inhibition include module_id, keeping
same-name alerts from different module instances independent.

Generic downstream alert identifiers include a non-empty module_id.
Explicit legacy alert mappings remain unchanged, even when the alert
contains module_id.

Existing built-in node targets remain unchanged.

The Robot test runner now synchronizes its cached Python environment with
tests/pythonreq.txt on every run, ensuring newly added dependencies are
installed.

Compatibility

Explicitly mapped alerts retain their existing portal identifiers:

LokiOffline + module_id=loki1 + node=4
→ loki-offline:node:4

Generic alerts with a non-empty module_id receive a module-scoped
identifier:

Application_Down + module_id=postgresql1 + node=2
→ application-down:postgresql1:node:2

Generic alerts without module_id retain their previous identifiers:

Application_Down + node=2
→ application-down:node:2

Mimir forwarding is unaffected because the complete original alert payload
continues to be forwarded without modification.

Related issue

NethServer/dev#8100

How to test

env PYTHONDONTWRITEBYTECODE=1 \
  python3 -m unittest discover -s tests -p 'test_*.py' -v

env venvroot=/usr PYTHONDONTWRITEBYTECODE=1 \
  python3 -m robot --console verbose \
  --output NONE --report NONE --log NONE \
  tests/00__unit_tests.robot

bash -n test-module.sh

All checks pass: nine Python tests and one Robot test.

The tests cover:

  • authoritative provider target identity;
  • malformed provider-field isolation;
  • Alertmanager grouping and inhibition;
  • distinct generic IDs for different module instances;
  • unchanged explicit legacy mappings when module_id is present;
  • unchanged generic IDs without module_id;
  • cached test-environment dependency synchronization.

Dependencies

None.

@Amygos Amygos self-assigned this Jul 23, 2026
@Amygos
Amygos requested review from DavidePrincipi and gsanchietti and removed request for DavidePrincipi July 23, 2026 12:57
@Amygos Amygos linked an issue Jul 23, 2026 that may be closed by this pull request

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba39231d0d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread imageroot/bin/provision-prometheus Resolved
Comment thread tests/pythonreq.txt Outdated
@@ -1,2 +1,3 @@
robotframework
robotframework-sshlibrary
PyYAML

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Refresh cached test environments for the new dependency

On any machine that has already run test-module.sh, the persistent rftest-cache volume contains an executable Robot installation, so lines 31-34 of that script skip pip install entirely. Adding PyYAML here therefore does not install it in those cached environments, and the new test_provision_prometheus.py fails during collection with ModuleNotFoundError: yaml; the dependency installation needs to run when the requirements change rather than only when Robot is absent.

AGENTS.md reference: AGENTS.md:L6-L6

Useful? React with 👍 / 👎.

@NethServer NethServer deleted a comment from chatgpt-codex-connector Bot Jul 23, 2026
@Amygos Amygos changed the title Enforce provider identity in metrics targets Enforce module identity across metric alerts Jul 23, 2026

@DavidePrincipi DavidePrincipi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Looking forward to phase 2.

Comment thread alert-proxy/README.md Resolved
Amygos added a commit that referenced this pull request Aug 27, 2026
Limit module scoping to generic alert identifiers so existing mapped
portal IDs remain stable.

#79 (comment)

Assisted-by: Codex:GPT-5
Amygos added a commit that referenced this pull request Aug 27, 2026
Cover generic per-module identifiers and verify every known mapping
retains its legacy portal ID when module_id is present.

#79 (comment)

Assisted-by: Codex:GPT-5
Amygos added a commit that referenced this pull request Aug 27, 2026
Synchronize cached Robot environments with the current requirements on
every run so newly added dependencies are installed.

#79 (comment)

Assisted-by: Codex:GPT-5
Amygos added a commit that referenced this pull request Aug 27, 2026
Document generic module scoping while preserving mapped portal IDs, and
remove the inapplicable provider-rule upgrade scenario.

#79 (comment)

Assisted-by: Codex:GPT-5
@Amygos
Amygos force-pushed the module-alert-rules-phase1 branch from 5432f3e to f5aef72 Compare August 27, 2026 14:23
Derive module ownership from each provider Redis key and apply it to
scrape targets so module-scoped alert rules cannot consume another
provider series.

Keep Alertmanager groups and inhibition rules separated by module
identity.

Assisted-by: Codex:gpt-5.6-sol
Describe authoritative target labels, field-level validation, and
generated filenames for provider integrations.

Record Alertmanager isolation, downstream ID scoping, and upgrade
compatibility for alert-proxy consumers.

Assisted-by: Codex:gpt-5.6-sol
@Amygos
Amygos force-pushed the module-alert-rules-phase1 branch from d36b639 to 90d31a8 Compare August 31, 2026 14:02
@Amygos
Amygos merged commit a5a6c77 into main Aug 31, 2026
1 check passed
@Amygos
Amygos deleted the module-alert-rules-phase1 branch August 31, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce module identity across metric alerts Allow applications to provide their own alert rules

3 participants