Skip to content

feat: migrate retention options to config file#8547

Merged
simonpasquier merged 1 commit into
prometheus-operator:mainfrom
vprashar2929:feat-retention-cfg
Jun 10, 2026
Merged

feat: migrate retention options to config file#8547
simonpasquier merged 1 commit into
prometheus-operator:mainfrom
vprashar2929:feat-retention-cfg

Conversation

@vprashar2929

Copy link
Copy Markdown
Contributor

Description

This commit migrates retention options from CLI flags to config file as per Prometheus v3 release which deprecates the
storage.tsdb.retention flags (prometheus/prometheus#18200) With this change the operator writes the retention options to the config file. For older Prometheus versions the CLI flags continue to be used

Addresses #8522

Written with the help of Claude Code

Closes: #8522

If you're contributing for the first-time, check our contribution guidelines.

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • 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

Please check the Prometheus-Operator testing guidelines for recommendations about automated tests.

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.


@vprashar2929
vprashar2929 requested a review from a team as a code owner April 29, 2026 17:43
Comment thread pkg/prometheus/server/statefulset.go Outdated
@@ -403,12 +403,12 @@ func buildServerArgs(cg *prompkg.ConfigGenerator, p *monitoringv1.Prometheus) []
}

if retentionTimeFlagValue != "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cg.WithMaximumVersion("3.11.0") would print a warning which we don't want.

Suggested change
if retentionTimeFlagValue != "" {
// Starting with Prometheus v3.11.0, retention settings are populated in the configuration file.
if retentionTimeFlagValue != "" && cg.Version().LT(semver.MustPass("3.11.0")) {

Comment thread pkg/prometheus/server/statefulset.go Outdated
promArgs = cg.WithMaximumVersion("3.11.0").AppendCommandlineArgument(promArgs, monitoringv1.Argument{Name: retentionTimeFlagName, Value: retentionTimeFlagValue})
}

if p.Spec.RetentionSize != "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here

Comment thread pkg/prometheus/promcfg.go Outdated
if cg.WithMinimumVersion("3.11.0").IsCompatible() {
var retentionSlice yaml.MapSlice
retentionTime := string(retention)
if retentionTime == "" && retentionSize == "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we need a way to avoid duplication for defaults between here and pkg/prometheus/server/statefulset.go

Comment thread pkg/prometheus/promcfg.go Outdated
selector metav1.LabelSelector,
selectorMechanism *monitoringv1.SelectorMechanism,
roles []string) k8sSDConfigOptions {
roles []string,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please avoid changes unrelated to the PR

Comment thread pkg/prometheus/promcfg_test.go Outdated
GoGC: ptr.To(int32(25)),
},
Golden: "RuntimeConfig_GoGC_Not_Set.golden",
Golden: "RuntimeConfig_GoGC_Not_Set_v2.52.0.golden",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please revert

@vprashar2929
vprashar2929 force-pushed the feat-retention-cfg branch 2 times, most recently from 8616967 to cfe0be9 Compare May 13, 2026 09:22
@vprashar2929

Copy link
Copy Markdown
Contributor Author

@simonpasquier Can we have a re-review of this?


// TestRetentionAndRetentionSizeNoCLIFlags asserts that retention CLI flags
// are not emitted for Prometheus >= v3.11.0.
func TestRetentionAndRetentionSizeNoCLIFlags(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we make this subtests of TestRetentionAndRetentionSize()?

This commit migrates retention options from CLI flags to config file
as per Prometheus v3 release which deprecates the
`storage.tsdb.retention` flags (prometheus/prometheus#18200)
With this change the operator writes the retention options to the
config file. For older Prometheus versions the CLI flags continue
to be used

Addresses prometheus-operator#8522

Written with the help of Claude Code

Signed-off-by: vprashar2929 <[email protected]>
@vprashar2929

Copy link
Copy Markdown
Contributor Author

@simonpasquier Implemented the review comments and updated the PR. Could you please re review it when convenient?

@simonpasquier simonpasquier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks!

@simonpasquier
simonpasquier merged commit c06fa58 into prometheus-operator:main Jun 10, 2026
22 checks passed
@nutmos nutmos mentioned this pull request Jun 11, 2026
5 tasks
dongjiang1989 added a commit to kubeservice-stack/prometheus-operator that referenced this pull request Jun 22, 2026
Main merged PR prometheus-operator#8547 which added storage.tsdb.retention.time to the
generated Prometheus config. Update the OutscaleSD golden test files
to include this new section.
sdwilsh pushed a commit to sdwilsh/ansible-playbooks that referenced this pull request Jul 22, 2026
…r to v0.92.1 (#1765)

##### [\`v0.92.1\`](https://github.com/prometheus-operator/prometheus-operator/releases/tag/v0.92.1)

- \[BUGFIX] Fix "namespace not found" errors when the operator watches monitoring and workload resources in different resources. [#8658](prometheus-operator/prometheus-operator#8658)

---
##### [\`v0.92.0\`](https://github.com/prometheus-operator/prometheus-operator/releases/tag/v0.92.0)

> \[!NOTE]
> The `PrometheusTopologySharding` and `PrometheusShardRetentionPolicy` feature gates have been promoted to **Beta** in this release and are now enabled by default. See the [sharding documentation](https://prometheus-operator.dev/docs/platform/sharding/) for details.

- \[CHANGE] Add URL validation for the `tokenUrl` field in OAuth2 configuration across all CRDs. [#8579](prometheus-operator/prometheus-operator#8579)
- \[CHANGE] Add URL validation for the `url` field in `RemoteReadSpec` in `Prometheus` CRD. [#8596](prometheus-operator/prometheus-operator#8596)
- \[FEATURE] Migrate retention options from CLI flags to the config file for `Prometheus` CRD (Prometheus >= v3 uses the config file; older versions continue to use CLI flags). [#8547](prometheus-operator/prometheus-operator#8547)
- \[FEATURE] Add `staleSeriesCompactionThreshold` field to `TSDBSpec` in `Prometheus` and `PrometheusAgent` CRDs. [#8563](prometheus-operator/prometheus-operator#8563)
- \[FEATURE] Add `labelNameUnderscoreSanitization` and `labelNamePreserveMultipleUnderscores` fields to `OTLPConfig` in `Prometheus` and `PrometheusAgent` CRDs. [#8562](prometheus-operator/prometheus-operator#8562)
- \[FEATURE] Add `payload` field to Webhook receiver in `AlertmanagerConfig` CRD. [#8507](prometheus-operator/prometheus-operator#8507)
- \[ENHANCEMENT] Use pod topology labels for zone sharding on Kubernetes >= 1.35 when the `PrometheusTopologySharding` feature gate is enabled (removes the need for `attachMetadata.node=true`). [#8564](prometheus-operator/prometheus-operator#8564)
- \[ENHANCEMENT] Add validation for the Slack `update_message` field in Alertmanager configuration Secret. [#8556](prometheus-operator/prometheus-operator#8556)
- \[BUGFIX] Validate target labels in `Probe` static configuration to prevent invalid Prometheus scrape configs. [#7901](prometheus-operator/prometheus-operator#7901)
- \[BUGFIX] Fix goroutine leak and data race in `pollBasedListerWatcher`. [#8593](prometheus-operator/prometheus-operator#8593)
- \[BUGFIX] Validate `ProxyConfig` in OAuth2 configuration. [#8610](prometheus-operator/prometheus-operator#8610)
- \[BUGFIX] Fix SMTP smarthost format error handling in Alertmanager configuration. [#8586](prometheus-operator/prometheus-operator#8586)
- \[BUGFIX] Fix missing `return` in admission webhook after marshal failure. [#8582](prometheus-operator/prometheus-operator#8582)
- \[BUGFIX] Fix `FindOwner` to return `nil` on `meta.Accessor` error. [#8585](prometheus-operator/prometheus-operator#8585)
- \[BUGFIX] Fix dropped gzip `Close` errors in `GzipConfig` and `GunzipConfig`. [#8573](prometheus-operator/prometheus-operator#8573)
- \[BUGFIX] Fix panic on malformed key=value flag input (e.g. `--labels "key"`). [#8560](prometheus-operator/prometheus-operator#8560)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate retention options from CLI to configuration file

2 participants