1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-06 17:14:13 +00:00

Merge pull request #7033 from simonpasquier/prom-rw-2

feat: add support for Remote Write v2.0
This commit is contained in:
Simon Pasquier 2024-10-23 14:23:33 +02:00 committed by GitHub
commit ca4f84f2bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 771 additions and 24 deletions

View file

@ -3,6 +3,7 @@
* [CHANGE] Allow overlapping compactions by default in Prometheus when the Thanos sidecar is configured with uploads. #6906
* [FEATURE] Add `dnsConfig` and `dnsPolicy` fields to `Alertmanager`, `Prometheus`, `PrometheusAgent` and `ThanosRuler` CRDs. #3889
* [FEATURE] Add `ruleQueryOffset` field to `Prometheus` CRD and `query_offset` field to `PrometheusRule` CRD. #6957
* [FEATURE] Add support for Remote Write v2.0 to `Prometheus` and `PrometheusAgent` CRDs. #7033
* [ENHANCEMENT] Add `goGC` field to `Prometheus` and `PrometheusAgent` CRDs. #6667
* [BUGFIX] Fix label name validation in `ScrapeConfig` CRD. #6892

124
Documentation/api.md generated
View file

@ -1991,6 +1991,22 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q
</tr>
<tr>
<td>
<code>remoteWriteReceiverMessageVersions</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion">
[]RemoteWriteMessageVersion
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>List of the protobuf message versions to accept when receiving the
remote writes.</p>
<p>It requires Prometheus &gt;= v2.54.0.</p>
</td>
</tr>
<tr>
<td>
<code>enableFeatures</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.EnableFeature">
@ -6896,6 +6912,22 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q
</tr>
<tr>
<td>
<code>remoteWriteReceiverMessageVersions</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion">
[]RemoteWriteMessageVersion
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>List of the protobuf message versions to accept when receiving the
remote writes.</p>
<p>It requires Prometheus &gt;= v2.54.0.</p>
</td>
</tr>
<tr>
<td>
<code>enableFeatures</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.EnableFeature">
@ -11567,6 +11599,22 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q
</tr>
<tr>
<td>
<code>remoteWriteReceiverMessageVersions</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion">
[]RemoteWriteMessageVersion
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>List of the protobuf message versions to accept when receiving the
remote writes.</p>
<p>It requires Prometheus &gt;= v2.54.0.</p>
</td>
</tr>
<tr>
<td>
<code>enableFeatures</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.EnableFeature">
@ -13901,6 +13949,28 @@ bool
</tr>
</tbody>
</table>
<h3 id="monitoring.coreos.com/v1.RemoteWriteMessageVersion">RemoteWriteMessageVersion
(<code>string</code> alias)</h3>
<p>
(<em>Appears on:</em><a href="#monitoring.coreos.com/v1.CommonPrometheusFields">CommonPrometheusFields</a>, <a href="#monitoring.coreos.com/v1.RemoteWriteSpec">RemoteWriteSpec</a>)
</p>
<div>
</div>
<table>
<thead>
<tr>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr><td><p>&#34;V1.0&#34;</p></td>
<td><p>Remote Write message&rsquo;s version 1.0.</p>
</td>
</tr><tr><td><p>&#34;V2.0&#34;</p></td>
<td><p>Remote Write message&rsquo;s version 2.0.</p>
</td>
</tr></tbody>
</table>
<h3 id="monitoring.coreos.com/v1.RemoteWriteSpec">RemoteWriteSpec
</h3>
<p>
@ -13937,6 +14007,7 @@ string
</em>
</td>
<td>
<em>(Optional)</em>
<p>The name of the remote write queue, it must be unique if specified. The
name is used in metrics and logging in order to differentiate queues.</p>
<p>It requires Prometheus &gt;= v2.15.0.</p>
@ -13944,6 +14015,27 @@ name is used in metrics and logging in order to differentiate queues.</p>
</tr>
<tr>
<td>
<code>messageVersion</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion">
RemoteWriteMessageVersion
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The Remote Write message&rsquo;s version to use when writing to the endpoint.</p>
<p><code>Version1.0</code> corresponds to the <code>prometheus.WriteRequest</code> protobuf message introduced in Remote Write 1.0.
<code>Version2.0</code> corresponds to the <code>io.prometheus.write.v2.Request</code> protobuf message introduced in Remote Write 2.0.</p>
<p>When <code>Version2.0</code> is selected, Prometheus will automatically be
configured to append the metadata of scraped metrics to the WAL.</p>
<p>Before setting this field, consult with your remote storage provider
what message version it supports.</p>
<p>It requires Prometheus &gt;= v2.54.0.</p>
</td>
</tr>
<tr>
<td>
<code>sendExemplars</code><br/>
<em>
bool
@ -18039,6 +18131,22 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q
</tr>
<tr>
<td>
<code>remoteWriteReceiverMessageVersions</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion">
[]RemoteWriteMessageVersion
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>List of the protobuf message versions to accept when receiving the
remote writes.</p>
<p>It requires Prometheus &gt;= v2.54.0.</p>
</td>
</tr>
<tr>
<td>
<code>enableFeatures</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.EnableFeature">
@ -25834,6 +25942,22 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q
</tr>
<tr>
<td>
<code>remoteWriteReceiverMessageVersions</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion">
[]RemoteWriteMessageVersion
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>List of the protobuf message versions to accept when receiving the
remote writes.</p>
<p>It requires Prometheus &gt;= v2.54.0.</p>
</td>
</tr>
<tr>
<td>
<code>enableFeatures</code><br/>
<em>
<a href="#monitoring.coreos.com/v1.EnableFeature">

66
bundle.yaml generated
View file

@ -26234,6 +26234,24 @@ spec:
It requires Prometheus >= v2.25.0.
type: object
messageVersion:
description: |-
The Remote Write message's version to use when writing to the endpoint.
`Version1.0` corresponds to the `prometheus.WriteRequest` protobuf message introduced in Remote Write 1.0.
`Version2.0` corresponds to the `io.prometheus.write.v2.Request` protobuf message introduced in Remote Write 2.0.
When `Version2.0` is selected, Prometheus will automatically be
configured to append the metadata of scraped metrics to the WAL.
Before setting this field, consult with your remote storage provider
what message version it supports.
It requires Prometheus >= v2.54.0.
enum:
- V1.0
- V2.0
type: string
metadataConfig:
description: MetadataConfig configures the sending of series
metadata to the remote storage.
@ -26957,6 +26975,7 @@ spec:
type: object
url:
description: The URL of the endpoint to send samples to.
minLength: 1
type: string
writeRelabelConfigs:
description: The list of remote write relabel configurations.
@ -27049,6 +27068,20 @@ spec:
- url
type: object
type: array
remoteWriteReceiverMessageVersions:
description: |-
List of the protobuf message versions to accept when receiving the
remote writes.
It requires Prometheus >= v2.54.0.
items:
enum:
- V1.0
- V2.0
type: string
minItems: 1
type: array
x-kubernetes-list-type: set
replicaExternalLabelName:
description: |-
Name of Prometheus external label used to denote the replica name.
@ -38309,6 +38342,24 @@ spec:
It requires Prometheus >= v2.25.0.
type: object
messageVersion:
description: |-
The Remote Write message's version to use when writing to the endpoint.
`Version1.0` corresponds to the `prometheus.WriteRequest` protobuf message introduced in Remote Write 1.0.
`Version2.0` corresponds to the `io.prometheus.write.v2.Request` protobuf message introduced in Remote Write 2.0.
When `Version2.0` is selected, Prometheus will automatically be
configured to append the metadata of scraped metrics to the WAL.
Before setting this field, consult with your remote storage provider
what message version it supports.
It requires Prometheus >= v2.54.0.
enum:
- V1.0
- V2.0
type: string
metadataConfig:
description: MetadataConfig configures the sending of series
metadata to the remote storage.
@ -39032,6 +39083,7 @@ spec:
type: object
url:
description: The URL of the endpoint to send samples to.
minLength: 1
type: string
writeRelabelConfigs:
description: The list of remote write relabel configurations.
@ -39124,6 +39176,20 @@ spec:
- url
type: object
type: array
remoteWriteReceiverMessageVersions:
description: |-
List of the protobuf message versions to accept when receiving the
remote writes.
It requires Prometheus >= v2.54.0.
items:
enum:
- V1.0
- V2.0
type: string
minItems: 1
type: array
x-kubernetes-list-type: set
replicaExternalLabelName:
description: |-
Name of Prometheus external label used to denote the replica name.

View file

@ -5303,6 +5303,24 @@ spec:
It requires Prometheus >= v2.25.0.
type: object
messageVersion:
description: |-
The Remote Write message's version to use when writing to the endpoint.
`Version1.0` corresponds to the `prometheus.WriteRequest` protobuf message introduced in Remote Write 1.0.
`Version2.0` corresponds to the `io.prometheus.write.v2.Request` protobuf message introduced in Remote Write 2.0.
When `Version2.0` is selected, Prometheus will automatically be
configured to append the metadata of scraped metrics to the WAL.
Before setting this field, consult with your remote storage provider
what message version it supports.
It requires Prometheus >= v2.54.0.
enum:
- V1.0
- V2.0
type: string
metadataConfig:
description: MetadataConfig configures the sending of series
metadata to the remote storage.
@ -6026,6 +6044,7 @@ spec:
type: object
url:
description: The URL of the endpoint to send samples to.
minLength: 1
type: string
writeRelabelConfigs:
description: The list of remote write relabel configurations.
@ -6118,6 +6137,20 @@ spec:
- url
type: object
type: array
remoteWriteReceiverMessageVersions:
description: |-
List of the protobuf message versions to accept when receiving the
remote writes.
It requires Prometheus >= v2.54.0.
items:
enum:
- V1.0
- V2.0
type: string
minItems: 1
type: array
x-kubernetes-list-type: set
replicaExternalLabelName:
description: |-
Name of Prometheus external label used to denote the replica name.

View file

@ -6806,6 +6806,24 @@ spec:
It requires Prometheus >= v2.25.0.
type: object
messageVersion:
description: |-
The Remote Write message's version to use when writing to the endpoint.
`Version1.0` corresponds to the `prometheus.WriteRequest` protobuf message introduced in Remote Write 1.0.
`Version2.0` corresponds to the `io.prometheus.write.v2.Request` protobuf message introduced in Remote Write 2.0.
When `Version2.0` is selected, Prometheus will automatically be
configured to append the metadata of scraped metrics to the WAL.
Before setting this field, consult with your remote storage provider
what message version it supports.
It requires Prometheus >= v2.54.0.
enum:
- V1.0
- V2.0
type: string
metadataConfig:
description: MetadataConfig configures the sending of series
metadata to the remote storage.
@ -7529,6 +7547,7 @@ spec:
type: object
url:
description: The URL of the endpoint to send samples to.
minLength: 1
type: string
writeRelabelConfigs:
description: The list of remote write relabel configurations.
@ -7621,6 +7640,20 @@ spec:
- url
type: object
type: array
remoteWriteReceiverMessageVersions:
description: |-
List of the protobuf message versions to accept when receiving the
remote writes.
It requires Prometheus >= v2.54.0.
items:
enum:
- V1.0
- V2.0
type: string
minItems: 1
type: array
x-kubernetes-list-type: set
replicaExternalLabelName:
description: |-
Name of Prometheus external label used to denote the replica name.

View file

@ -5304,6 +5304,24 @@ spec:
It requires Prometheus >= v2.25.0.
type: object
messageVersion:
description: |-
The Remote Write message's version to use when writing to the endpoint.
`Version1.0` corresponds to the `prometheus.WriteRequest` protobuf message introduced in Remote Write 1.0.
`Version2.0` corresponds to the `io.prometheus.write.v2.Request` protobuf message introduced in Remote Write 2.0.
When `Version2.0` is selected, Prometheus will automatically be
configured to append the metadata of scraped metrics to the WAL.
Before setting this field, consult with your remote storage provider
what message version it supports.
It requires Prometheus >= v2.54.0.
enum:
- V1.0
- V2.0
type: string
metadataConfig:
description: MetadataConfig configures the sending of series
metadata to the remote storage.
@ -6027,6 +6045,7 @@ spec:
type: object
url:
description: The URL of the endpoint to send samples to.
minLength: 1
type: string
writeRelabelConfigs:
description: The list of remote write relabel configurations.
@ -6119,6 +6138,20 @@ spec:
- url
type: object
type: array
remoteWriteReceiverMessageVersions:
description: |-
List of the protobuf message versions to accept when receiving the
remote writes.
It requires Prometheus >= v2.54.0.
items:
enum:
- V1.0
- V2.0
type: string
minItems: 1
type: array
x-kubernetes-list-type: set
replicaExternalLabelName:
description: |-
Name of Prometheus external label used to denote the replica name.

View file

@ -6807,6 +6807,24 @@ spec:
It requires Prometheus >= v2.25.0.
type: object
messageVersion:
description: |-
The Remote Write message's version to use when writing to the endpoint.
`Version1.0` corresponds to the `prometheus.WriteRequest` protobuf message introduced in Remote Write 1.0.
`Version2.0` corresponds to the `io.prometheus.write.v2.Request` protobuf message introduced in Remote Write 2.0.
When `Version2.0` is selected, Prometheus will automatically be
configured to append the metadata of scraped metrics to the WAL.
Before setting this field, consult with your remote storage provider
what message version it supports.
It requires Prometheus >= v2.54.0.
enum:
- V1.0
- V2.0
type: string
metadataConfig:
description: MetadataConfig configures the sending of series
metadata to the remote storage.
@ -7530,6 +7548,7 @@ spec:
type: object
url:
description: The URL of the endpoint to send samples to.
minLength: 1
type: string
writeRelabelConfigs:
description: The list of remote write relabel configurations.
@ -7622,6 +7641,20 @@ spec:
- url
type: object
type: array
remoteWriteReceiverMessageVersions:
description: |-
List of the protobuf message versions to accept when receiving the
remote writes.
It requires Prometheus >= v2.54.0.
items:
enum:
- V1.0
- V2.0
type: string
minItems: 1
type: array
x-kubernetes-list-type: set
replicaExternalLabelName:
description: |-
Name of Prometheus external label used to denote the replica name.

View file

@ -4501,6 +4501,14 @@
"description": "Custom HTTP headers to be sent along with each remote write request.\nBe aware that headers that are set by Prometheus itself can't be overwritten.\n\nIt requires Prometheus >= v2.25.0.",
"type": "object"
},
"messageVersion": {
"description": "The Remote Write message's version to use when writing to the endpoint.\n\n`Version1.0` corresponds to the `prometheus.WriteRequest` protobuf message introduced in Remote Write 1.0.\n`Version2.0` corresponds to the `io.prometheus.write.v2.Request` protobuf message introduced in Remote Write 2.0.\n\nWhen `Version2.0` is selected, Prometheus will automatically be\nconfigured to append the metadata of scraped metrics to the WAL.\n\nBefore setting this field, consult with your remote storage provider\nwhat message version it supports.\n\nIt requires Prometheus >= v2.54.0.",
"enum": [
"V1.0",
"V2.0"
],
"type": "string"
},
"metadataConfig": {
"description": "MetadataConfig configures the sending of series metadata to the remote storage.",
"properties": {
@ -5176,6 +5184,7 @@
},
"url": {
"description": "The URL of the endpoint to send samples to.",
"minLength": 1,
"type": "string"
},
"writeRelabelConfigs": {
@ -5255,6 +5264,19 @@
},
"type": "array"
},
"remoteWriteReceiverMessageVersions": {
"description": "List of the protobuf message versions to accept when receiving the\nremote writes.\n\nIt requires Prometheus >= v2.54.0.",
"items": {
"enum": [
"V1.0",
"V2.0"
],
"type": "string"
},
"minItems": 1,
"type": "array",
"x-kubernetes-list-type": "set"
},
"replicaExternalLabelName": {
"description": "Name of Prometheus external label used to denote the replica name.\nThe external label will _not_ be added when the field is set to the\nempty string (`\"\"`).\n\nDefault: \"prometheus_replica\"",
"type": "string"

View file

@ -5830,6 +5830,14 @@
"description": "Custom HTTP headers to be sent along with each remote write request.\nBe aware that headers that are set by Prometheus itself can't be overwritten.\n\nIt requires Prometheus >= v2.25.0.",
"type": "object"
},
"messageVersion": {
"description": "The Remote Write message's version to use when writing to the endpoint.\n\n`Version1.0` corresponds to the `prometheus.WriteRequest` protobuf message introduced in Remote Write 1.0.\n`Version2.0` corresponds to the `io.prometheus.write.v2.Request` protobuf message introduced in Remote Write 2.0.\n\nWhen `Version2.0` is selected, Prometheus will automatically be\nconfigured to append the metadata of scraped metrics to the WAL.\n\nBefore setting this field, consult with your remote storage provider\nwhat message version it supports.\n\nIt requires Prometheus >= v2.54.0.",
"enum": [
"V1.0",
"V2.0"
],
"type": "string"
},
"metadataConfig": {
"description": "MetadataConfig configures the sending of series metadata to the remote storage.",
"properties": {
@ -6505,6 +6513,7 @@
},
"url": {
"description": "The URL of the endpoint to send samples to.",
"minLength": 1,
"type": "string"
},
"writeRelabelConfigs": {
@ -6584,6 +6593,19 @@
},
"type": "array"
},
"remoteWriteReceiverMessageVersions": {
"description": "List of the protobuf message versions to accept when receiving the\nremote writes.\n\nIt requires Prometheus >= v2.54.0.",
"items": {
"enum": [
"V1.0",
"V2.0"
],
"type": "string"
},
"minItems": 1,
"type": "array",
"x-kubernetes-list-type": "set"
},
"replicaExternalLabelName": {
"description": "Name of Prometheus external label used to denote the replica name.\nThe external label will _not_ be added when the field is set to the\nempty string (`\"\"`).\n\nDefault: \"prometheus_replica\"",
"type": "string"

View file

@ -307,6 +307,16 @@ type CommonPrometheusFields struct {
// It requires Prometheus >= v2.33.0.
EnableRemoteWriteReceiver bool `json:"enableRemoteWriteReceiver,omitempty"`
// List of the protobuf message versions to accept when receiving the
// remote writes.
//
// It requires Prometheus >= v2.54.0.
//
// +kubebuilder:validation:MinItems=1
// +listType:=set
// +optional
RemoteWriteReceiverMessageVersions []RemoteWriteMessageVersion `json:"remoteWriteReceiverMessageVersions,omitempty"`
// Enable access to Prometheus feature flags. By default, no features are enabled.
//
// Enabling features which are disabled by default is entirely outside the
@ -1338,6 +1348,8 @@ type ThanosSpec struct {
// +k8s:openapi-gen=true
type RemoteWriteSpec struct {
// The URL of the endpoint to send samples to.
// +kubebuilder:validation:MinLength=1
// +required
URL string `json:"url"`
// The name of the remote write queue, it must be unique if specified. The
@ -1345,7 +1357,24 @@ type RemoteWriteSpec struct {
//
// It requires Prometheus >= v2.15.0.
//
Name string `json:"name,omitempty"`
//+optional
Name *string `json:"name,omitempty"`
// The Remote Write message's version to use when writing to the endpoint.
//
// `Version1.0` corresponds to the `prometheus.WriteRequest` protobuf message introduced in Remote Write 1.0.
// `Version2.0` corresponds to the `io.prometheus.write.v2.Request` protobuf message introduced in Remote Write 2.0.
//
// When `Version2.0` is selected, Prometheus will automatically be
// configured to append the metadata of scraped metrics to the WAL.
//
// Before setting this field, consult with your remote storage provider
// what message version it supports.
//
// It requires Prometheus >= v2.54.0.
//
// +optional
MessageVersion *RemoteWriteMessageVersion `json:"messageVersion,omitempty"`
// Enables sending of exemplars over remote write. Note that
// exemplar-storage itself must be enabled using the `spec.enableFeatures`
@ -1456,6 +1485,16 @@ type RemoteWriteSpec struct {
EnableHttp2 *bool `json:"enableHTTP2,omitempty"`
}
// +kubebuilder:validation:Enum=V1.0;V2.0
type RemoteWriteMessageVersion string
const (
// Remote Write message's version 1.0.
RemoteWriteMessageVersion1_0 = RemoteWriteMessageVersion("V1.0")
// Remote Write message's version 2.0.
RemoteWriteMessageVersion2_0 = RemoteWriteMessageVersion("V2.0")
)
// QueueConfig allows the tuning of remote write's queue_config parameters.
// This object is referenced in the RemoteWriteSpec object.
// +k8s:openapi-gen=true

View file

@ -752,6 +752,11 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) {
(*out)[key] = val
}
}
if in.RemoteWriteReceiverMessageVersions != nil {
in, out := &in.RemoteWriteReceiverMessageVersions, &out.RemoteWriteReceiverMessageVersions
*out = make([]RemoteWriteMessageVersion, len(*in))
copy(*out, *in)
}
if in.EnableFeatures != nil {
in, out := &in.EnableFeatures, &out.EnableFeatures
*out = make([]EnableFeature, len(*in))
@ -2600,6 +2605,16 @@ func (in *RemoteReadSpec) DeepCopy() *RemoteReadSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RemoteWriteSpec) DeepCopyInto(out *RemoteWriteSpec) {
*out = *in
if in.Name != nil {
in, out := &in.Name, &out.Name
*out = new(string)
**out = **in
}
if in.MessageVersion != nil {
in, out := &in.MessageVersion, &out.MessageVersion
*out = new(RemoteWriteMessageVersion)
**out = **in
}
if in.SendExemplars != nil {
in, out := &in.SendExemplars, &out.SendExemplars
*out = new(bool)

View file

@ -51,6 +51,7 @@ type CommonPrometheusFieldsApplyConfiguration struct {
ScrapeProtocols []monitoringv1.ScrapeProtocol `json:"scrapeProtocols,omitempty"`
ExternalLabels map[string]string `json:"externalLabels,omitempty"`
EnableRemoteWriteReceiver *bool `json:"enableRemoteWriteReceiver,omitempty"`
RemoteWriteReceiverMessageVersions []monitoringv1.RemoteWriteMessageVersion `json:"remoteWriteReceiverMessageVersions,omitempty"`
EnableFeatures []monitoringv1.EnableFeature `json:"enableFeatures,omitempty"`
ExternalURL *string `json:"externalUrl,omitempty"`
RoutePrefix *string `json:"routePrefix,omitempty"`
@ -330,6 +331,16 @@ func (b *CommonPrometheusFieldsApplyConfiguration) WithEnableRemoteWriteReceiver
return b
}
// WithRemoteWriteReceiverMessageVersions adds the given value to the RemoteWriteReceiverMessageVersions 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 RemoteWriteReceiverMessageVersions field.
func (b *CommonPrometheusFieldsApplyConfiguration) WithRemoteWriteReceiverMessageVersions(values ...monitoringv1.RemoteWriteMessageVersion) *CommonPrometheusFieldsApplyConfiguration {
for i := range values {
b.RemoteWriteReceiverMessageVersions = append(b.RemoteWriteReceiverMessageVersions, values[i])
}
return b
}
// WithEnableFeatures adds the given value to the EnableFeatures 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 EnableFeatures field.

View file

@ -268,6 +268,16 @@ func (b *PrometheusSpecApplyConfiguration) WithEnableRemoteWriteReceiver(value b
return b
}
// WithRemoteWriteReceiverMessageVersions adds the given value to the RemoteWriteReceiverMessageVersions 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 RemoteWriteReceiverMessageVersions field.
func (b *PrometheusSpecApplyConfiguration) WithRemoteWriteReceiverMessageVersions(values ...monitoringv1.RemoteWriteMessageVersion) *PrometheusSpecApplyConfiguration {
for i := range values {
b.RemoteWriteReceiverMessageVersions = append(b.RemoteWriteReceiverMessageVersions, values[i])
}
return b
}
// WithEnableFeatures adds the given value to the EnableFeatures 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 EnableFeatures field.

View file

@ -26,6 +26,7 @@ import (
type RemoteWriteSpecApplyConfiguration struct {
URL *string `json:"url,omitempty"`
Name *string `json:"name,omitempty"`
MessageVersion *v1.RemoteWriteMessageVersion `json:"messageVersion,omitempty"`
SendExemplars *bool `json:"sendExemplars,omitempty"`
SendNativeHistograms *bool `json:"sendNativeHistograms,omitempty"`
RemoteTimeout *v1.Duration `json:"remoteTimeout,omitempty"`
@ -68,6 +69,14 @@ func (b *RemoteWriteSpecApplyConfiguration) WithName(value string) *RemoteWriteS
return b
}
// WithMessageVersion sets the MessageVersion 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 MessageVersion field is set to the value of the last call.
func (b *RemoteWriteSpecApplyConfiguration) WithMessageVersion(value v1.RemoteWriteMessageVersion) *RemoteWriteSpecApplyConfiguration {
b.MessageVersion = &value
return b
}
// WithSendExemplars sets the SendExemplars 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 SendExemplars field is set to the value of the last call.

View file

@ -255,6 +255,16 @@ func (b *PrometheusAgentSpecApplyConfiguration) WithEnableRemoteWriteReceiver(va
return b
}
// WithRemoteWriteReceiverMessageVersions adds the given value to the RemoteWriteReceiverMessageVersions 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 RemoteWriteReceiverMessageVersions field.
func (b *PrometheusAgentSpecApplyConfiguration) WithRemoteWriteReceiverMessageVersions(values ...monitoringv1.RemoteWriteMessageVersion) *PrometheusAgentSpecApplyConfiguration {
for i := range values {
b.RemoteWriteReceiverMessageVersions = append(b.RemoteWriteReceiverMessageVersions, values[i])
}
return b
}
// WithEnableFeatures adds the given value to the EnableFeatures 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 EnableFeatures field.

View file

@ -219,6 +219,25 @@ func BuildCommonPrometheusArgs(cpf monitoringv1.CommonPrometheusFields, cg *Conf
if cpf.EnableRemoteWriteReceiver {
promArgs = cg.WithMinimumVersion("2.33.0").AppendCommandlineArgument(promArgs, monitoringv1.Argument{Name: "web.enable-remote-write-receiver"})
if len(cpf.RemoteWriteReceiverMessageVersions) > 0 {
versions := make([]string, 0, len(cpf.RemoteWriteReceiverMessageVersions))
for _, v := range cpf.RemoteWriteReceiverMessageVersions {
versions = append(versions, toProtobufMessageVersion(v))
}
promArgs = cg.WithMinimumVersion("2.54.0").AppendCommandlineArgument(
promArgs,
monitoringv1.Argument{
Name: "web.remote-write-receiver.accepted-protobuf-messages",
Value: strings.Join(versions, ","),
},
)
}
}
for _, rw := range cpf.RemoteWrite {
if ptr.Deref(rw.MessageVersion, monitoringv1.RemoteWriteMessageVersion1_0) == monitoringv1.RemoteWriteMessageVersion2_0 {
promArgs = cg.WithMinimumVersion("2.54.0").AppendCommandlineArgument(promArgs, monitoringv1.Argument{Name: "enable-feature", Value: "metadata-wal-records"})
}
}
if len(cpf.EnableFeatures) > 0 {

View file

@ -18,6 +18,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
@ -96,3 +97,67 @@ func TestStartupProbeTimeoutSeconds(t *testing.T) {
require.Equal(t, test.expectedMaxStartupDuration, startupPeriodSeconds*startupFailureThreshold)
}
}
func TestBuildCommonPrometheusArgsWithRemoteWriteMessageV2(t *testing.T) {
for _, tc := range []struct {
version string
messageVersion *monitoringv1.RemoteWriteMessageVersion
expectedPresent bool
}{
{
version: "v2.53.0",
},
{
version: "v2.53.0",
messageVersion: ptr.To(monitoringv1.RemoteWriteMessageVersion2_0),
},
{
version: "v2.54.0",
},
{
version: "v2.54.0",
messageVersion: ptr.To(monitoringv1.RemoteWriteMessageVersion1_0),
},
{
version: "v2.54.0",
messageVersion: ptr.To(monitoringv1.RemoteWriteMessageVersion2_0),
expectedPresent: true,
},
} {
t.Run("", func(t *testing.T) {
p := &monitoringv1.Prometheus{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "test",
},
Spec: monitoringv1.PrometheusSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
Version: tc.version,
RemoteWrite: []monitoringv1.RemoteWriteSpec{
{
URL: "http://example.com",
MessageVersion: tc.messageVersion,
},
},
},
},
}
cg, err := NewConfigGenerator(NewLogger(), p)
require.NoError(t, err)
args := BuildCommonPrometheusArgs(p.GetCommonPrometheusFields(), cg)
var found bool
for _, arg := range args {
if arg.Name == "enable-feature" && arg.Value == "metadata-wal-records" {
found = true
break
}
}
require.Equal(t, tc.expectedPresent, found)
})
}
}

View file

@ -261,7 +261,7 @@ func (cg *ConfigGenerator) AppendMapItem(m yaml.MapSlice, k string, v interface{
// the updated slice.
func (cg *ConfigGenerator) AppendCommandlineArgument(m []monitoringv1.Argument, argument monitoringv1.Argument) []monitoringv1.Argument {
if cg.notCompatible {
cg.logger.Warn(fmt.Sprintf("ignoring command line argument %q not supported by Prometheus", argument.Name))
cg.logger.Warn(fmt.Sprintf("ignoring command line argument %q=%q not supported by Prometheus", argument.Name, argument.Value))
return m
}
@ -2172,6 +2172,20 @@ func (cg *ConfigGenerator) addOAuth2ToYaml(
return cg.WithMinimumVersion("2.27.0").AppendMapItem(cfg, "oauth2", oauth2Cfg)
}
func toProtobufMessageVersion(mv monitoringv1.RemoteWriteMessageVersion) string {
switch mv {
case monitoringv1.RemoteWriteMessageVersion1_0:
return "prometheus.WriteRequest"
case monitoringv1.RemoteWriteMessageVersion2_0:
return "io.prometheus.write.v2.Request"
}
// The API should allow only the values listed in the switch/case
// statement but in case something goes wrong, let's return remote
// write v1.
return "prometheus.WriteRequest"
}
func (cg *ConfigGenerator) generateRemoteWriteConfig(
store *assets.StoreBuilder,
) yaml.MapItem {
@ -2193,8 +2207,12 @@ func (cg *ConfigGenerator) generateRemoteWriteConfig(
cfg = cg.WithMinimumVersion("2.15.0").AppendMapItem(cfg, "headers", stringMapToMapSlice(spec.Headers))
}
if spec.Name != "" {
cfg = cg.WithMinimumVersion("2.15.0").AppendMapItem(cfg, "name", spec.Name)
if ptr.Deref(spec.Name, "") != "" {
cfg = cg.WithMinimumVersion("2.15.0").AppendMapItem(cfg, "name", *spec.Name)
}
if spec.MessageVersion != nil {
cfg = cg.WithMinimumVersion("2.54.0").AppendMapItem(cfg, "protobuf_message", toProtobufMessageVersion(*spec.MessageVersion))
}
if spec.SendExemplars != nil {

View file

@ -4029,6 +4029,22 @@ func TestRemoteWriteConfig(t *testing.T) {
},
golden: "RemoteWriteConfig_v2.43.0_ProxyConfigWithMutiValues.golden",
},
{
version: "v2.53.0",
remoteWrite: monitoringv1.RemoteWriteSpec{
URL: "http://example.com",
MessageVersion: ptr.To(monitoringv1.RemoteWriteMessageVersion2_0),
},
golden: "RemoteWriteConfig_v2.53.0_MessageVersion2.golden",
},
{
version: "v2.54.0",
remoteWrite: monitoringv1.RemoteWriteSpec{
URL: "http://example.com",
MessageVersion: ptr.To(monitoringv1.RemoteWriteMessageVersion2_0),
},
golden: "RemoteWriteConfig_v2.54.0_MessageVersion2.golden",
},
} {
t.Run(fmt.Sprintf("i=%d,version=%s", i, tc.version), func(t *testing.T) {
p := defaultPrometheus()

View file

@ -2093,23 +2093,27 @@ func TestQueryLogFileVolumeMountNotPresent(t *testing.T) {
require.False(t, found, "Query log file mounted, when it shouldn't be.")
}
func TestEnableRemoteWriteReceiver(t *testing.T) {
func TestRemoteWriteReceiver(t *testing.T) {
for _, tc := range []struct {
version string
enableRemoteWriteReceiver bool
version string
enableRemoteWriteReceiver bool
messageVersions []monitoringv1.RemoteWriteMessageVersion
expectedRemoteWriteReceiverFlag bool
expectedMessageVersions string
}{
// Test lower version where feature not available
// Remote write receiver not supported.
{
version: "2.32.0",
enableRemoteWriteReceiver: true,
},
// Test correct version from which feature available
// Remote write receiver supported starting with v2.33.0.
{
version: "2.33.0",
enableRemoteWriteReceiver: true,
expectedRemoteWriteReceiverFlag: true,
},
// Remote write receiver supported but not enabled.
{
version: "2.33.0",
enableRemoteWriteReceiver: false,
@ -2121,27 +2125,67 @@ func TestEnableRemoteWriteReceiver(t *testing.T) {
enableRemoteWriteReceiver: true,
expectedRemoteWriteReceiverFlag: true,
},
// RemoteWriteMessageVersions not supported.
{
version: "2.53.0",
enableRemoteWriteReceiver: true,
expectedRemoteWriteReceiverFlag: true,
messageVersions: []monitoringv1.RemoteWriteMessageVersion{
monitoringv1.RemoteWriteMessageVersion2_0,
},
},
// RemoteWriteMessageVersions supported and set to one value.
{
version: "2.54.0",
enableRemoteWriteReceiver: true,
messageVersions: []monitoringv1.RemoteWriteMessageVersion{
monitoringv1.RemoteWriteMessageVersion2_0,
},
expectedRemoteWriteReceiverFlag: true,
expectedMessageVersions: "io.prometheus.write.v2.Request",
},
// RemoteWriteMessageVersions supported and set to 2 values.
{
version: "2.54.0",
enableRemoteWriteReceiver: true,
messageVersions: []monitoringv1.RemoteWriteMessageVersion{
monitoringv1.RemoteWriteMessageVersion1_0,
monitoringv1.RemoteWriteMessageVersion2_0,
},
expectedRemoteWriteReceiverFlag: true,
expectedMessageVersions: "prometheus.WriteRequest,io.prometheus.write.v2.Request",
},
} {
t.Run(fmt.Sprintf("case %s", tc.version), func(t *testing.T) {
sset, err := makeStatefulSetFromPrometheus(monitoringv1.Prometheus{
t.Run(tc.version, func(t *testing.T) {
p := monitoringv1.Prometheus{
Spec: monitoringv1.PrometheusSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
Version: tc.version,
EnableRemoteWriteReceiver: tc.enableRemoteWriteReceiver,
Version: tc.version,
EnableRemoteWriteReceiver: tc.enableRemoteWriteReceiver,
RemoteWriteReceiverMessageVersions: tc.messageVersions,
},
},
})
}
sset, err := makeStatefulSetFromPrometheus(p)
require.NoError(t, err)
found := false
var (
enabled bool
messageVersions string
)
for _, flag := range sset.Spec.Template.Spec.Containers[0].Args {
if flag == "--web.enable-remote-write-receiver" {
found = true
break
flag = strings.TrimPrefix(flag, "--")
values := strings.Split(flag, "=")
switch values[0] {
case "web.enable-remote-write-receiver":
enabled = true
case "web.remote-write-receiver.accepted-protobuf-messages":
messageVersions = values[1]
}
}
require.Equal(t, tc.expectedRemoteWriteReceiverFlag, found, "Expecting Prometheus remote write receiver to be %t, got %t", tc.expectedRemoteWriteReceiverFlag, found)
require.Equal(t, tc.expectedRemoteWriteReceiverFlag, enabled)
require.Equal(t, tc.expectedMessageVersions, messageVersions)
})
}
}

View file

@ -0,0 +1,10 @@
global:
evaluation_interval: 30s
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
scrape_configs: []
remote_write:
- url: http://example.com
remote_timeout: 30s

View file

@ -0,0 +1,11 @@
global:
evaluation_interval: 30s
scrape_interval: 30s
external_labels:
prometheus: default/test
prometheus_replica: $(POD_NAME)
scrape_configs: []
remote_write:
- url: http://example.com
remote_timeout: 30s
protobuf_message: io.prometheus.write.v2.Request

View file

@ -686,6 +686,28 @@ func testPromRemoteWriteWithTLS(t *testing.T) {
},
success: true,
},
{
// Prometheus Remote Write v2.0.
name: "remote-write-v2.0",
rwConfig: testFramework.PromRemoteWriteTestConfig{
ClientKey: testFramework.Key{
Filename: "client.key",
SecretName: "client-tls-key-cert-ca",
},
ClientCert: testFramework.Cert{
Filename: "client.crt",
ResourceName: "client-tls-key-cert-ca",
ResourceType: testFramework.SECRET,
},
CA: testFramework.Cert{
Filename: "ca.crt",
ResourceName: "client-tls-key-cert-ca",
ResourceType: testFramework.SECRET,
},
RemoteWriteMessageVersion: ptr.To(monitoringv1.RemoteWriteMessageVersion2_0),
},
success: true,
},
} {
tc := tc
@ -4773,6 +4795,85 @@ func testPrometheusCRDValidation(t *testing.T) {
},
expectedError: true,
},
{
name: "valid-remote-write-message-version",
prometheusSpec: monitoringv1.PrometheusSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
Replicas: &replicas,
Version: operator.DefaultPrometheusVersion,
ServiceAccountName: "prometheus",
RemoteWrite: []monitoringv1.RemoteWriteSpec{
{
URL: "http://example.com",
MessageVersion: ptr.To(monitoringv1.RemoteWriteMessageVersion2_0),
},
},
},
},
expectedError: false,
},
{
name: "invalid-remote-write-message-version",
prometheusSpec: monitoringv1.PrometheusSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
Replicas: &replicas,
Version: operator.DefaultPrometheusVersion,
ServiceAccountName: "prometheus",
RemoteWrite: []monitoringv1.RemoteWriteSpec{
{
URL: "http://example.com",
MessageVersion: ptr.To(monitoringv1.RemoteWriteMessageVersion("xx")),
},
},
},
},
expectedError: true,
},
{
name: "invalid-empty-remote-write-url",
prometheusSpec: monitoringv1.PrometheusSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
Replicas: &replicas,
Version: operator.DefaultPrometheusVersion,
ServiceAccountName: "prometheus",
RemoteWrite: []monitoringv1.RemoteWriteSpec{
{
URL: "",
},
},
},
},
expectedError: true,
},
{
name: "valid-remote-write-receiver-message-versions",
prometheusSpec: monitoringv1.PrometheusSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
Replicas: &replicas,
Version: operator.DefaultPrometheusVersion,
ServiceAccountName: "prometheus",
RemoteWriteReceiverMessageVersions: []monitoringv1.RemoteWriteMessageVersion{
monitoringv1.RemoteWriteMessageVersion2_0,
},
},
},
expectedError: false,
},
{
name: "invalid-remote-write-receiver-message-versions",
prometheusSpec: monitoringv1.PrometheusSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
Replicas: &replicas,
Version: operator.DefaultPrometheusVersion,
ServiceAccountName: "prometheus",
RemoteWriteReceiverMessageVersions: []monitoringv1.RemoteWriteMessageVersion{
monitoringv1.RemoteWriteMessageVersion2_0,
monitoringv1.RemoteWriteMessageVersion("xx"),
},
},
},
expectedError: true,
},
}
for _, test := range tests {

View file

@ -68,10 +68,11 @@ type Cert struct {
}
type PromRemoteWriteTestConfig struct {
ClientKey Key
ClientCert Cert
CA Cert
InsecureSkipVerify bool
ClientKey Key
ClientCert Cert
CA Cert
InsecureSkipVerify bool
RemoteWriteMessageVersion *monitoringv1.RemoteWriteMessageVersion
}
func (f *Framework) CreateCertificateResources(namespace, certsDir string, prwtc PromRemoteWriteTestConfig) error {
@ -222,7 +223,8 @@ func (f *Framework) MakeBasicPrometheus(ns, name, group string, replicas int32)
// AddRemoteWriteWithTLSToPrometheus configures Prometheus to send samples to the remote-write endpoint.
func (prwtc PromRemoteWriteTestConfig) AddRemoteWriteWithTLSToPrometheus(p *monitoringv1.Prometheus, url string) {
p.Spec.RemoteWrite = []monitoringv1.RemoteWriteSpec{{
URL: url,
URL: url,
MessageVersion: prwtc.RemoteWriteMessageVersion,
QueueConfig: &monitoringv1.QueueConfig{
BatchSendDeadline: (*monitoringv1.Duration)(ptr.To("1s")),
},