Skip to content

feat(monitoring): Mimir rules ConfigMap (Prometheus-free rule delivery) - #468

Draft
christopherfickess wants to merge 4 commits into
feat/operator-monitoring-pocfrom
feat/operator-monitoring-poc-mimir
Draft

feat(monitoring): Mimir rules ConfigMap (Prometheus-free rule delivery)#468
christopherfickess wants to merge 4 commits into
feat/operator-monitoring-pocfrom
feat/operator-monitoring-poc-mimir

Conversation

@christopherfickess

Copy link
Copy Markdown

Summary

Draft POC — the Prometheus-free rule-delivery option, for the "Grafana Alloy + Mimir instead of Prometheus" direction.

Based on feat/operator-monitoring-poc (#466) so the diff here is only the Mimir addition.

Background: on a Grafana Alloy + Mimir stack, almost everything the operator emits is already backend-neutral — the ServiceMonitor and the dedicated metrics Service are consumed by Grafana Alloy (prometheus.operator.servicemonitors), which remote-writes to Mimir, and the dashboards are Grafana-native. The one Prometheus-specific piece is alert-rule delivery: Alloy/Mimir don't consume the PrometheusRule CRD. This PR adds that seam.

Adds spec.monitoring.mimirRules:

  • Ships the same per-instance, pod-scoped alert rules as prometheusRule, but as a plain ConfigMap in Prometheus rules format (groups:) for a Mimir ruler-sync (mimirtool or a sidecar) to load — instead of a PrometheusRule CRD.
  • Discovery label (default mimir_rules: "1") for the ruler-sync, plus an optional tenant annotation for multi-tenant Mimir.
  • Cleanup-on-disable + Owns(ConfigMap), consistent with the rest of the monitoring reconcile.

No changes to ServiceMonitor / metrics Service / client+calls metrics — this is purely additive.

Cluster prerequisites (documented in docs/examples/mattermost_monitoring_mimir.yaml): install the prometheus-operator CRDs only (no Prometheus server) so Alloy can discover the ServiceMonitor; run Alloy scraping kube-state-metrics + cAdvisor (the CPU/mem/crash-loop alerts depend on those series — metrics-server does not provide them); and run a Mimir ruler-sync that loads mimir_rules-labelled ConfigMaps.

Ticket Link

Internal SRE monitoring POC — no public ticket. Alternative rule delivery for #466; companion to #467 (dashboards).

Release Note

Add `spec.monitoring.mimirRules` to the Mattermost CRD: ships Mattermost's alerting rules as a ConfigMap (Prometheus rules format) for a Grafana Mimir ruler-sync, as a Prometheus-free alternative to the PrometheusRule CRD.

🤖 Generated with Claude Code

@mm-cloud-bot mm-cloud-bot added kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Aug 11, 2026
@christopherfickess
christopherfickess requested a balanced review from Copilot August 11, 2026 14:09

Copilot AI 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.

Pull request overview

Adds ConfigMap-based alert-rule delivery for Grafana Alloy and Mimir deployments without a Prometheus server.

Changes:

  • Adds the spec.monitoring.mimirRules API.
  • Generates and reconciles Mimir rule ConfigMaps.
  • Adds generation tests and deployment documentation.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
apis/mattermost/v1beta1/mattermost_types.go Defines the Mimir rules API.
apis/mattermost/v1beta1/zz_generated.deepcopy.go Adds generated deep-copy support.
config/crd/bases/installation.mattermost.com_mattermosts.yaml Exposes the API through the CRD.
controllers/mattermost/mattermost/controller.go Watches owned ConfigMaps.
controllers/mattermost/mattermost/monitoring.go Reconciles and deletes rule ConfigMaps.
docs/examples/mattermost_monitoring_mimir.yaml Documents Alloy and Mimir configuration.
pkg/mattermost/monitoring.go Generates ConfigMaps containing alert rules.
pkg/mattermost/monitoring_test.go Tests rule ConfigMap generation.
pkg/resources/create_resources.go Adds ConfigMap creation support.
Files not reviewed (1)
  • apis/mattermost/v1beta1/zz_generated.deepcopy.go: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/mattermost/monitoring.go
Comment thread pkg/mattermost/monitoring.go
Comment thread controllers/mattermost/mattermost/monitoring.go Outdated
Comment thread apis/mattermost/v1beta1/mattermost_types.go
@christopherfickess
christopherfickess force-pushed the feat/operator-monitoring-poc-mimir branch from 0b3a158 to e93eefd Compare August 11, 2026 14:27
@christopherfickess
christopherfickess force-pushed the feat/operator-monitoring-poc branch from c73548c to 9763ed7 Compare August 11, 2026 14:27
@christopherfickess
christopherfickess force-pushed the feat/operator-monitoring-poc-mimir branch from 5f9b006 to b74f328 Compare August 11, 2026 15:13
@christopherfickess

Copy link
Copy Markdown
Author

Thanks for the review — here's the resolution.

Fixed:

  • Owned-only cleanup — disabling mimirRules now deletes only ConfigMaps carrying the operator's marker label (mattermost.com/mimir-rules, listed via selector), so an unrelated ConfigMap that merely shares the derived name is never touched.
  • MattermostLabels map mutation — now copies spec.resourceLabels (shared with the base branch).
  • Service label scoping — the Mimir rules ConfigMap uses the same corrected <name>-metrics service scoping as the PrometheusRule.

discoveryLabel vs marker-label collision: the marker label key (mattermost.com/grafana-dashboard-style mattermost.com/mimir-rules) is namespaced under mattermost.com/, so a user-supplied discoveryLabel colliding with it is not a realistic configuration; the marker is set after the discovery label and cleanup keys off the marker.

This PR is stacked on #466 (rebased so the diff is only the Mimir delta). Shared CI fixes (openapi, gofmt, CEL removal, server-side apply) come from the base.

@christopherfickess
christopherfickess force-pushed the feat/operator-monitoring-poc-mimir branch from 8f1c7e1 to 5aca2d6 Compare August 11, 2026 15:28

Copilot AI 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.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • apis/mattermost/v1beta1/zz_generated.deepcopy.go: Generated file
Suppressed comments (1)

controllers/mattermost/mattermost/monitoring_reconcile_test.go:40

  • This reconcile test never enables MimirRules or asserts that its ConfigMap is created, remains stable, and is removed on disable. The generator test does not exercise the newly added controller/create/update/label-selected cleanup paths, so the PR's central reconciliation behavior is currently uncovered. Extend this test with the Mimir flag and ConfigMap create/delete assertions.
			Monitoring: &mmv1beta.Monitoring{
				ServiceMonitor: &mmv1beta.ServiceMonitor{Enabled: true},
				PrometheusRule: &mmv1beta.PrometheusRule{Enabled: true},

Comment thread controllers/mattermost/mattermost/monitoring.go

Copilot AI 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.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • apis/mattermost/v1beta1/zz_generated.deepcopy.go: Generated file
Suppressed comments (1)

controllers/mattermost/mattermost/monitoring_reconcile_test.go:41

  • This reconcile test never enables MimirRules, so the new controller create/idempotency/cleanup path is not exercised; only the pre-existing ServiceMonitor and PrometheusRule paths are covered. Add the Mimir setting plus assertions that mm-mimir-rules is created, remains stable on the second reconcile, and is deleted after disabling it.
			Monitoring: &mmv1beta.Monitoring{
				ServiceMonitor: &mmv1beta.ServiceMonitor{Enabled: true},
				PrometheusRule: &mmv1beta.PrometheusRule{Enabled: true},
			},

@christopherfickess
christopherfickess force-pushed the feat/operator-monitoring-poc-mimir branch 3 times, most recently from 2fc1523 to 183d869 Compare August 11, 2026 17:12
@christopherfickess
christopherfickess marked this pull request as ready for review August 11, 2026 17:47
@christopherfickess
christopherfickess marked this pull request as draft August 11, 2026 17:56
@christopherfickess
christopherfickess force-pushed the feat/operator-monitoring-poc-mimir branch from 183d869 to 6a9f3b5 Compare August 11, 2026 18:13
christopher.fickess and others added 3 commits August 11, 2026 13:16
Prometheus-free rule delivery for a Grafana Alloy + Mimir stack. Adds
spec.monitoring.mimirRules: the same per-instance, pod-scoped alert rules as
prometheusRule, delivered as a ConfigMap for a Mimir ruler-sync instead of a
PrometheusRule CRD. Create/update refuses to overwrite, and cleanup deletes only,
ConfigMaps this CR controls. ServiceMonitor + metrics Service unchanged.

Re-seated onto the updated base so the diff is only the Mimir delta.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Mirror the CodeRabbit hardening applied to the other generators:

- GenerateMimirRulesConfigMapV1Beta returns nil when spec.monitoring is
  unset, so direct callers don't panic (the reconcile path already guards
  this via mimirRulesEnabled).
- Reject a mimirRules.discoveryLabel that collides with the reserved
  marker key, which would otherwise be silently overwritten during label
  assembly and break ruler-sync discovery.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Regenerated via `make yaml` so the bundle carries the full spec.monitoring
schema (including mimirRules) and the servicemonitors/prometheusrules/
events RBAC. The committed bundle was stale (Copilot review).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • apis/mattermost/v1beta1/zz_generated.deepcopy.go: Generated file
Suppressed comments (1)

controllers/mattermost/mattermost/monitoring.go:46

  • The existing monitoring reconcile test covers create, idempotent reconcile, and cleanup for every other monitoring resource, but it never enables or asserts the new Mimir ConfigMap path. Add the Mimir option and ConfigMap assertions so the ownership guard and label-based cleanup-on-disable are exercised; otherwise regressions in the lifecycle promised by this feature are untested.
	if err := r.checkMattermostPrometheusRule(mattermost, reqLogger); err != nil {
		return err
	}
	return r.checkMattermostMimirRules(mattermost, reqLogger)

Comment thread controllers/mattermost/mattermost/monitoring.go
The Mimir feature commit predated the clusterIPs-preservation fix, so its
copy of reconcileService won during rebase and dropped the call. Restore
resources.CopyServiceEmptyAutoAssignedFields(desired, current) before
Update, matching the base branch -- without it, updates to the headless
metrics Service try to clear the immutable clusterIPs (["None"]) and fail.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants