Repository navigation
docs: add Kubernetes service discovery examples for ScrapeConfig - #8882
simonpasquier merged 2 commits into
Conversation
Add two concrete use cases for kubernetesSDConfigs in the ScrapeConfig guide (pods in selected namespaces filtered by label and named port, and a per-node exporter via the Node role) plus a note on the RBAC permissions Prometheus needs. Signed-off-by: Ayman Zahran <[email protected]>
|
@AymanZahran Thank you for the PR. Have you tested the examples in actual cluster? We don't have ci to check the examples actually work. |
simonpasquier
left a comment
There was a problem hiding this comment.
Thanks for tackling this! IMHO the examples shouldn't duplicate configurations which can be covered by ServiceMonitor, PodMonitor or Probe already.
|
|
||
| > **Note:** The Prometheus service account needs `get`, `list` and `watch` permissions on the discovered resources (for example `nodes`, `pods`, `services`, `endpoints` or `endpointslices`) in the discovered namespaces. See [Prometheus RBAC](https://prometheus-operator.dev/docs/platform/rbac/#prometheus-rbac) for details. | ||
|
|
||
| ### Example: scrape pods from specific namespaces |
There was a problem hiding this comment.
what's the motivation for this example vs. using PodMonitor with selectorMechanism: RoleSelector?
There was a problem hiding this comment.
Good question. The Pod-role Kubernetes SD example is for Prometheus-native kubernetes_sd_config behavior, like custom relabelings or address rewrites, without a PodMonitor. I'm happy to drop it if PodMonitor with selectorMechanism: RoleSelector is preferred, and keep only the Node-role example, since that one has no PodMonitor equivalent. Want me to trim it?
There was a problem hiding this comment.
Again if a use case is covered by ServiceMonitor or PodMonitor, I don't see the point of documenting a more complicated setup with ScrapeConfig.
About nodes, one can argue that it's also covered by the operator's kubelet controller but there's no CRD supporting node discovery directly so I'm fine with the second example.
There was a problem hiding this comment.
Makes sense. I dropped the Pod-role example and kept only the Node one, and added a line pointing to ServiceMonitor, PodMonitor and Probe first.
|
Thanks @slashpai. I validated the YAML against the ScrapeConfig API and the Prometheus Kubernetes SD docs, but I haven't applied these examples in a live cluster. I'm happy to add an "illustrative" note to the docs, or to try them in a kind cluster and report back. Which would you prefer? |
Address review feedback: keep only the Node-role example, which has no dedicated CRD, and point readers to ServiceMonitor/PodMonitor/Probe first. Signed-off-by: Ayman Zahran <[email protected]>
* alertmanager: add rocket chat validation * alertmanager: add test cases to cover all rocket chat URLs * build(deps): bump github.com/prometheus/prometheus Bumps [github.com/prometheus/prometheus](https://github.com/prometheus/prometheus) from 0.314.0 to 0.315.0. - [Release notes](https://github.com/prometheus/prometheus/releases) - [Changelog](https://github.com/prometheus/prometheus/blob/main/CHANGELOG.md) - [Commits](prometheus/prometheus@v0.314.0...v0.315.0) --- updated-dependencies: - dependency-name: github.com/prometheus/prometheus dependency-version: 0.315.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump github/codeql-action/upload-sarif Bumps the github-actions-deps group with 1 update: [github/codeql-action/upload-sarif](https://github.com/github/codeql-action). Updates `github/codeql-action/upload-sarif` from 4.38.1 to 4.38.2 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@1c5b675...2892aa5) --- updated-dependencies: - dependency-name: github/codeql-action/upload-sarif dependency-version: 4.38.2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions-deps ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump github.com/prometheus/exporter-toolkit Bumps [github.com/prometheus/exporter-toolkit](https://github.com/prometheus/exporter-toolkit) from 0.19.0 to 0.20.0. - [Release notes](https://github.com/prometheus/exporter-toolkit/releases) - [Commits](prometheus/exporter-toolkit@v0.19.0...v0.20.0) --- updated-dependencies: - dependency-name: github.com/prometheus/exporter-toolkit dependency-version: 0.20.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * chore: update k8s.io to v0.37.1 Signed-off-by: Simon Pasquier <[email protected]> * fix: handle unset email threading in AlertmanagerConfig conversion Converting an AlertmanagerConfig between v1beta1 and v1alpha1 panicked when an email receiver didn't set threading, because the converters dereferenced the pointer without a nil check. Since threading is optional, the conversion webhook failed for most email receivers. Return nil when threading is unset, and add the first unit tests for the conversion functions. Part of #8841 Signed-off-by: Sanchit2662 <[email protected]> * Merge pull request #8403 from nutmos/feat/telegram-bot-token-cr Feat: Add botToken support for Telegram in Alertmanager global config CR * Update PodMonitor's status subresource on PrometheusAgent reconciliations Signed-off-by: whiskey-coder <[email protected]> * Reconcile ServiceMonitor status for PrometheusAgent Reuse the configuration resource status sync to report accepted and rejected ServiceMonitors, remove stale bindings after deselection, and clean up bindings before deleting the Agent. Add feature-gated end-to-end coverage for status transitions, multiple Agents, deselection, and deletion. Signed-off-by: whiskey-coder <[email protected]> * Merge pull request #8769 from nutmos/feat/operator-separate-webhook-test Feat: enhance Webhook config test cases in operator test * chore: simplify detection of StatusForConfigurationResources feture gate Signed-off-by: Simon Pasquier <[email protected]> * build(deps): bump github.com/prometheus/common from 0.71.0 to 0.72.0 Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.71.0 to 0.72.0. - [Release notes](https://github.com/prometheus/common/releases) - [Changelog](https://github.com/prometheus/common/blob/main/CHANGELOG.md) - [Commits](prometheus/common@v0.71.0...v0.72.0) --- updated-dependencies: - dependency-name: github.com/prometheus/common dependency-version: 0.72.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * fix: add zone info to kubelet endpointslice Signed-off-by: Simon Pasquier <[email protected]> * fix: keep Pushover ttl in AlertmanagerConfig conversion The ttl field exists on PushoverConfig in both v1beta1 and v1alpha1, but the converters never copied it. Because v1alpha1 is the storage version, a ttl set through v1beta1 was silently dropped before it reached the operator, and a ttl set through v1alpha1 was lost when the object was read and written back as v1beta1. Copy the field in both directions and add a test case for it. Closes #8841 Signed-off-by: Sanchit2662 <[email protected]> * build(deps): bump sigs.k8s.io/controller-runtime from 0.25.1 to 0.25.2 Bumps [sigs.k8s.io/controller-runtime](https://github.com/kubernetes-sigs/controller-runtime) from 0.25.1 to 0.25.2. - [Release notes](https://github.com/kubernetes-sigs/controller-runtime/releases) - [Changelog](https://github.com/kubernetes-sigs/controller-runtime/blob/main/RELEASE.md) - [Commits](kubernetes-sigs/controller-runtime@v0.25.1...v0.25.2) --- updated-dependencies: - dependency-name: sigs.k8s.io/controller-runtime dependency-version: 0.25.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * update prometheus lts version to v3.13.4 Signed-off-by: dongjiang1989 <[email protected]> * update golangci linter to v2.14.0 Signed-off-by: dongjiang1989 <[email protected]> * build(deps): bump golang.org/x/sync from 0.23.0 to 0.24.0 Bumps [golang.org/x/sync](https://github.com/golang/sync) from 0.23.0 to 0.24.0. - [Commits](golang/sync@v0.23.0...v0.24.0) --- updated-dependencies: - dependency-name: golang.org/x/sync dependency-version: 0.24.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump helm/kind-action Bumps the github-actions-deps group with 1 update: [helm/kind-action](https://github.com/helm/kind-action). Updates `helm/kind-action` from 1.15.0 to 1.15.1 - [Release notes](https://github.com/helm/kind-action/releases) - [Commits](helm/kind-action@06c1ae1...1544676) --- updated-dependencies: - dependency-name: helm/kind-action dependency-version: 1.15.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions-deps ... Signed-off-by: dependabot[bot] <[email protected]> * docs: document volume permissions for persistent storage Prometheus runs as a non-root user and the operator doesn't set a Pod security context by default. When the root directory of a persistent volume (e.g. NFS or CephFS) is owned by root, Prometheus can't write to it and crash loops. Explain how to set fsGroup in the securityContext field and when it doesn't take effect. Closes #5354 Signed-off-by: Ayman Zahran <[email protected]> * fix: improve validation for PagerDuty in CRD This commit ensures that the referenced `routingKey` and `serviceKey` values aren't empty which Alertmanager would reject. Signed-off-by: Simon Pasquier <[email protected]> * test: harden testPromReloadRules() This commit ensures that when updating a PrometheusRule, the test will retry if the rule has been updated by another actor in the meantime. Signed-off-by: Simon Pasquier <[email protected]> * build(deps): bump github.com/prometheus/client_golang Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.24.1 to 1.25.0. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/v1.25.0/CHANGELOG.md) - [Commits](prometheus/client_golang@v1.24.1...v1.25.0) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-version: 1.25.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump golang.org/x/net from 0.59.0 to 0.61.0 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.59.0 to 0.61.0. - [Commits](golang/net@v0.59.0...v0.61.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-version: 0.61.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump the github-actions-deps group with 2 updates Bumps the github-actions-deps group with 2 updates: [actions/upload-artifact](https://github.com/actions/upload-artifact) and [github/codeql-action/upload-sarif](https://github.com/github/codeql-action). Updates `actions/upload-artifact` from 7.0.1 to 7.0.2 - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](actions/upload-artifact@043fb46...cf430e0) Updates `github/codeql-action/upload-sarif` from 4.38.2 to 4.38.3 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@2892aa5...24c5418) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-version: 7.0.2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions-deps - dependency-name: github/codeql-action/upload-sarif dependency-version: 4.38.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions-deps ... Signed-off-by: dependabot[bot] <[email protected]> * Merge pull request #8870 from nutmos/feat/add-telegram-validation feat: add Telegram receiver validation * Feat: add support for labels to route in Alertmanager secret config (#8865) * alertmanager: add route to the secret config to support new feature introduced in AM 0.34.0 * alertmanager: update test case fix version def * alertmanager: update logger warning message * alertmanager: update test file to match the result * feat: add extraScrapeMetrics to the global Prometheus configuration (#8810) * pkg/prometheus: add extraScrapeMetrics to the global configuration Prometheus supports extra_scrape_metrics in the global section since v3.10.0, and the --enable-feature=extra-scrape-metrics flag is being phased out in favor of it. Expose the setting on the shared CommonPrometheusFields so both Prometheus and PrometheusAgent can set it globally instead of repeating it in every scrape config. The field is version-gated to Prometheus >= 3.10.0, following the same pattern as the other global scrape settings. Regenerated CRDs, bundle.yaml, jsonnet, api-reference docs, deepcopy and client applyconfiguration. Fixes #8809 Signed-off-by: longyuxiang <[email protected]> * address review: inject extra-scrape-metrics feature flag for older versions - Drop the "can be overridden per scrape config" wording until the scrape CRDs (ServiceMonitor, PodMonitor, Probe, ScrapeConfig) gain the field; that stays a follow-up to keep this PR narrow. - For Prometheus >= v2.32.0 and < v3.10.0, inject --enable-feature=extra-scrape-metrics so the setting also works on versions that only support the feature flag; >= v3.10.0 keeps using the global config field. User-provided enableFeatures entries are not duplicated. - Sync the generated applyconfiguration wrappers (PrometheusSpec, PrometheusAgentSpec) and regenerate the API reference docs. Signed-off-by: longyuxiang <[email protected]> * address review: simplify flag injection and silence version warning - Drop the duplicate check before injecting extra-scrape-metrics into enable-feature: Prometheus handles duplicate values fine. - appendExtraScrapeMetrics now skips silently below v3.10.0 instead of going through WithMinimumVersion, which would log a misleading warning: those versions honor the setting thanks to the injected feature flag argument. - Simplify the field doc to 'It requires Prometheus >= v2.32.0.' as suggested. - Regenerate CRDs, bundle.yaml, jsonnet and api-reference docs. Signed-off-by: longyuxiang <[email protected]> --------- Signed-off-by: longyuxiang <[email protected]> * build(deps): bump github.com/prometheus/common from 0.72.0 to 0.72.1 Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.72.0 to 0.72.1. - [Release notes](https://github.com/prometheus/common/releases) - [Changelog](https://github.com/prometheus/common/blob/main/CHANGELOG.md) - [Commits](prometheus/common@v0.72.0...v0.72.1) --- updated-dependencies: - dependency-name: github.com/prometheus/common dependency-version: 0.72.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * pkg/apis: add extraScrapeMetrics to the scrape CRDs Follow-up to the global extraScrapeMetrics setting: allow configuring extra_scrape_metrics per scrape config via ServiceMonitor, PodMonitor, Probe and ScrapeConfig, as requested in review. Like the other per-scrape settings the field is version-gated to Prometheus >= v3.10.0 (per-scrape overrides are not honored on older versions, so the version warning applies here). Regenerated deepcopy, client applyconfigurations, CRDs, bundle.yaml, jsonnet and the API reference docs. Signed-off-by: longyuxiang <[email protected]> * feat: support log level configuration in runtime for Prometheus >= 3.15.0 when using Prometheus version 3.15.0 or higher, configure the log level in the runtime config section instead of using the command-line argument. Signed-off-by: Christoph Maser <[email protected]> * Merge pull request #8882 from AymanZahran/fix/6674-kubernetes-sd-examples docs: add Kubernetes service discovery examples for ScrapeConfig * docs: clarify that ServiceMonitor targets must be backed by Pods (#8878) * docs: clarify that ServiceMonitor targets must be backed by Pods Signed-off-by: Ayman Zahran <[email protected]> * chore: regenerate apply configurations Signed-off-by: Ayman Zahran <[email protected]> * docs: address review on ServiceMonitor Pod-backed note Signed-off-by: Ayman Zahran <[email protected]> * docs: clarify ServiceMonitor targets not backed by Pods Address review feedback: scraping Service targets without a Pod reference requires 'port' instead of 'targetPort' and 'filterRunning: false'; manually created Pods have no such restriction. ScrapeConfig is now suggested as an option rather than a requirement. Signed-off-by: Ayman Zahran <[email protected]> --------- Signed-off-by: Ayman Zahran <[email protected]> Co-authored-by: Ayman Zahran <[email protected]> * build: add distroless image variants Keep BusyBox images as the default while adding separately tagged distroless variants for the operator, config reloader, and admission webhook. Build, publish, sign, and validate the variants in CI. Relates to #8748 Signed-off-by: Sidheshwar Sarangal <[email protected]> * alertmanager: fix logs missing single quote * alertmanager: fix logs missing single quote * Merge pull request #8893 from nutmos/fix/pushover-sound-drop Feat: update Pushover CR conversion and check * fix: reject duplicate time interval names in AlertmanagerConfig Alertmanager refuses a configuration with two time intervals of the same name, which blocks every change until the object is fixed. Validate the names like the receiver names are validated, for v1alpha1 and v1beta1. Fixes #8887 Signed-off-by: Aryan Deshmukh <[email protected]> * build(deps): bump github.com/go-test/deep from 1.1.1 to 1.1.2 Bumps [github.com/go-test/deep](https://github.com/go-test/deep) from 1.1.1 to 1.1.2. - [Release notes](https://github.com/go-test/deep/releases) - [Changelog](https://github.com/go-test/deep/blob/main/CHANGES.md) - [Commits](go-test/deep@v1.1.1...v1.1.2) --- updated-dependencies: - dependency-name: github.com/go-test/deep dependency-version: 1.1.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump the github-actions-deps group with 2 updates Bumps the github-actions-deps group with 2 updates: [github/codeql-action/upload-sarif](https://github.com/github/codeql-action) and [streetsidesoftware/cspell-action](https://github.com/streetsidesoftware/cspell-action). Updates `github/codeql-action/upload-sarif` from 4.38.3 to 4.39.0 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@24c5418...6f2ac81) Updates `streetsidesoftware/cspell-action` from 9.1.0 to 9.2.0 - [Release notes](https://github.com/streetsidesoftware/cspell-action/releases) - [Changelog](https://github.com/streetsidesoftware/cspell-action/blob/main/CHANGELOG.md) - [Commits](streetsidesoftware/cspell-action@6f3c77c...ce1816e) --- updated-dependencies: - dependency-name: github/codeql-action/upload-sarif dependency-version: 4.39.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-deps - dependency-name: streetsidesoftware/cspell-action dependency-version: 9.2.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-deps ... Signed-off-by: dependabot[bot] <[email protected]> * fix ci file * revert change --------- Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Simon Pasquier <[email protected]> Signed-off-by: Sanchit2662 <[email protected]> Signed-off-by: whiskey-coder <[email protected]> Signed-off-by: dongjiang1989 <[email protected]> Signed-off-by: Ayman Zahran <[email protected]> Signed-off-by: longyuxiang <[email protected]> Signed-off-by: Christoph Maser <[email protected]> Signed-off-by: Sidheshwar Sarangal <[email protected]> Signed-off-by: Aryan Deshmukh <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Simon Pasquier <[email protected]> Co-authored-by: Sanchit2662 <[email protected]> Co-authored-by: whiskey-coder <[email protected]> Co-authored-by: dongjiang1989 <[email protected]> Co-authored-by: Ayman Zahran <[email protected]> Co-authored-by: longxiucai <[email protected]> Co-authored-by: Christoph Maser <[email protected]> Co-authored-by: Ayman Zahran <[email protected]> Co-authored-by: Sidheshwar Sarangal <[email protected]> Co-authored-by: Aryan Deshmukh <[email protected]>
Description
Adds concrete Kubernetes service discovery use cases to the ScrapeConfig guide (
Documentation/developer/scrapeconfig.md), as requested in #6674:role: Podrestricted withnamespaces.namesand a labelselectorsentry, keeping only container ports namedmetricsand addingnamespace/podtarget labels.role: Nodewith relabelings that rewrite__address__from__meta_kubernetes_node_address_InternalIPto port9100and use the node name asinstance.get/list/watchon the discovered resources, linking to the Prometheus RBAC section.Field names follow the
v1alpha1KubernetesSDConfig/K8SSelectorConfigtypes (capitalized roles,namespaces.names,selectors[].label).Closes: #6674
Type of change
CHANGE(fix or feature that would cause existing functionality to not work as expected)FEATURE(non-breaking change which adds functionality)BUGFIX(non-breaking change which fixes an issue)ENHANCEMENT(non-breaking change which improves existing functionality)NONE(if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)Verification
make format generateproduces no further changes.make checkpasses.mdox fmt --checkwith link validation passes for the changed file.Changelog entry