diff --git a/Documentation/api.md b/Documentation/api.md index d82f61166..3e8d37ba6 100644 --- a/Documentation/api.md +++ b/Documentation/api.md @@ -1724,6 +1724,23 @@ Duration </tr> <tr> <td> +<code>scrapeProtocols</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.ScrapeProtocol"> +[]ScrapeProtocol +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The protocols to negotiate during a scrape. It tells clients the +protocols supported by Prometheus in order of preference (from most to least preferred).</p> +<p>If unset, Prometheus uses its default value.</p> +<p>It requires Prometheus >= v2.49.0.</p> +</td> +</tr> +<tr> +<td> <code>externalLabels</code><br/> <em> map[string]string @@ -6129,6 +6146,23 @@ Duration </tr> <tr> <td> +<code>scrapeProtocols</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.ScrapeProtocol"> +[]ScrapeProtocol +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The protocols to negotiate during a scrape. It tells clients the +protocols supported by Prometheus in order of preference (from most to least preferred).</p> +<p>If unset, Prometheus uses its default value.</p> +<p>It requires Prometheus >= v2.49.0.</p> +</td> +</tr> +<tr> +<td> <code>externalLabels</code><br/> <em> map[string]string @@ -10279,6 +10313,23 @@ Duration </tr> <tr> <td> +<code>scrapeProtocols</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.ScrapeProtocol"> +[]ScrapeProtocol +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The protocols to negotiate during a scrape. It tells clients the +protocols supported by Prometheus in order of preference (from most to least preferred).</p> +<p>If unset, Prometheus uses its default value.</p> +<p>It requires Prometheus >= v2.49.0.</p> +</td> +</tr> +<tr> +<td> <code>externalLabels</code><br/> <em> map[string]string @@ -13011,6 +13062,19 @@ bool </tr> </tbody> </table> +<h3 id="monitoring.coreos.com/v1.ScrapeProtocol">ScrapeProtocol +(<code>string</code> alias)</h3> +<p> +(<em>Appears on:</em><a href="#monitoring.coreos.com/v1.CommonPrometheusFields">CommonPrometheusFields</a>, <a href="#monitoring.coreos.com/v1alpha1.ScrapeConfigSpec">ScrapeConfigSpec</a>) +</p> +<div> +<p>ScrapeProtocol represents a protocol used by Prometheus for scraping metrics. +Supported values are: +* <code>OpenMetricsText0.0.1</code> +* <code>OpenMetricsText1.0.0</code> +* <code>PrometheusProto</code> +* <code>PrometheusText0.0.4</code></p> +</div> <h3 id="monitoring.coreos.com/v1.SecretOrConfigMap">SecretOrConfigMap </h3> <p> @@ -15873,6 +15937,23 @@ Duration </tr> <tr> <td> +<code>scrapeProtocols</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.ScrapeProtocol"> +[]ScrapeProtocol +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The protocols to negotiate during a scrape. It tells clients the +protocols supported by Prometheus in order of preference (from most to least preferred).</p> +<p>If unset, Prometheus uses its default value.</p> +<p>It requires Prometheus >= v2.49.0.</p> +</td> +</tr> +<tr> +<td> <code>externalLabels</code><br/> <em> map[string]string @@ -17023,6 +17104,23 @@ Duration </tr> <tr> <td> +<code>scrapeProtocols</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.ScrapeProtocol"> +[]ScrapeProtocol +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The protocols to negotiate during a scrape. It tells clients the +protocols supported by Prometheus in order of preference (from most to least preferred).</p> +<p>If unset, Prometheus uses its default value.</p> +<p>It requires Prometheus >= v2.49.0.</p> +</td> +</tr> +<tr> +<td> <code>honorTimestamps</code><br/> <em> bool @@ -20652,6 +20750,23 @@ Duration </tr> <tr> <td> +<code>scrapeProtocols</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.ScrapeProtocol"> +[]ScrapeProtocol +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The protocols to negotiate during a scrape. It tells clients the +protocols supported by Prometheus in order of preference (from most to least preferred).</p> +<p>If unset, Prometheus uses its default value.</p> +<p>It requires Prometheus >= v2.49.0.</p> +</td> +</tr> +<tr> +<td> <code>externalLabels</code><br/> <em> map[string]string @@ -22571,6 +22686,23 @@ Duration </tr> <tr> <td> +<code>scrapeProtocols</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.ScrapeProtocol"> +[]ScrapeProtocol +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>The protocols to negotiate during a scrape. It tells clients the +protocols supported by Prometheus in order of preference (from most to least preferred).</p> +<p>If unset, Prometheus uses its default value.</p> +<p>It requires Prometheus >= v2.49.0.</p> +</td> +</tr> +<tr> +<td> <code>honorTimestamps</code><br/> <em> bool diff --git a/bundle.yaml b/bundle.yaml index 6191ffb6b..59a869bac 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -19790,6 +19790,23 @@ spec: description: "Interval between consecutive scrapes. \n Default: \"30s\"" 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 + scrapeProtocols: + description: "The protocols to negotiate during a scrape. It tells + clients the protocols supported by Prometheus in order of preference + (from most to least preferred). \n If unset, Prometheus uses its + default value. \n It requires Prometheus >= v2.49.0." + items: + description: 'ScrapeProtocol represents a protocol used by Prometheus + for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` + * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`' + enum: + - PrometheusProto + - OpenMetricsText0.0.1 + - OpenMetricsText1.0.0 + - PrometheusText0.0.4 + type: string + type: array + x-kubernetes-list-type: set scrapeTimeout: description: Number of seconds to wait until a scrape request times out. @@ -29317,6 +29334,23 @@ spec: description: "Interval between consecutive scrapes. \n Default: \"30s\"" 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 + scrapeProtocols: + description: "The protocols to negotiate during a scrape. It tells + clients the protocols supported by Prometheus in order of preference + (from most to least preferred). \n If unset, Prometheus uses its + default value. \n It requires Prometheus >= v2.49.0." + items: + description: 'ScrapeProtocol represents a protocol used by Prometheus + for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` + * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`' + enum: + - PrometheusProto + - OpenMetricsText0.0.1 + - OpenMetricsText1.0.0 + - PrometheusText0.0.4 + type: string + type: array + x-kubernetes-list-type: set scrapeTimeout: description: Number of seconds to wait until a scrape request times out. @@ -35535,6 +35569,23 @@ spec: description: ScrapeInterval is the interval between consecutive scrapes. 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 + scrapeProtocols: + description: "The protocols to negotiate during a scrape. It tells + clients the protocols supported by Prometheus in order of preference + (from most to least preferred). \n If unset, Prometheus uses its + default value. \n It requires Prometheus >= v2.49.0." + items: + description: 'ScrapeProtocol represents a protocol used by Prometheus + for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` + * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`' + enum: + - PrometheusProto + - OpenMetricsText0.0.1 + - OpenMetricsText1.0.0 + - PrometheusText0.0.4 + type: string + type: array + x-kubernetes-list-type: set scrapeTimeout: description: ScrapeTimeout is the number of seconds to wait until a scrape request times out. 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 911f8be53..496a561ff 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml @@ -5182,6 +5182,23 @@ spec: description: "Interval between consecutive scrapes. \n Default: \"30s\"" 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 + scrapeProtocols: + description: "The protocols to negotiate during a scrape. It tells + clients the protocols supported by Prometheus in order of preference + (from most to least preferred). \n If unset, Prometheus uses its + default value. \n It requires Prometheus >= v2.49.0." + items: + description: 'ScrapeProtocol represents a protocol used by Prometheus + for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` + * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`' + enum: + - PrometheusProto + - OpenMetricsText0.0.1 + - OpenMetricsText1.0.0 + - PrometheusText0.0.4 + type: string + type: array + x-kubernetes-list-type: set scrapeTimeout: description: Number of seconds to wait until a scrape request times out. 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 924771054..747dd7d5e 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml @@ -6162,6 +6162,23 @@ spec: description: "Interval between consecutive scrapes. \n Default: \"30s\"" 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 + scrapeProtocols: + description: "The protocols to negotiate during a scrape. It tells + clients the protocols supported by Prometheus in order of preference + (from most to least preferred). \n If unset, Prometheus uses its + default value. \n It requires Prometheus >= v2.49.0." + items: + description: 'ScrapeProtocol represents a protocol used by Prometheus + for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` + * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`' + enum: + - PrometheusProto + - OpenMetricsText0.0.1 + - OpenMetricsText1.0.0 + - PrometheusText0.0.4 + type: string + type: array + x-kubernetes-list-type: set scrapeTimeout: description: Number of seconds to wait until a scrape request times out. diff --git a/example/prometheus-operator-crd-full/monitoring.coreos.com_scrapeconfigs.yaml b/example/prometheus-operator-crd-full/monitoring.coreos.com_scrapeconfigs.yaml index 209dc8552..ebc06576f 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_scrapeconfigs.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_scrapeconfigs.yaml @@ -2299,6 +2299,23 @@ spec: description: ScrapeInterval is the interval between consecutive scrapes. 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 + scrapeProtocols: + description: "The protocols to negotiate during a scrape. It tells + clients the protocols supported by Prometheus in order of preference + (from most to least preferred). \n If unset, Prometheus uses its + default value. \n It requires Prometheus >= v2.49.0." + items: + description: 'ScrapeProtocol represents a protocol used by Prometheus + for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` + * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`' + enum: + - PrometheusProto + - OpenMetricsText0.0.1 + - OpenMetricsText1.0.0 + - PrometheusText0.0.4 + type: string + type: array + x-kubernetes-list-type: set scrapeTimeout: description: ScrapeTimeout is the number of seconds to wait until a scrape request times out. diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml index d5c6224b7..7827a06f7 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml @@ -5183,6 +5183,23 @@ spec: description: "Interval between consecutive scrapes. \n Default: \"30s\"" 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 + scrapeProtocols: + description: "The protocols to negotiate during a scrape. It tells + clients the protocols supported by Prometheus in order of preference + (from most to least preferred). \n If unset, Prometheus uses its + default value. \n It requires Prometheus >= v2.49.0." + items: + description: 'ScrapeProtocol represents a protocol used by Prometheus + for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` + * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`' + enum: + - PrometheusProto + - OpenMetricsText0.0.1 + - OpenMetricsText1.0.0 + - PrometheusText0.0.4 + type: string + type: array + x-kubernetes-list-type: set scrapeTimeout: description: Number of seconds to wait until a scrape request times out. diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml index 8ba36ad7a..27eeb9416 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml @@ -6163,6 +6163,23 @@ spec: description: "Interval between consecutive scrapes. \n Default: \"30s\"" 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 + scrapeProtocols: + description: "The protocols to negotiate during a scrape. It tells + clients the protocols supported by Prometheus in order of preference + (from most to least preferred). \n If unset, Prometheus uses its + default value. \n It requires Prometheus >= v2.49.0." + items: + description: 'ScrapeProtocol represents a protocol used by Prometheus + for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` + * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`' + enum: + - PrometheusProto + - OpenMetricsText0.0.1 + - OpenMetricsText1.0.0 + - PrometheusText0.0.4 + type: string + type: array + x-kubernetes-list-type: set scrapeTimeout: description: Number of seconds to wait until a scrape request times out. diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_scrapeconfigs.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_scrapeconfigs.yaml index 9f3caf599..9cb96ef24 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_scrapeconfigs.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_scrapeconfigs.yaml @@ -2300,6 +2300,23 @@ spec: description: ScrapeInterval is the interval between consecutive scrapes. 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 + scrapeProtocols: + description: "The protocols to negotiate during a scrape. It tells + clients the protocols supported by Prometheus in order of preference + (from most to least preferred). \n If unset, Prometheus uses its + default value. \n It requires Prometheus >= v2.49.0." + items: + description: 'ScrapeProtocol represents a protocol used by Prometheus + for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` + * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`' + enum: + - PrometheusProto + - OpenMetricsText0.0.1 + - OpenMetricsText1.0.0 + - PrometheusText0.0.4 + type: string + type: array + x-kubernetes-list-type: set scrapeTimeout: description: ScrapeTimeout is the number of seconds to wait until a scrape request times out. diff --git a/jsonnet/prometheus-operator/prometheusagents-crd.json b/jsonnet/prometheus-operator/prometheusagents-crd.json index 6a478f04a..827b1a2a0 100644 --- a/jsonnet/prometheus-operator/prometheusagents-crd.json +++ b/jsonnet/prometheus-operator/prometheusagents-crd.json @@ -4722,6 +4722,21 @@ "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" }, + "scrapeProtocols": { + "description": "The protocols to negotiate during a scrape. It tells clients the protocols supported by Prometheus in order of preference (from most to least preferred). \n If unset, Prometheus uses its default value. \n It requires Prometheus >= v2.49.0.", + "items": { + "description": "ScrapeProtocol represents a protocol used by Prometheus for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`", + "enum": [ + "PrometheusProto", + "OpenMetricsText0.0.1", + "OpenMetricsText1.0.0", + "PrometheusText0.0.4" + ], + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "set" + }, "scrapeTimeout": { "description": "Number of seconds to wait until a scrape request times out.", "pattern": "^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$", diff --git a/jsonnet/prometheus-operator/prometheuses-crd.json b/jsonnet/prometheus-operator/prometheuses-crd.json index c8b350a32..0cb08af80 100644 --- a/jsonnet/prometheus-operator/prometheuses-crd.json +++ b/jsonnet/prometheus-operator/prometheuses-crd.json @@ -5732,6 +5732,21 @@ "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" }, + "scrapeProtocols": { + "description": "The protocols to negotiate during a scrape. It tells clients the protocols supported by Prometheus in order of preference (from most to least preferred). \n If unset, Prometheus uses its default value. \n It requires Prometheus >= v2.49.0.", + "items": { + "description": "ScrapeProtocol represents a protocol used by Prometheus for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`", + "enum": [ + "PrometheusProto", + "OpenMetricsText0.0.1", + "OpenMetricsText1.0.0", + "PrometheusText0.0.4" + ], + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "set" + }, "scrapeTimeout": { "description": "Number of seconds to wait until a scrape request times out.", "pattern": "^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$", diff --git a/jsonnet/prometheus-operator/scrapeconfigs-crd.json b/jsonnet/prometheus-operator/scrapeconfigs-crd.json index 83f84d20b..ea76d84e3 100644 --- a/jsonnet/prometheus-operator/scrapeconfigs-crd.json +++ b/jsonnet/prometheus-operator/scrapeconfigs-crd.json @@ -2470,6 +2470,21 @@ "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" }, + "scrapeProtocols": { + "description": "The protocols to negotiate during a scrape. It tells clients the protocols supported by Prometheus in order of preference (from most to least preferred). \n If unset, Prometheus uses its default value. \n It requires Prometheus >= v2.49.0.", + "items": { + "description": "ScrapeProtocol represents a protocol used by Prometheus for scraping metrics. Supported values are: * `OpenMetricsText0.0.1` * `OpenMetricsText1.0.0` * `PrometheusProto` * `PrometheusText0.0.4`", + "enum": [ + "PrometheusProto", + "OpenMetricsText0.0.1", + "OpenMetricsText1.0.0", + "PrometheusText0.0.4" + ], + "type": "string" + }, + "type": "array", + "x-kubernetes-list-type": "set" + }, "scrapeTimeout": { "description": "ScrapeTimeout is the number of seconds to wait until a scrape request times out.", "pattern": "^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$", diff --git a/pkg/apis/monitoring/v1/prometheus_types.go b/pkg/apis/monitoring/v1/prometheus_types.go index 4b66d0e19..f07bf5267 100644 --- a/pkg/apis/monitoring/v1/prometheus_types.go +++ b/pkg/apis/monitoring/v1/prometheus_types.go @@ -32,6 +32,15 @@ const ( PrometheusKindKey = "prometheus" ) +// ScrapeProtocol represents a protocol used by Prometheus for scraping metrics. +// Supported values are: +// * `OpenMetricsText0.0.1` +// * `OpenMetricsText1.0.0` +// * `PrometheusProto` +// * `PrometheusText0.0.4` +// +kubebuilder:validation:Enum=PrometheusProto;OpenMetricsText0.0.1;OpenMetricsText1.0.0;PrometheusText0.0.4 +type ScrapeProtocol string + // PrometheusInterface is used by Prometheus and PrometheusAgent to share common methods, e.g. config generation. // +k8s:deepcopy-gen=false type PrometheusInterface interface { @@ -252,6 +261,17 @@ type CommonPrometheusFields struct { // Number of seconds to wait until a scrape request times out. ScrapeTimeout Duration `json:"scrapeTimeout,omitempty"` + // The protocols to negotiate during a scrape. It tells clients the + // protocols supported by Prometheus in order of preference (from most to least preferred). + // + // If unset, Prometheus uses its default value. + // + // It requires Prometheus >= v2.49.0. + // + // +listType=set + // +optional + ScrapeProtocols []ScrapeProtocol `json:"scrapeProtocols,omitempty"` + // The labels to add to any time series or alerts when communicating with // external systems (federation, remote storage, Alertmanager). // Labels defined by `spec.replicaExternalLabelName` and diff --git a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go index 77f57a525..fa7fd3c17 100644 --- a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go @@ -681,6 +681,11 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) { *out = new(string) **out = **in } + if in.ScrapeProtocols != nil { + in, out := &in.ScrapeProtocols, &out.ScrapeProtocols + *out = make([]ScrapeProtocol, len(*in)) + copy(*out, *in) + } if in.ExternalLabels != nil { in, out := &in.ExternalLabels, &out.ExternalLabels *out = make(map[string]string, len(*in)) diff --git a/pkg/apis/monitoring/v1alpha1/scrapeconfig_types.go b/pkg/apis/monitoring/v1alpha1/scrapeconfig_types.go index 771dffb90..c0006a3a3 100644 --- a/pkg/apis/monitoring/v1alpha1/scrapeconfig_types.go +++ b/pkg/apis/monitoring/v1alpha1/scrapeconfig_types.go @@ -160,6 +160,16 @@ type ScrapeConfigSpec struct { // ScrapeTimeout is the number of seconds to wait until a scrape request times out. // +optional ScrapeTimeout *v1.Duration `json:"scrapeTimeout,omitempty"` + // The protocols to negotiate during a scrape. It tells clients the + // protocols supported by Prometheus in order of preference (from most to least preferred). + // + // If unset, Prometheus uses its default value. + // + // It requires Prometheus >= v2.49.0. + // + // +listType=set + // +optional + ScrapeProtocols []v1.ScrapeProtocol `json:"scrapeProtocols,omitempty"` // HonorTimestamps controls whether Prometheus respects the timestamps present in scraped data. // +optional HonorTimestamps *bool `json:"honorTimestamps,omitempty"` diff --git a/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go index 59e3d290c..409bb4301 100644 --- a/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go @@ -1660,6 +1660,11 @@ func (in *ScrapeConfigSpec) DeepCopyInto(out *ScrapeConfigSpec) { *out = new(monitoringv1.Duration) **out = **in } + if in.ScrapeProtocols != nil { + in, out := &in.ScrapeProtocols, &out.ScrapeProtocols + *out = make([]monitoringv1.ScrapeProtocol, len(*in)) + copy(*out, *in) + } if in.HonorTimestamps != nil { in, out := &in.HonorTimestamps, &out.HonorTimestamps *out = new(bool) diff --git a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go index 00d8eff21..d68e32ce8 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go +++ b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go @@ -48,6 +48,7 @@ type CommonPrometheusFieldsApplyConfiguration struct { LogFormat *string `json:"logFormat,omitempty"` ScrapeInterval *monitoringv1.Duration `json:"scrapeInterval,omitempty"` ScrapeTimeout *monitoringv1.Duration `json:"scrapeTimeout,omitempty"` + ScrapeProtocols []monitoringv1.ScrapeProtocol `json:"scrapeProtocols,omitempty"` ExternalLabels map[string]string `json:"externalLabels,omitempty"` EnableRemoteWriteReceiver *bool `json:"enableRemoteWriteReceiver,omitempty"` EnableFeatures []string `json:"enableFeatures,omitempty"` @@ -290,6 +291,16 @@ func (b *CommonPrometheusFieldsApplyConfiguration) WithScrapeTimeout(value monit return b } +// WithScrapeProtocols adds the given value to the ScrapeProtocols field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the ScrapeProtocols field. +func (b *CommonPrometheusFieldsApplyConfiguration) WithScrapeProtocols(values ...monitoringv1.ScrapeProtocol) *CommonPrometheusFieldsApplyConfiguration { + for i := range values { + b.ScrapeProtocols = append(b.ScrapeProtocols, values[i]) + } + return b +} + // WithExternalLabels puts the entries into the ExternalLabels field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, the entries provided by each call will be put on the ExternalLabels field, diff --git a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go index 437226f89..39a2ed75f 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go @@ -235,6 +235,16 @@ func (b *PrometheusSpecApplyConfiguration) WithScrapeTimeout(value monitoringv1. return b } +// WithScrapeProtocols adds the given value to the ScrapeProtocols field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the ScrapeProtocols field. +func (b *PrometheusSpecApplyConfiguration) WithScrapeProtocols(values ...monitoringv1.ScrapeProtocol) *PrometheusSpecApplyConfiguration { + for i := range values { + b.ScrapeProtocols = append(b.ScrapeProtocols, values[i]) + } + return b +} + // WithExternalLabels puts the entries into the ExternalLabels field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, the entries provided by each call will be put on the ExternalLabels field, diff --git a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go index d5ec780ab..7a0197b2f 100644 --- a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go @@ -214,6 +214,16 @@ func (b *PrometheusAgentSpecApplyConfiguration) WithScrapeTimeout(value monitori return b } +// WithScrapeProtocols adds the given value to the ScrapeProtocols field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the ScrapeProtocols field. +func (b *PrometheusAgentSpecApplyConfiguration) WithScrapeProtocols(values ...monitoringv1.ScrapeProtocol) *PrometheusAgentSpecApplyConfiguration { + for i := range values { + b.ScrapeProtocols = append(b.ScrapeProtocols, values[i]) + } + return b +} + // WithExternalLabels puts the entries into the ExternalLabels field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, the entries provided by each call will be put on the ExternalLabels field, diff --git a/pkg/client/applyconfiguration/monitoring/v1alpha1/scrapeconfigspec.go b/pkg/client/applyconfiguration/monitoring/v1alpha1/scrapeconfigspec.go index 7f4fa2e9c..4ed875993 100644 --- a/pkg/client/applyconfiguration/monitoring/v1alpha1/scrapeconfigspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1alpha1/scrapeconfigspec.go @@ -39,6 +39,7 @@ type ScrapeConfigSpecApplyConfiguration struct { MetricsPath *string `json:"metricsPath,omitempty"` ScrapeInterval *v1.Duration `json:"scrapeInterval,omitempty"` ScrapeTimeout *v1.Duration `json:"scrapeTimeout,omitempty"` + ScrapeProtocols []v1.ScrapeProtocol `json:"scrapeProtocols,omitempty"` HonorTimestamps *bool `json:"honorTimestamps,omitempty"` TrackTimestampsStaleness *bool `json:"trackTimestampsStaleness,omitempty"` HonorLabels *bool `json:"honorLabels,omitempty"` @@ -244,6 +245,16 @@ func (b *ScrapeConfigSpecApplyConfiguration) WithScrapeTimeout(value v1.Duration return b } +// WithScrapeProtocols adds the given value to the ScrapeProtocols field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the ScrapeProtocols field. +func (b *ScrapeConfigSpecApplyConfiguration) WithScrapeProtocols(values ...v1.ScrapeProtocol) *ScrapeConfigSpecApplyConfiguration { + for i := range values { + b.ScrapeProtocols = append(b.ScrapeProtocols, values[i]) + } + return b +} + // WithHonorTimestamps sets the HonorTimestamps 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 HonorTimestamps field is set to the value of the last call. diff --git a/pkg/prometheus/promcfg.go b/pkg/prometheus/promcfg.go index 927433e40..1d4d3f0d8 100644 --- a/pkg/prometheus/promcfg.go +++ b/pkg/prometheus/promcfg.go @@ -563,6 +563,7 @@ func (cg *ConfigGenerator) GenerateServerConfiguration( globalItems := yaml.MapSlice{} globalItems = cg.appendEvaluationInterval(globalItems, evaluationInterval) globalItems = cg.appendScrapeIntervals(globalItems) + globalItems = cg.appendScrapeProtocols(globalItems) globalItems = cg.appendExternalLabels(globalItems) globalItems = cg.appendQueryLogFile(globalItems, queryLogFile) globalItems = cg.appendScrapeLimits(globalItems) @@ -2064,6 +2065,16 @@ func (cg *ConfigGenerator) appendScrapeIntervals(slice yaml.MapSlice) yaml.MapSl return slice } +func (cg *ConfigGenerator) appendScrapeProtocols(slice yaml.MapSlice) yaml.MapSlice { + cpf := cg.prom.GetCommonPrometheusFields() + + if len(cpf.ScrapeProtocols) == 0 { + return slice + } + + return cg.WithMinimumVersion("2.49.0").AppendMapItem(slice, "scrape_protocols", cpf.ScrapeProtocols) +} + func (cg *ConfigGenerator) appendEvaluationInterval(slice yaml.MapSlice, evaluationInterval monitoringv1.Duration) yaml.MapSlice { return append(slice, yaml.MapItem{Key: "evaluation_interval", Value: evaluationInterval}) } @@ -2254,6 +2265,7 @@ func (cg *ConfigGenerator) GenerateAgentConfiguration( cfg := yaml.MapSlice{} globalItems := yaml.MapSlice{} globalItems = cg.appendScrapeIntervals(globalItems) + globalItems = cg.appendScrapeProtocols(globalItems) globalItems = cg.appendExternalLabels(globalItems) globalItems = cg.appendScrapeLimits(globalItems) cfg = append(cfg, yaml.MapItem{Key: "global", Value: globalItems}) @@ -2379,6 +2391,10 @@ func (cg *ConfigGenerator) generateScrapeConfig( cfg = append(cfg, yaml.MapItem{Key: "scrape_timeout", Value: *sc.Spec.ScrapeTimeout}) } + if len(sc.Spec.ScrapeProtocols) > 0 { + cfg = cg.WithMinimumVersion("2.49.0").AppendMapItem(cfg, "scrape_protocols", sc.Spec.ScrapeProtocols) + } + if sc.Spec.Scheme != nil { cfg = append(cfg, yaml.MapItem{Key: "scheme", Value: strings.ToLower(*sc.Spec.Scheme)}) } diff --git a/pkg/prometheus/promcfg_test.go b/pkg/prometheus/promcfg_test.go index 395d3f82c..d97d8768b 100644 --- a/pkg/prometheus/promcfg_test.go +++ b/pkg/prometheus/promcfg_test.go @@ -99,13 +99,18 @@ func TestConfigGeneration(t *testing.T) { func TestGlobalSettings(t *testing.T) { var ( - expectedBodySizeLimit monitoringv1.ByteSize = "1000MB" - expectedSampleLimit uint64 = 10000 - expectedTargetLimit uint64 = 1000 - expectedLabelLimit uint64 = 50 - expectedLabelNameLengthLimit uint64 = 40 - expectedLabelValueLengthLimit uint64 = 30 - expectedkeepDroppedTargets uint64 = 50 + expectedBodySizeLimit monitoringv1.ByteSize = "1000MB" + expectedSampleLimit uint64 = 10000 + expectedTargetLimit uint64 = 1000 + expectedLabelLimit uint64 = 50 + expectedLabelNameLengthLimit uint64 = 40 + expectedLabelValueLengthLimit uint64 = 30 + expectedkeepDroppedTargets uint64 = 50 + expectedscrapeProtocols []monitoringv1.ScrapeProtocol = []monitoringv1.ScrapeProtocol{ + "OpenMetricsText1.0.0", + "OpenMetricsText0.0.1", + "PrometheusText0.0.4", + } ) for _, tc := range []struct { @@ -113,6 +118,7 @@ func TestGlobalSettings(t *testing.T) { EvaluationInterval monitoringv1.Duration ScrapeInterval monitoringv1.Duration ScrapeTimeout monitoringv1.Duration + ScrapeProtocols []monitoringv1.ScrapeProtocol ExternalLabels map[string]string PrometheusExternalLabelName *string ReplicaExternalLabelName *string @@ -215,6 +221,14 @@ func TestGlobalSettings(t *testing.T) { KeepDroppedTargets: &expectedkeepDroppedTargets, Golden: "valid_global_config_with_keep_dropped_targets.golden", }, + { + Scenario: "valid global config with scrape protocols", + Version: "v2.49.0", + ScrapeInterval: "30s", + EvaluationInterval: "30s", + ScrapeProtocols: expectedscrapeProtocols, + Golden: "valid_global_config_with_scrape_protocols.golden", + }, } { p := &monitoringv1.Prometheus{ @@ -223,6 +237,7 @@ func TestGlobalSettings(t *testing.T) { CommonPrometheusFields: monitoringv1.CommonPrometheusFields{ ScrapeInterval: tc.ScrapeInterval, ScrapeTimeout: tc.ScrapeTimeout, + ScrapeProtocols: tc.ScrapeProtocols, ExternalLabels: tc.ExternalLabels, PrometheusExternalLabelName: tc.PrometheusExternalLabelName, ReplicaExternalLabelName: tc.ReplicaExternalLabelName, @@ -5256,6 +5271,18 @@ func TestScrapeConfigSpecConfig(t *testing.T) { }, golden: "ScrapeConfigSpecConfig_ScrapeTimeout.golden", }, + { + name: "scrape_protocols", + scSpec: monitoringv1alpha1.ScrapeConfigSpec{ + ScrapeProtocols: []monitoringv1.ScrapeProtocol{ + monitoringv1.ScrapeProtocol("PrometheusProto"), + monitoringv1.ScrapeProtocol("OpenMetricsText1.0.0"), + monitoringv1.ScrapeProtocol("OpenMetricsText0.0.1"), + monitoringv1.ScrapeProtocol("PrometheusText0.0.4"), + }, + }, + golden: "ScrapeConfigSpecConfig_ScrapeProtocols.golden", + }, { name: "non_empty_metric_relabel_config", scSpec: monitoringv1alpha1.ScrapeConfigSpec{ diff --git a/pkg/prometheus/testdata/ScrapeConfigSpecConfig_ScrapeProtocols.golden b/pkg/prometheus/testdata/ScrapeConfigSpecConfig_ScrapeProtocols.golden new file mode 100644 index 000000000..4fd978d8e --- /dev/null +++ b/pkg/prometheus/testdata/ScrapeConfigSpecConfig_ScrapeProtocols.golden @@ -0,0 +1,17 @@ +global: + evaluation_interval: 30s + scrape_interval: 30s + external_labels: + prometheus: default/test + prometheus_replica: $(POD_NAME) +scrape_configs: +- job_name: scrapeConfig/default/testscrapeconfig1 + scrape_protocols: + - PrometheusProto + - OpenMetricsText1.0.0 + - OpenMetricsText0.0.1 + - PrometheusText0.0.4 + relabel_configs: + - source_labels: + - job + target_label: __tmp_prometheus_job_name diff --git a/pkg/prometheus/testdata/valid_global_config_with_scrape_protocols.golden b/pkg/prometheus/testdata/valid_global_config_with_scrape_protocols.golden new file mode 100644 index 000000000..9296d92cc --- /dev/null +++ b/pkg/prometheus/testdata/valid_global_config_with_scrape_protocols.golden @@ -0,0 +1,11 @@ +global: + evaluation_interval: 30s + scrape_interval: 30s + scrape_protocols: + - OpenMetricsText1.0.0 + - OpenMetricsText0.0.1 + - PrometheusText0.0.4 + external_labels: + prometheus: / + prometheus_replica: $(POD_NAME) +scrape_configs: []