diff --git a/Documentation/api.md b/Documentation/api.md index a5d384d9a..a5080a910 100644 --- a/Documentation/api.md +++ b/Documentation/api.md @@ -2826,6 +2826,21 @@ If unset, the operator assumes the “Endpoints” role.</p> </tr> <tr> <td> +<code>tsdb</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.TSDBSpec"> +TSDBSpec +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>Defines the runtime reloadable configuration of the timeseries database(TSDB). +It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0.</p> +</td> +</tr> +<tr> +<td> <code>baseImage</code><br/> <em> string @@ -3140,20 +3155,6 @@ ensure only clients authorized to perform these actions can do so.</p> <a href="https://prometheus.io/docs/prometheus/latest/querying/api/#tsdb-admin-apis">https://prometheus.io/docs/prometheus/latest/querying/api/#tsdb-admin-apis</a></p> </td> </tr> -<tr> -<td> -<code>tsdb</code><br/> -<em> -<a href="#monitoring.coreos.com/v1.TSDBSpec"> -TSDBSpec -</a> -</em> -</td> -<td> -<p>Defines the runtime reloadable configuration of the timeseries database -(TSDB).</p> -</td> -</tr> </table> </td> </tr> @@ -7573,6 +7574,21 @@ ServiceDiscoveryRole If unset, the operator assumes the “Endpoints” role.</p> </td> </tr> +<tr> +<td> +<code>tsdb</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.TSDBSpec"> +TSDBSpec +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>Defines the runtime reloadable configuration of the timeseries database(TSDB). +It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0.</p> +</td> +</tr> </tbody> </table> <h3 id="monitoring.coreos.com/v1.Condition">Condition @@ -11883,6 +11899,21 @@ If unset, the operator assumes the “Endpoints” role.</p> </tr> <tr> <td> +<code>tsdb</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.TSDBSpec"> +TSDBSpec +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>Defines the runtime reloadable configuration of the timeseries database(TSDB). +It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0.</p> +</td> +</tr> +<tr> +<td> <code>baseImage</code><br/> <em> string @@ -12197,20 +12228,6 @@ ensure only clients authorized to perform these actions can do so.</p> <a href="https://prometheus.io/docs/prometheus/latest/querying/api/#tsdb-admin-apis">https://prometheus.io/docs/prometheus/latest/querying/api/#tsdb-admin-apis</a></p> </td> </tr> -<tr> -<td> -<code>tsdb</code><br/> -<em> -<a href="#monitoring.coreos.com/v1.TSDBSpec"> -TSDBSpec -</a> -</em> -</td> -<td> -<p>Defines the runtime reloadable configuration of the timeseries database -(TSDB).</p> -</td> -</tr> </tbody> </table> <h3 id="monitoring.coreos.com/v1.PrometheusStatus">PrometheusStatus @@ -14829,7 +14846,7 @@ string <h3 id="monitoring.coreos.com/v1.TSDBSpec">TSDBSpec </h3> <p> -(<em>Appears on:</em><a href="#monitoring.coreos.com/v1.PrometheusSpec">PrometheusSpec</a>) +(<em>Appears on:</em><a href="#monitoring.coreos.com/v1.CommonPrometheusFields">CommonPrometheusFields</a>) </p> <div> </div> @@ -14857,7 +14874,7 @@ respect to the TSDB max time.</p> the timestamp of the sample is >= (TSDB.MaxTime - outOfOrderTimeWindow).</p> <p>This is an <em>experimental feature</em>, it may change in any upcoming release in a breaking way.</p> -<p>It requires Prometheus >= v2.39.0.</p> +<p>It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0.</p> </td> </tr> </tbody> @@ -18144,6 +18161,21 @@ ServiceDiscoveryRole If unset, the operator assumes the “Endpoints” role.</p> </td> </tr> +<tr> +<td> +<code>tsdb</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.TSDBSpec"> +TSDBSpec +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>Defines the runtime reloadable configuration of the timeseries database(TSDB). +It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0.</p> +</td> +</tr> </table> </td> </tr> @@ -25606,6 +25638,21 @@ ServiceDiscoveryRole If unset, the operator assumes the “Endpoints” role.</p> </td> </tr> +<tr> +<td> +<code>tsdb</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.TSDBSpec"> +TSDBSpec +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>Defines the runtime reloadable configuration of the timeseries database(TSDB). +It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0.</p> +</td> +</tr> </tbody> </table> <h3 id="monitoring.coreos.com/v1alpha1.PuppetDBSDConfig">PuppetDBSDConfig diff --git a/bundle.yaml b/bundle.yaml index e2e093c5f..69fa6fc16 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -28422,6 +28422,26 @@ spec: required: - endpoint type: object + tsdb: + description: |- + Defines the runtime reloadable configuration of the timeseries database(TSDB). + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. + properties: + outOfOrderTimeWindow: + description: |- + Configures how old an out-of-order/out-of-bounds sample can be with + respect to the TSDB max time. + + An out-of-order/out-of-bounds sample is ingested into the TSDB as long as + the timestamp of the sample is >= (TSDB.MaxTime - outOfOrderTimeWindow). + + This is an *experimental feature*, it may change in any upcoming release + in a breaking way. + + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. + pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$ + type: string + type: object version: description: |- Version of Prometheus being deployed. The operator uses this information @@ -41074,8 +41094,8 @@ spec: type: object tsdb: description: |- - Defines the runtime reloadable configuration of the timeseries database - (TSDB). + Defines the runtime reloadable configuration of the timeseries database(TSDB). + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. properties: outOfOrderTimeWindow: description: |- @@ -41088,7 +41108,7 @@ spec: This is an *experimental feature*, it may change in any upcoming release in a breaking way. - It requires Prometheus >= v2.39.0. + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$ type: string type: object diff --git a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml index dffa02779..d652d972b 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml @@ -8249,6 +8249,26 @@ spec: required: - endpoint type: object + tsdb: + description: |- + Defines the runtime reloadable configuration of the timeseries database(TSDB). + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. + properties: + outOfOrderTimeWindow: + description: |- + Configures how old an out-of-order/out-of-bounds sample can be with + respect to the TSDB max time. + + An out-of-order/out-of-bounds sample is ingested into the TSDB as long as + the timestamp of the sample is >= (TSDB.MaxTime - outOfOrderTimeWindow). + + This is an *experimental feature*, it may change in any upcoming release + in a breaking way. + + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. + pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$ + type: string + type: object version: description: |- Version of Prometheus being deployed. The operator uses this information diff --git a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml index 5b27472d2..dd4eeadb4 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml @@ -10414,8 +10414,8 @@ spec: type: object tsdb: description: |- - Defines the runtime reloadable configuration of the timeseries database - (TSDB). + Defines the runtime reloadable configuration of the timeseries database(TSDB). + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. properties: outOfOrderTimeWindow: description: |- @@ -10428,7 +10428,7 @@ spec: This is an *experimental feature*, it may change in any upcoming release in a breaking way. - It requires Prometheus >= v2.39.0. + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$ type: string type: object diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml index ddb79e505..fee75cad0 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml @@ -8250,6 +8250,26 @@ spec: required: - endpoint type: object + tsdb: + description: |- + Defines the runtime reloadable configuration of the timeseries database(TSDB). + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. + properties: + outOfOrderTimeWindow: + description: |- + Configures how old an out-of-order/out-of-bounds sample can be with + respect to the TSDB max time. + + An out-of-order/out-of-bounds sample is ingested into the TSDB as long as + the timestamp of the sample is >= (TSDB.MaxTime - outOfOrderTimeWindow). + + This is an *experimental feature*, it may change in any upcoming release + in a breaking way. + + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. + pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$ + type: string + type: object version: description: |- Version of Prometheus being deployed. The operator uses this information diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml index 0236da918..006edea7e 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml @@ -10415,8 +10415,8 @@ spec: type: object tsdb: description: |- - Defines the runtime reloadable configuration of the timeseries database - (TSDB). + Defines the runtime reloadable configuration of the timeseries database(TSDB). + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. properties: outOfOrderTimeWindow: description: |- @@ -10429,7 +10429,7 @@ spec: This is an *experimental feature*, it may change in any upcoming release in a breaking way. - It requires Prometheus >= v2.39.0. + It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$ type: string type: object diff --git a/jsonnet/prometheus-operator/prometheusagents-crd.json b/jsonnet/prometheus-operator/prometheusagents-crd.json index c35f0732f..d33312872 100644 --- a/jsonnet/prometheus-operator/prometheusagents-crd.json +++ b/jsonnet/prometheus-operator/prometheusagents-crd.json @@ -6901,6 +6901,17 @@ ], "type": "object" }, + "tsdb": { + "description": "Defines the runtime reloadable configuration of the timeseries database(TSDB).\nIt requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0.", + "properties": { + "outOfOrderTimeWindow": { + "description": "Configures how old an out-of-order/out-of-bounds sample can be with\nrespect to the TSDB max time.\n\nAn out-of-order/out-of-bounds sample is ingested into the TSDB as long as\nthe timestamp of the sample is >= (TSDB.MaxTime - outOfOrderTimeWindow).\n\nThis is an *experimental feature*, it may change in any upcoming release\nin a breaking way.\n\nIt requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0.", + "pattern": "^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$", + "type": "string" + } + }, + "type": "object" + }, "version": { "description": "Version of Prometheus being deployed. The operator uses this information\nto generate the Prometheus StatefulSet + configuration files.\n\nIf not specified, the operator assumes the latest upstream version of\nPrometheus available at the time when the version of the operator was\nreleased.", "type": "string" diff --git a/jsonnet/prometheus-operator/prometheuses-crd.json b/jsonnet/prometheus-operator/prometheuses-crd.json index 3814e4ac0..b3ffe35e3 100644 --- a/jsonnet/prometheus-operator/prometheuses-crd.json +++ b/jsonnet/prometheus-operator/prometheuses-crd.json @@ -8800,10 +8800,10 @@ "type": "object" }, "tsdb": { - "description": "Defines the runtime reloadable configuration of the timeseries database\n(TSDB).", + "description": "Defines the runtime reloadable configuration of the timeseries database(TSDB).\nIt requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0.", "properties": { "outOfOrderTimeWindow": { - "description": "Configures how old an out-of-order/out-of-bounds sample can be with\nrespect to the TSDB max time.\n\nAn out-of-order/out-of-bounds sample is ingested into the TSDB as long as\nthe timestamp of the sample is >= (TSDB.MaxTime - outOfOrderTimeWindow).\n\nThis is an *experimental feature*, it may change in any upcoming release\nin a breaking way.\n\nIt requires Prometheus >= v2.39.0.", + "description": "Configures how old an out-of-order/out-of-bounds sample can be with\nrespect to the TSDB max time.\n\nAn out-of-order/out-of-bounds sample is ingested into the TSDB as long as\nthe timestamp of the sample is >= (TSDB.MaxTime - outOfOrderTimeWindow).\n\nThis is an *experimental feature*, it may change in any upcoming release\nin a breaking way.\n\nIt requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0.", "pattern": "^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$", "type": "string" } diff --git a/pkg/apis/monitoring/v1/prometheus_types.go b/pkg/apis/monitoring/v1/prometheus_types.go index c2f555d1d..30029cbbf 100644 --- a/pkg/apis/monitoring/v1/prometheus_types.go +++ b/pkg/apis/monitoring/v1/prometheus_types.go @@ -787,6 +787,12 @@ type CommonPrometheusFields struct { // // +optional ServiceDiscoveryRole *ServiceDiscoveryRole `json:"serviceDiscoveryRole,omitempty"` + + // Defines the runtime reloadable configuration of the timeseries database(TSDB). + // It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. + // + // +optional + TSDB *TSDBSpec `json:"tsdb,omitempty"` } // +kubebuilder:validation:Enum=HTTP;ProcessSignal @@ -1009,10 +1015,6 @@ type PrometheusSpec struct { // For more information: // https://prometheus.io/docs/prometheus/latest/querying/api/#tsdb-admin-apis EnableAdminAPI bool `json:"enableAdminAPI,omitempty"` - - // Defines the runtime reloadable configuration of the timeseries database - // (TSDB). - TSDB TSDBSpec `json:"tsdb,omitempty"` } type PrometheusTracingConfig struct { @@ -1881,7 +1883,7 @@ type TSDBSpec struct { // This is an *experimental feature*, it may change in any upcoming release // in a breaking way. // - // It requires Prometheus >= v2.39.0. + // It requires Prometheus >= v2.39.0 or PrometheusAgent >= v2.54.0. OutOfOrderTimeWindow Duration `json:"outOfOrderTimeWindow,omitempty"` } diff --git a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go index 333e687b9..4d8c98495 100644 --- a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go @@ -984,6 +984,11 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) { *out = new(ServiceDiscoveryRole) **out = **in } + if in.TSDB != nil { + in, out := &in.TSDB, &out.TSDB + *out = new(TSDBSpec) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CommonPrometheusFields. @@ -2152,7 +2157,6 @@ func (in *PrometheusSpec) DeepCopyInto(out *PrometheusSpec) { *out = new(Exemplars) (*in).DeepCopyInto(*out) } - out.TSDB = in.TSDB } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusSpec. diff --git a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go index 0b6423bd8..f5b772998 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go +++ b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go @@ -109,6 +109,7 @@ type CommonPrometheusFieldsApplyConfiguration struct { MaximumStartupDurationSeconds *int32 `json:"maximumStartupDurationSeconds,omitempty"` ScrapeClasses []ScrapeClassApplyConfiguration `json:"scrapeClasses,omitempty"` ServiceDiscoveryRole *monitoringv1.ServiceDiscoveryRole `json:"serviceDiscoveryRole,omitempty"` + TSDB *TSDBSpecApplyConfiguration `json:"tsdb,omitempty"` } // CommonPrometheusFieldsApplyConfiguration constructs a declarative configuration of the CommonPrometheusFields type for use with @@ -844,3 +845,11 @@ func (b *CommonPrometheusFieldsApplyConfiguration) WithServiceDiscoveryRole(valu b.ServiceDiscoveryRole = &value return b } + +// WithTSDB sets the TSDB field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the TSDB field is set to the value of the last call. +func (b *CommonPrometheusFieldsApplyConfiguration) WithTSDB(value *TSDBSpecApplyConfiguration) *CommonPrometheusFieldsApplyConfiguration { + b.TSDB = value + return b +} diff --git a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go index 8d715eaa3..3c746ad75 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go @@ -48,7 +48,6 @@ type PrometheusSpecApplyConfiguration struct { Exemplars *ExemplarsApplyConfiguration `json:"exemplars,omitempty"` EvaluationInterval *monitoringv1.Duration `json:"evaluationInterval,omitempty"` EnableAdminAPI *bool `json:"enableAdminAPI,omitempty"` - TSDB *TSDBSpecApplyConfiguration `json:"tsdb,omitempty"` } // PrometheusSpecApplyConfiguration constructs a declarative configuration of the PrometheusSpec type for use with @@ -785,6 +784,14 @@ func (b *PrometheusSpecApplyConfiguration) WithServiceDiscoveryRole(value monito return b } +// WithTSDB sets the TSDB field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the TSDB field is set to the value of the last call. +func (b *PrometheusSpecApplyConfiguration) WithTSDB(value *TSDBSpecApplyConfiguration) *PrometheusSpecApplyConfiguration { + b.TSDB = value + return b +} + // WithBaseImage sets the BaseImage field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the BaseImage field is set to the value of the last call. @@ -962,11 +969,3 @@ func (b *PrometheusSpecApplyConfiguration) WithEnableAdminAPI(value bool) *Prome b.EnableAdminAPI = &value return b } - -// WithTSDB sets the TSDB field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the TSDB field is set to the value of the last call. -func (b *PrometheusSpecApplyConfiguration) WithTSDB(value *TSDBSpecApplyConfiguration) *PrometheusSpecApplyConfiguration { - b.TSDB = value - return b -} diff --git a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go index bb163ebd7..3445887b4 100644 --- a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go @@ -772,3 +772,11 @@ func (b *PrometheusAgentSpecApplyConfiguration) WithServiceDiscoveryRole(value m b.ServiceDiscoveryRole = &value return b } + +// WithTSDB sets the TSDB field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the TSDB field is set to the value of the last call. +func (b *PrometheusAgentSpecApplyConfiguration) WithTSDB(value *v1.TSDBSpecApplyConfiguration) *PrometheusAgentSpecApplyConfiguration { + b.TSDB = value + return b +} diff --git a/pkg/prometheus/agent/operator.go b/pkg/prometheus/agent/operator.go index 0b0970ed9..ca3a963cc 100644 --- a/pkg/prometheus/agent/operator.go +++ b/pkg/prometheus/agent/operator.go @@ -909,6 +909,7 @@ func (c *Operator) createOrUpdateConfigurationSecret(ctx context.Context, p *mon pmons, bmons, scrapeConfigs, + p.Spec.TSDB, store, additionalScrapeConfigs, ) diff --git a/pkg/prometheus/promcfg.go b/pkg/prometheus/promcfg.go index ff15878af..884c1f444 100644 --- a/pkg/prometheus/promcfg.go +++ b/pkg/prometheus/promcfg.go @@ -704,7 +704,7 @@ func (cg *ConfigGenerator) GenerateServerConfiguration( queryLogFile string, ruleSelector *metav1.LabelSelector, exemplars *monitoringv1.Exemplars, - tsdb monitoringv1.TSDBSpec, + tsdb *monitoringv1.TSDBSpec, alerting *monitoringv1.AlertingSpec, remoteRead []monitoringv1.RemoteReadSpec, sMons map[string]*monitoringv1.ServiceMonitor, @@ -808,7 +808,7 @@ func (cg *ConfigGenerator) GenerateServerConfiguration( return yaml.Marshal(cfg) } -func (cg *ConfigGenerator) appendStorageSettingsConfig(cfg yaml.MapSlice, exemplars *monitoringv1.Exemplars, tsdb monitoringv1.TSDBSpec) (yaml.MapSlice, error) { +func (cg *ConfigGenerator) appendStorageSettingsConfig(cfg yaml.MapSlice, exemplars *monitoringv1.Exemplars, tsdb *monitoringv1.TSDBSpec) (yaml.MapSlice, error) { var ( storage yaml.MapSlice cgStorage = cg.WithMinimumVersion("2.29.0") @@ -823,7 +823,7 @@ func (cg *ConfigGenerator) appendStorageSettingsConfig(cfg yaml.MapSlice, exempl }) } - if tsdb.OutOfOrderTimeWindow != "" { + if tsdb != nil && tsdb.OutOfOrderTimeWindow != "" { storage = cg.WithMinimumVersion("2.39.0").AppendMapItem(storage, "tsdb", yaml.MapSlice{ { Key: "out_of_order_time_window", @@ -2519,6 +2519,7 @@ func (cg *ConfigGenerator) GenerateAgentConfiguration( pMons map[string]*monitoringv1.PodMonitor, probes map[string]*monitoringv1.Probe, sCons map[string]*monitoringv1alpha1.ScrapeConfig, + tsdb *monitoringv1.TSDBSpec, store *assets.StoreBuilder, additionalScrapeConfigs []byte, ) ([]byte, error) { @@ -2564,6 +2565,18 @@ func (cg *ConfigGenerator) GenerateAgentConfiguration( Value: scrapeConfigs, }) + // TSDB + if tsdb != nil && tsdb.OutOfOrderTimeWindow != "" { + var storage yaml.MapSlice + storage = cg.AppendMapItem(storage, "tsdb", yaml.MapSlice{ + { + Key: "out_of_order_time_window", + Value: tsdb.OutOfOrderTimeWindow, + }, + }) + cfg = cg.WithMinimumVersion("2.54.0").AppendMapItem(cfg, "storage", storage) + } + // Remote write config if len(cpf.RemoteWrite) > 0 { cfg = append(cfg, cg.generateRemoteWriteConfig(store)) diff --git a/pkg/prometheus/promcfg_test.go b/pkg/prometheus/promcfg_test.go index 326a61217..fd7d83bf8 100644 --- a/pkg/prometheus/promcfg_test.go +++ b/pkg/prometheus/promcfg_test.go @@ -5396,7 +5396,7 @@ func TestTSDBConfig(t *testing.T) { p.Spec.CommonPrometheusFields.Version = tc.version } if tc.tsdb != nil { - p.Spec.TSDB = *tc.tsdb + p.Spec.TSDB = tc.tsdb } cg := mustNewConfigGenerator(t, p) @@ -5424,6 +5424,61 @@ func TestTSDBConfig(t *testing.T) { } } +func TestTSDBConfigPrometheusAgent(t *testing.T) { + for _, tc := range []struct { + name string + p *monitoringv1.Prometheus + version string + tsdb *monitoringv1.TSDBSpec + golden string + }{ + { + name: "PrometheusAgent no TSDB config", + golden: "PrometheusAgent_no_TSDB_config.golden", + }, + { + name: "PrometheusAgent TSDB config < v2.54.0", + version: "v2.53.0", + tsdb: &monitoringv1.TSDBSpec{ + OutOfOrderTimeWindow: monitoringv1.Duration("10m"), + }, + golden: "PrometheusAgent_TSDB_config_less_than_v2.53.0.golden", + }, + { + + name: "PrometheusAgent TSDB config >= v2.54.0", + version: "v2.54.0", + tsdb: &monitoringv1.TSDBSpec{ + OutOfOrderTimeWindow: monitoringv1.Duration("10m"), + }, + golden: "PrometheusAgent_TSDB_config_greater_than_or_equal_to_v2.54.0.golden", + }, + } { + t.Run(tc.name, func(t *testing.T) { + p := defaultPrometheus() + if tc.version != "" { + p.Spec.CommonPrometheusFields.Version = tc.version + } + if tc.tsdb != nil { + p.Spec.TSDB = tc.tsdb + } + + cg := mustNewConfigGenerator(t, p) + cfg, err := cg.GenerateAgentConfiguration( + nil, + nil, + nil, + nil, + tc.tsdb, + &assets.StoreBuilder{}, + nil, + ) + require.NoError(t, err) + golden.Assert(t, string(cfg), tc.golden) + }) + } +} + func TestGenerateRelabelConfig(t *testing.T) { p := defaultPrometheus() diff --git a/pkg/prometheus/testdata/PrometheusAgent_TSDB_config_greater_than_or_equal_to_v2.54.0.golden b/pkg/prometheus/testdata/PrometheusAgent_TSDB_config_greater_than_or_equal_to_v2.54.0.golden new file mode 100644 index 000000000..294e72225 --- /dev/null +++ b/pkg/prometheus/testdata/PrometheusAgent_TSDB_config_greater_than_or_equal_to_v2.54.0.golden @@ -0,0 +1,9 @@ +global: + scrape_interval: 30s + external_labels: + prometheus: default/test + prometheus_replica: $(POD_NAME) +scrape_configs: [] +storage: + tsdb: + out_of_order_time_window: 10m diff --git a/pkg/prometheus/testdata/PrometheusAgent_TSDB_config_less_than_v2.53.0.golden b/pkg/prometheus/testdata/PrometheusAgent_TSDB_config_less_than_v2.53.0.golden new file mode 100644 index 000000000..8d09a4dc2 --- /dev/null +++ b/pkg/prometheus/testdata/PrometheusAgent_TSDB_config_less_than_v2.53.0.golden @@ -0,0 +1,6 @@ +global: + scrape_interval: 30s + external_labels: + prometheus: default/test + prometheus_replica: $(POD_NAME) +scrape_configs: [] diff --git a/pkg/prometheus/testdata/PrometheusAgent_no_TSDB_config.golden b/pkg/prometheus/testdata/PrometheusAgent_no_TSDB_config.golden new file mode 100644 index 000000000..8d09a4dc2 --- /dev/null +++ b/pkg/prometheus/testdata/PrometheusAgent_no_TSDB_config.golden @@ -0,0 +1,6 @@ +global: + scrape_interval: 30s + external_labels: + prometheus: default/test + prometheus_replica: $(POD_NAME) +scrape_configs: []