Skip to content

Prometheus operator migration - #692

Draft
mxsrc wants to merge 13 commits into
mainfrom
prometheus-operator-migration
Draft

mxsrc wants to merge 13 commits into
mainfrom
prometheus-operator-migration

Conversation

@mxsrc

@mxsrc mxsrc commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

So far we rely on a prometheus helm chart for scraping. This PR replaces that with the prometheus operator, which makes it easier to scrape dynamically generated entities, like the SPDK pods. When using the operator, CRs are created to monitor specific components. This PR introduces {Service,Pod}Monitors to scrape all of our components. Additionally, since the operator has ownership of the AlertManager, the alerts are configured to use that as well.

prometheus.enabled=true is self-contained: this chart now bundles kube-prometheus-stack as a dependency on that same flag, so nothing has to be installed beforehand.

helm install cert-manager jetstack/cert-manager -n cert-manager --create-namespace --set crds.enabled=true

helm upgrade --install simplyblock-operator helm-charts/charts/simplyblock-operator \
    -n simplyblock --create-namespace \
    --set deployment.profile=standalone \
    --set image.operator.repository="public.ecr.aws/simply-block/simplyblock-operator" \
    --set image.operator.tag="prometheus-operator-migration" \
    --set image.simplyblock.repository="public.ecr.aws/simply-block/simplyblock" \
    --set image.simplyblock.tag="main" \
    --set controlplane.observability.enabled=false \
    --set prometheus.enabled=true

To scrape with a prometheus-operator the customer already runs instead, turn the bundled one off and point
prometheus.serviceAccount at the existing Prometheus's own ServiceAccount (webappapi does a TokenReview on
every scrape's bearer token, so it has to be named here or every scrape gets a 401):

--set prometheus.enabled=true \
--set kube-prometheus-stack.crds.enabled=false \
--set kube-prometheus-stack.prometheusOperator.enabled=false \
--set kube-prometheus-stack.prometheus.enabled=false \
--set kube-prometheus-stack.alertmanager.enabled=false \
--set prometheus.serviceAccount.name=kube-prometheus-stack-prometheus \
--set prometheus.serviceAccount.namespace=monitoring

@boddumanohar boddumanohar 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.

the helm parameter prometheus.enabled looks a bit confusing. Prometheus is always needs to be present in the cluster.

In this PR, prometheus.enabled actually helps chose which prometheus to use. So probably something like:

prometheus.mode: Managed | External

would me more accurate?

Additionally I've created #957 so that upgrades from 26.3 keep working. Because those upgrades run with prometheus.enabled=false.

mxsrc and others added 13 commits November 25, 2026 19:10
…prometheus-operator

Lets a customer running their own prometheus-operator scrape this chart's
targets via ServiceMonitor/PodMonitor objects instead of the bundled
`prometheus` subchart's static scrape config. Gated behind
`prometheusOperator.enabled`, mutually exclusive with `prometheus.enabled`,
and failing fast when the monitoring.coreos.com CRDs aren't present.

The webappapi Service carried no labels of its own, only a Pod selector, so a
ServiceMonitor had nothing to match it by.
…own prometheus-operator

Converts the Grafana-provisioned alert rules and contact points in
controlplane_configmap.yaml into a PrometheusRule (all eleven rules, same
expr/for/labels/annotations) and an AlertmanagerConfig built from the same
controlplane.observability.grafana.notifications.* values, so a customer's own
Alertmanager can route these alerts instead of Grafana's alerting engine.

Independent of the previous commit's ServiceMonitor/PodMonitor objects: a
customer can take the scrape config without the rules, or the rules without
alert routing, since the PrometheusRule renders whenever prometheusOperator.enabled
is true regardless of which (if any) notifications.* receiver is configured.
…block.io annotations

Nothing reads prometheus.simplyblock.io/scrape|port|path: the bundled static
prometheus.yml has no annotation-based (kubernetes_sd_configs) discovery, and
the PodMonitor added for prometheus-operator selects storage node pods by the
role=simplyblock-storage-node label, not by annotation. They predate both
scrape paths and had no consumer in either.

The test asserting these annotations could not have caught their removal: it
rebuilds its "expected" pod by replaying injectSidecar and re-setting the same
constants by hand, rather than reading them off the real admission patch, so
it was checking its own fixture rather than the webhook's output.

Also fixes two preexisting house-style findings the quality gate surfaced on
this file (a British spelling, a misplaced closing quotation mark), unrelated
to this change but in a file this commit already touches.
Same pattern as the rebalancer's PodMonitor: selects storage node pods by
role=simplyblock-storage-node and scrapes a named container port rather than a
fixed number, since each proxy binds its own RPC_PORT on the host network.
Assumes the proxy-http port (added to the storage node pod template in the
control-plane repo) and an unauthenticated /_meta/metrics are both in place.
…or only

This chart deployed its own prometheus-community/prometheus subchart as one
of two scrape paths, mutually exclusive with the bring-your-own
prometheus-operator path (ServiceMonitor/PodMonitor/ScrapeConfig/
PrometheusRule/AlertmanagerConfig). Removes the bundled path entirely, since
maintaining two ways to scrape the same targets only kept the gap between
them from ever being forced shut.

Removed:
- The `prometheus` Chart.yaml dependency and its vendored tarball.
- The entire `prometheus:` values block (server, alertmanager,
  prometheus-pushgateway, prometheus-node-exporter, kube-state-metrics,
  configmapReload, defaultBackend) except `simplyblock.{prometheusURL,
  prometheusPORT}`, which Control Center's own Prometheus link still falls
  back to and now defaults empty.
- The legacy `simplyblock-prometheus-config` static scrape ConfigMap
  (controlplane_configmap.yaml), including its lookup-based preserve-on-
  upgrade trick.
- The Thanos querier's per-replica --store= flags against the bundled
  Prometheus's own thanos-sidecar (controlplane_deploy.yaml), which pointed
  at StatefulSet pods nothing creates once the subchart is gone.
- The now-moot prometheus.enabled/prometheusOperator.enabled mutual-
  exclusivity fail check.

Also corrected two assumptions the bundled subchart's existence had let the
code carry silently:
- managementapi.go's SB_K8S_METRICS_SERVICE_ACCOUNTS trusted the bundled
  subchart's own ServiceAccount by default; with no bundled Prometheus ever
  presenting that identity, the entry was dead weight. The management API
  now trusts only identities the chart names via prometheusOperator's
  configured account (SB_EXTRA_METRICS_SERVICE_ACCOUNTS), the same way
  SB_K8S_ADMIN_SERVICE_ACCOUNTS already works.
- podspec.go's hardcoded PROMETHEUS_URL/PROMETHEUS_PORT (where the control
  plane pushes what it measures) still names the bundled chart's old Service,
  which nothing creates anymore. Left as-is and flagged in its own comment:
  making this configurable is a separate change this commit does not make.
prometheus-operator is the only scrape path this chart supports now, so
there is no second `prometheus` value left to collide with: the old
prometheus.simplyblock.{prometheusURL,prometheusPORT} (Control Center's own
fallback) is folded in as a sibling of enabled/additionalLabels/interval/
serviceAccount under one prometheus: key, and every .Values.prometheusOperator
reference, fail-fast message, and prose mention is renamed to match.
…when enabled

prometheus.enabled now needs nothing installed beforehand: it brings its own
prometheus-operator (kube-prometheus-stack 92.2.0, condition:
prometheus.enabled) by default — CRDs, the controller, one Prometheus, and
Alertmanager (for the PrometheusRule/AlertmanagerConfig objects this chart
also renders). Grafana, node-exporter, and kube-state-metrics stay off: a
scrape target for the customer's own dashboards, not a second monitoring
stack.

The bundled Prometheus's ServiceAccount is pinned to a literal name
(simplyblock-prometheus-operator) rather than left to kube-prometheus-stack's
own release-derived default, so prometheus.serviceAccount can name it without
predicting it — the metrics-scraper trust that used to need a manual
`kubectl get prometheus ... serviceAccountName` lookup is wired by default
now. Its prometheusSpec also turns off every selector's
NilUsesHelmValues, which otherwise restricts discovery to objects carrying a
release label this chart's own ServiceMonitor/PodMonitor/ScrapeConfig/
PrometheusRule objects don't set.

To scrape with a prometheus-operator the customer already runs instead, every
component kube-prometheus-stack renders has to be turned off explicitly
(values.yaml documents the full list — cluster-component scrapers and
defaultRules are separate toggles that don't follow
prometheusOperator.enabled/prometheus.enabled, discovered by testing each
override combination against `helm template` until nothing from the
dependency rendered). Left on with monitoring.coreos.com CRDs already present
from elsewhere, the chart now fails fast rather than installing a second
prometheus-operator: a release-ownership check (via `lookup`, comparing the
existing ServiceMonitor CRD's meta.helm.sh/release-name annotation against
this release) tells apart "ours, from import a prior upgrade of this same
release" from "somebody else's."

The existing "CRD missing" fail-fast checks in
prometheus-operator-servicemonitors.yaml and prometheus-operator-alerting.yaml
had to change shape too: .Capabilities.APIVersions is captured before this
same install's own kube-prometheus-stack dependency would create its CRDs, so
on a fresh bundled install the literal capability check would fail an install
that was about to supply the CRD itself. They now skip that check entirely
whenever bundling is in effect (simplyblock.bundlesPrometheusOperator) and
trust Helm's own install ordering instead, applying only to the
not-bundling (bring-your-own) path.
…eus subchart removal deleted

TestAKeyHoldingDotsIsOneSegment anchored on prometheus.server.extraArgs."storage.tsdb.min-block-duration",
which no longer exists now that the bundled Prometheus subchart is gone. Point it at an Ingress annotation
key instead, and resync the chart/ copy this module keeps of values.yaml and Chart.yaml.
…already scrapes it

managementAPIObjects always applied a Prometheus+Thanos StatefulSet, unconditionally,
for every local ControlPlane install -- including one where the chart's own
prometheus.enabled path (bundled kube-prometheus-stack, or bring-your-own) already
scrapes the management API through a ServiceMonitor. The two ran side by side,
duplicating scrapes, with no flag to turn either off.

Detect the chart's ServiceMonitor instead of adding a new one, matching the
convention internal/prerequisites already uses for cert-manager and the other
cluster add-ons: check what's on the cluster before installing, rather than
threading a coordination flag through the chart and the CRD. Present, this
control plane's own Prometheus, Thanos, and RBAC are left out of the apply.

Known gap: flipping prometheus.enabled on for an install that already has its
own Prometheus StatefulSet leaves that StatefulSet in place rather than
deleting it -- applyAll only ever applies what's in the set, never prunes.
…etheus.enabled off

An upgrade from 26.3 runs with prometheus.enabled=false, where the operator
still runs simplyblock-prometheus. The migration broke that path three ways:

- The management API no longer trusted simplyblock-prometheus, so every
  scrape got a 401. The operator now always trusts it, then the chart's extras.
- Control Center's Prometheus URL defaulted to prometheus-operated, which only
  exists with the bundled stack. It now follows prometheus.enabled.
- Thanos Query lost the sidecar --store, hiding the newest two hours. It is
  back whenever prometheus.enabled is off.

With prometheus.enabled on, the ScrapeConfig used authorization.credentialsFile,
which prometheus-operator does not have. It now presents the token of a chart
ServiceAccount, simplyblock-metrics-scraper, which the management API trusts.

helm-charts/scripts/test-prometheus-values.sh checks both renders and runs in
the Helm lint workflow.

Claude-Session: https://claude.ai/code/session_011oztNZUjNFk6NYW7UXA1A2
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.

2 participants