diff --git a/Documentation/api.md b/Documentation/api.md index 5d81514ac..0b8ad97d5 100644 --- a/Documentation/api.md +++ b/Documentation/api.md @@ -1996,6 +1996,20 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q </tr> <tr> <td> +<code>enableOTLPReceiver</code><br/> +<em> +bool +</em> +</td> +<td> +<em>(Optional)</em> +<p>Enable Prometheus to be used as a receiver for the OTLP Metrics protocol.</p> +<p>Note that the OTLP receiver endpoint is automatically enabled if <code>.spec.otlpConfig</code> is defined.</p> +<p>It requires Prometheus >= v2.47.0.</p> +</td> +</tr> +<tr> +<td> <code>remoteWriteReceiverMessageVersions</code><br/> <em> <a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion"> @@ -6921,6 +6935,20 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q </tr> <tr> <td> +<code>enableOTLPReceiver</code><br/> +<em> +bool +</em> +</td> +<td> +<em>(Optional)</em> +<p>Enable Prometheus to be used as a receiver for the OTLP Metrics protocol.</p> +<p>Note that the OTLP receiver endpoint is automatically enabled if <code>.spec.otlpConfig</code> is defined.</p> +<p>It requires Prometheus >= v2.47.0.</p> +</td> +</tr> +<tr> +<td> <code>remoteWriteReceiverMessageVersions</code><br/> <em> <a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion"> @@ -11645,6 +11673,20 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q </tr> <tr> <td> +<code>enableOTLPReceiver</code><br/> +<em> +bool +</em> +</td> +<td> +<em>(Optional)</em> +<p>Enable Prometheus to be used as a receiver for the OTLP Metrics protocol.</p> +<p>Note that the OTLP receiver endpoint is automatically enabled if <code>.spec.otlpConfig</code> is defined.</p> +<p>It requires Prometheus >= v2.47.0.</p> +</td> +</tr> +<tr> +<td> <code>remoteWriteReceiverMessageVersions</code><br/> <em> <a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion"> @@ -18228,6 +18270,20 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q </tr> <tr> <td> +<code>enableOTLPReceiver</code><br/> +<em> +bool +</em> +</td> +<td> +<em>(Optional)</em> +<p>Enable Prometheus to be used as a receiver for the OTLP Metrics protocol.</p> +<p>Note that the OTLP receiver endpoint is automatically enabled if <code>.spec.otlpConfig</code> is defined.</p> +<p>It requires Prometheus >= v2.47.0.</p> +</td> +</tr> +<tr> +<td> <code>remoteWriteReceiverMessageVersions</code><br/> <em> <a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion"> @@ -26085,6 +26141,20 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q </tr> <tr> <td> +<code>enableOTLPReceiver</code><br/> +<em> +bool +</em> +</td> +<td> +<em>(Optional)</em> +<p>Enable Prometheus to be used as a receiver for the OTLP Metrics protocol.</p> +<p>Note that the OTLP receiver endpoint is automatically enabled if <code>.spec.otlpConfig</code> is defined.</p> +<p>It requires Prometheus >= v2.47.0.</p> +</td> +</tr> +<tr> +<td> <code>remoteWriteReceiverMessageVersions</code><br/> <em> <a href="#monitoring.coreos.com/v1.RemoteWriteMessageVersion"> diff --git a/bundle.yaml b/bundle.yaml index 7639fa2e0..6b569651d 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -23853,6 +23853,14 @@ spec: type: string type: array x-kubernetes-list-type: set + enableOTLPReceiver: + description: |- + Enable Prometheus to be used as a receiver for the OTLP Metrics protocol. + + Note that the OTLP receiver endpoint is automatically enabled if `.spec.otlpConfig` is defined. + + It requires Prometheus >= v2.47.0. + type: boolean enableRemoteWriteReceiver: description: |- Enable Prometheus to be used as a receiver for the Prometheus remote @@ -35181,6 +35189,14 @@ spec: type: string type: array x-kubernetes-list-type: set + enableOTLPReceiver: + description: |- + Enable Prometheus to be used as a receiver for the OTLP Metrics protocol. + + Note that the OTLP receiver endpoint is automatically enabled if `.spec.otlpConfig` is defined. + + It requires Prometheus >= v2.47.0. + type: boolean enableRemoteWriteReceiver: description: |- Enable Prometheus to be used as a receiver for the Prometheus remote 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 215870de3..48264c48d 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml @@ -2910,6 +2910,14 @@ spec: type: string type: array x-kubernetes-list-type: set + enableOTLPReceiver: + description: |- + Enable Prometheus to be used as a receiver for the OTLP Metrics protocol. + + Note that the OTLP receiver endpoint is automatically enabled if `.spec.otlpConfig` is defined. + + It requires Prometheus >= v2.47.0. + type: boolean enableRemoteWriteReceiver: description: |- Enable Prometheus to be used as a receiver for the Prometheus remote 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 effdec4c4..8416a7e88 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml @@ -3605,6 +3605,14 @@ spec: type: string type: array x-kubernetes-list-type: set + enableOTLPReceiver: + description: |- + Enable Prometheus to be used as a receiver for the OTLP Metrics protocol. + + Note that the OTLP receiver endpoint is automatically enabled if `.spec.otlpConfig` is defined. + + It requires Prometheus >= v2.47.0. + type: boolean enableRemoteWriteReceiver: description: |- Enable Prometheus to be used as a receiver for the Prometheus remote diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml index f87d26618..c1f948378 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml @@ -2911,6 +2911,14 @@ spec: type: string type: array x-kubernetes-list-type: set + enableOTLPReceiver: + description: |- + Enable Prometheus to be used as a receiver for the OTLP Metrics protocol. + + Note that the OTLP receiver endpoint is automatically enabled if `.spec.otlpConfig` is defined. + + It requires Prometheus >= v2.47.0. + type: boolean enableRemoteWriteReceiver: description: |- Enable Prometheus to be used as a receiver for the Prometheus remote diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml index 63455bf62..baaec307d 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml @@ -3606,6 +3606,14 @@ spec: type: string type: array x-kubernetes-list-type: set + enableOTLPReceiver: + description: |- + Enable Prometheus to be used as a receiver for the OTLP Metrics protocol. + + Note that the OTLP receiver endpoint is automatically enabled if `.spec.otlpConfig` is defined. + + It requires Prometheus >= v2.47.0. + type: boolean enableRemoteWriteReceiver: description: |- Enable Prometheus to be used as a receiver for the Prometheus remote diff --git a/jsonnet/prometheus-operator/prometheusagents-crd.json b/jsonnet/prometheus-operator/prometheusagents-crd.json index 751f9dbc0..a44b26add 100644 --- a/jsonnet/prometheus-operator/prometheusagents-crd.json +++ b/jsonnet/prometheus-operator/prometheusagents-crd.json @@ -2528,6 +2528,10 @@ "type": "array", "x-kubernetes-list-type": "set" }, + "enableOTLPReceiver": { + "description": "Enable Prometheus to be used as a receiver for the OTLP Metrics protocol.\n\nNote that the OTLP receiver endpoint is automatically enabled if `.spec.otlpConfig` is defined.\n\nIt requires Prometheus >= v2.47.0.", + "type": "boolean" + }, "enableRemoteWriteReceiver": { "description": "Enable Prometheus to be used as a receiver for the Prometheus remote\nwrite protocol.\n\nWARNING: This is not considered an efficient way of ingesting samples.\nUse it with caution for specific low-volume use cases.\nIt is not suitable for replacing the ingestion via scraping and turning\nPrometheus into a push-based metrics collection system.\nFor more information see https://prometheus.io/docs/prometheus/latest/querying/api/#remote-write-receiver\n\nIt requires Prometheus >= v2.33.0.", "type": "boolean" diff --git a/jsonnet/prometheus-operator/prometheuses-crd.json b/jsonnet/prometheus-operator/prometheuses-crd.json index e9dc35725..2aa5056f4 100644 --- a/jsonnet/prometheus-operator/prometheuses-crd.json +++ b/jsonnet/prometheus-operator/prometheuses-crd.json @@ -3120,6 +3120,10 @@ "type": "array", "x-kubernetes-list-type": "set" }, + "enableOTLPReceiver": { + "description": "Enable Prometheus to be used as a receiver for the OTLP Metrics protocol.\n\nNote that the OTLP receiver endpoint is automatically enabled if `.spec.otlpConfig` is defined.\n\nIt requires Prometheus >= v2.47.0.", + "type": "boolean" + }, "enableRemoteWriteReceiver": { "description": "Enable Prometheus to be used as a receiver for the Prometheus remote\nwrite protocol.\n\nWARNING: This is not considered an efficient way of ingesting samples.\nUse it with caution for specific low-volume use cases.\nIt is not suitable for replacing the ingestion via scraping and turning\nPrometheus into a push-based metrics collection system.\nFor more information see https://prometheus.io/docs/prometheus/latest/querying/api/#remote-write-receiver\n\nIt requires Prometheus >= v2.33.0.", "type": "boolean" diff --git a/pkg/apis/monitoring/v1/prometheus_types.go b/pkg/apis/monitoring/v1/prometheus_types.go index 60f0bbb0f..1e31c56cc 100644 --- a/pkg/apis/monitoring/v1/prometheus_types.go +++ b/pkg/apis/monitoring/v1/prometheus_types.go @@ -318,6 +318,14 @@ type CommonPrometheusFields struct { // It requires Prometheus >= v2.33.0. EnableRemoteWriteReceiver bool `json:"enableRemoteWriteReceiver,omitempty"` + // Enable Prometheus to be used as a receiver for the OTLP Metrics protocol. + // + // Note that the OTLP receiver endpoint is automatically enabled if `.spec.otlpConfig` is defined. + // + // It requires Prometheus >= v2.47.0. + // +optional + EnableOTLPReceiver *bool `json:"enableOTLPReceiver,omitempty"` + // List of the protobuf message versions to accept when receiving the // remote writes. // diff --git a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go index f782d70bf..e553cffc5 100644 --- a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go @@ -752,6 +752,11 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) { (*out)[key] = val } } + if in.EnableOTLPReceiver != nil { + in, out := &in.EnableOTLPReceiver, &out.EnableOTLPReceiver + *out = new(bool) + **out = **in + } if in.RemoteWriteReceiverMessageVersions != nil { in, out := &in.RemoteWriteReceiverMessageVersions, &out.RemoteWriteReceiverMessageVersions *out = make([]RemoteWriteMessageVersion, len(*in)) diff --git a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go index e4e32995f..774e01270 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go +++ b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go @@ -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"` + EnableOTLPReceiver *bool `json:"enableOTLPReceiver,omitempty"` RemoteWriteReceiverMessageVersions []monitoringv1.RemoteWriteMessageVersion `json:"remoteWriteReceiverMessageVersions,omitempty"` EnableFeatures []monitoringv1.EnableFeature `json:"enableFeatures,omitempty"` ExternalURL *string `json:"externalUrl,omitempty"` @@ -332,6 +333,14 @@ func (b *CommonPrometheusFieldsApplyConfiguration) WithEnableRemoteWriteReceiver return b } +// WithEnableOTLPReceiver sets the EnableOTLPReceiver 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 EnableOTLPReceiver field is set to the value of the last call. +func (b *CommonPrometheusFieldsApplyConfiguration) WithEnableOTLPReceiver(value bool) *CommonPrometheusFieldsApplyConfiguration { + b.EnableOTLPReceiver = &value + 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. diff --git a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go index 2a3c57c0b..b0d8385ef 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go @@ -267,6 +267,14 @@ func (b *PrometheusSpecApplyConfiguration) WithEnableRemoteWriteReceiver(value b return b } +// WithEnableOTLPReceiver sets the EnableOTLPReceiver 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 EnableOTLPReceiver field is set to the value of the last call. +func (b *PrometheusSpecApplyConfiguration) WithEnableOTLPReceiver(value bool) *PrometheusSpecApplyConfiguration { + b.EnableOTLPReceiver = &value + 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. diff --git a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go index 2a86c0136..8b46a1fe0 100644 --- a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go @@ -255,6 +255,14 @@ func (b *PrometheusAgentSpecApplyConfiguration) WithEnableRemoteWriteReceiver(va return b } +// WithEnableOTLPReceiver sets the EnableOTLPReceiver 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 EnableOTLPReceiver field is set to the value of the last call. +func (b *PrometheusAgentSpecApplyConfiguration) WithEnableOTLPReceiver(value bool) *PrometheusAgentSpecApplyConfiguration { + b.EnableOTLPReceiver = &value + 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. diff --git a/pkg/prometheus/common_test.go b/pkg/prometheus/common_test.go index f21936e48..29cfabe5c 100644 --- a/pkg/prometheus/common_test.go +++ b/pkg/prometheus/common_test.go @@ -15,6 +15,7 @@ package prometheus import ( + "strings" "testing" "github.com/stretchr/testify/require" @@ -159,3 +160,125 @@ func TestBuildCommonPrometheusArgsWithRemoteWriteMessageV2(t *testing.T) { }) } } + +func TestBuildCommonPrometheusArgsWithOTLPReceiver(t *testing.T) { + for _, tc := range []struct { + version string + enableOTLPReceiver *bool + expectedOTLPReceiverFlag bool + OTLPConfig *monitoringv1.OTLPConfig + expectedOTLPFeatureEnabled bool + }{ + // OTLP receiver not supported. + { + version: "2.46.0", + enableOTLPReceiver: ptr.To(true), + expectedOTLPFeatureEnabled: false, + expectedOTLPReceiverFlag: false, + }, + // OTLP receiver supported starting with v2.47.0. + { + version: "2.47.0", + enableOTLPReceiver: ptr.To(true), + expectedOTLPFeatureEnabled: true, + expectedOTLPReceiverFlag: false, + }, + // OTLP receiver supported but not enabled. + { + version: "2.47.0", + enableOTLPReceiver: ptr.To(false), + expectedOTLPFeatureEnabled: false, + expectedOTLPReceiverFlag: false, + }, + // OTLP receiver config supported but verison not support + { + version: "2.46.0", + enableOTLPReceiver: ptr.To(false), + OTLPConfig: &monitoringv1.OTLPConfig{ + PromoteResourceAttributes: []string{"aa", "bb"}, + }, + expectedOTLPFeatureEnabled: false, + expectedOTLPReceiverFlag: false, + }, + // OTLP receiver config supported + { + version: "2.55.0", + enableOTLPReceiver: nil, + OTLPConfig: &monitoringv1.OTLPConfig{ + PromoteResourceAttributes: []string{"aa", "bb"}, + }, + expectedOTLPFeatureEnabled: true, + expectedOTLPReceiverFlag: false, + }, + // OTLP receiver config supported with verison 3.x + { + version: "3.0.0", + enableOTLPReceiver: nil, + OTLPConfig: &monitoringv1.OTLPConfig{ + PromoteResourceAttributes: []string{"aa", "bb"}, + }, + expectedOTLPFeatureEnabled: false, + expectedOTLPReceiverFlag: true, + }, + // Test higher version from which enable-feature available. + { + version: "2.54.0", + enableOTLPReceiver: ptr.To(true), + expectedOTLPFeatureEnabled: true, + expectedOTLPReceiverFlag: false, + }, + // Test higher version from which web.enable-otlp-receiver arg available. + { + version: "3.0.0", + enableOTLPReceiver: ptr.To(true), + expectedOTLPFeatureEnabled: false, + expectedOTLPReceiverFlag: true, + }, + // Test higher version but not enabled. + { + version: "3.0.0", + enableOTLPReceiver: ptr.To(false), + expectedOTLPFeatureEnabled: false, + expectedOTLPReceiverFlag: false, + }, + } { + t.Run("", func(t *testing.T) { + p := &monitoringv1.Prometheus{ + Spec: monitoringv1.PrometheusSpec{ + CommonPrometheusFields: monitoringv1.CommonPrometheusFields{ + Version: tc.version, + EnableOTLPReceiver: tc.enableOTLPReceiver, + OTLP: tc.OTLPConfig, + }, + }, + } + + cg, err := NewConfigGenerator(NewLogger(), p) + require.NoError(t, err) + + args := cg.BuildCommonPrometheusArgs() + + var ( + argsEnabled bool + featureEnabled bool + ) + for _, arg := range args { + switch arg.Name { + case "web.enable-otlp-receiver": + argsEnabled = true + case "enable-feature": + feats := strings.Split(arg.Value, ",") + for _, feat := range feats { + if feat == "otlp-write-receiver" { + featureEnabled = true + break + } + } + } + } + + require.Equal(t, tc.expectedOTLPReceiverFlag, argsEnabled) + require.Equal(t, tc.expectedOTLPFeatureEnabled, featureEnabled) + }) + } +} diff --git a/pkg/prometheus/promcfg.go b/pkg/prometheus/promcfg.go index 19b4ae95a..38659bcef 100644 --- a/pkg/prometheus/promcfg.go +++ b/pkg/prometheus/promcfg.go @@ -1009,6 +1009,15 @@ func (cg *ConfigGenerator) BuildCommonPrometheusArgs() []monitoringv1.Argument { } } + // Turn on the OTLP receiver endpoint automatically if/when the OTLP config isn't empty. + if (cpf.EnableOTLPReceiver != nil && *cpf.EnableOTLPReceiver) || (cpf.EnableOTLPReceiver == nil && cpf.OTLP != nil) { + if cg.version.Major >= 3 { + promArgs = cg.AppendCommandlineArgument(promArgs, monitoringv1.Argument{Name: "web.enable-otlp-receiver"}) + } else { + promArgs = cg.WithMinimumVersion("2.47.0").AppendCommandlineArgument(promArgs, monitoringv1.Argument{Name: "enable-feature", Value: "otlp-write-receiver"}) + } + } + if len(cpf.EnableFeatures) > 0 { efs := make([]string, len(cpf.EnableFeatures)) for i := range cpf.EnableFeatures {