diff --git a/.chloggen/bug_2877.yaml b/.chloggen/bug_2877.yaml new file mode 100755 index 0000000000..0ca822551d --- /dev/null +++ b/.chloggen/bug_2877.yaml @@ -0,0 +1,20 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) +component: collector + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Create a Service Monitor for the monitoring service and another one for the collector service when the Prometheus exporter is used. + +# One or more tracking issues related to the change +issues: [2877] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: | + Create a Service Monitor for the collector Service when Prometheus exporter is used. A different Service Monitor is created for the monitoring service. + This helps excluding the headless service (duplicating the metrics collection) and splits responsibilities between the two Service Monitors. + Now, the operator.opentelemetry.io/collector-service-type label is used to differentiate the services. + operator.opentelemetry.io/collector-monitoring-service and operator.opentelemetry.io/collector-headless-service are deprecated now. \ No newline at end of file diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 5cf49c9cde..32fd6db2fd 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -259,12 +259,13 @@ service: Name: "test-collector", Namespace: "test", Labels: map[string]string{ - "app.kubernetes.io/component": "opentelemetry-collector", - "app.kubernetes.io/instance": "test.test", - "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/name": "test-collector", - "app.kubernetes.io/part-of": "opentelemetry", - "app.kubernetes.io/version": "latest", + "app.kubernetes.io/component": "opentelemetry-collector", + "app.kubernetes.io/instance": "test.test", + "app.kubernetes.io/managed-by": "opentelemetry-operator", + "app.kubernetes.io/name": "test-collector", + "app.kubernetes.io/part-of": "opentelemetry", + "app.kubernetes.io/version": "latest", + "operator.opentelemetry.io/collector-service-type": "base", }, Annotations: nil, }, @@ -291,6 +292,7 @@ service: "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", "operator.opentelemetry.io/collector-headless-service": "Exists", + "operator.opentelemetry.io/collector-service-type": "headless", }, Annotations: map[string]string{ "service.beta.openshift.io/serving-cert-secret-name": "test-collector-headless-tls", @@ -319,6 +321,7 @@ service: "app.kubernetes.io/name": "test-collector-monitoring", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", + "operator.opentelemetry.io/collector-service-type": "monitoring", "operator.opentelemetry.io/collector-monitoring-service": "Exists", }, Annotations: nil, @@ -506,12 +509,13 @@ service: Name: "test-collector", Namespace: "test", Labels: map[string]string{ - "app.kubernetes.io/component": "opentelemetry-collector", - "app.kubernetes.io/instance": "test.test", - "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/name": "test-collector", - "app.kubernetes.io/part-of": "opentelemetry", - "app.kubernetes.io/version": "latest", + "app.kubernetes.io/component": "opentelemetry-collector", + "app.kubernetes.io/instance": "test.test", + "app.kubernetes.io/managed-by": "opentelemetry-operator", + "app.kubernetes.io/name": "test-collector", + "app.kubernetes.io/part-of": "opentelemetry", + "app.kubernetes.io/version": "latest", + "operator.opentelemetry.io/collector-service-type": "base", }, Annotations: nil, }, @@ -537,6 +541,7 @@ service: "app.kubernetes.io/name": "test-collector", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", + "operator.opentelemetry.io/collector-service-type": "headless", "operator.opentelemetry.io/collector-headless-service": "Exists", }, Annotations: map[string]string{ @@ -566,6 +571,7 @@ service: "app.kubernetes.io/name": "test-collector-monitoring", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", + "operator.opentelemetry.io/collector-service-type": "monitoring", "operator.opentelemetry.io/collector-monitoring-service": "Exists", }, Annotations: nil, @@ -774,12 +780,13 @@ service: Name: "test-collector", Namespace: "test", Labels: map[string]string{ - "app.kubernetes.io/component": "opentelemetry-collector", - "app.kubernetes.io/instance": "test.test", - "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/name": "test-collector", - "app.kubernetes.io/part-of": "opentelemetry", - "app.kubernetes.io/version": "latest", + "app.kubernetes.io/component": "opentelemetry-collector", + "app.kubernetes.io/instance": "test.test", + "app.kubernetes.io/managed-by": "opentelemetry-operator", + "app.kubernetes.io/name": "test-collector", + "app.kubernetes.io/part-of": "opentelemetry", + "app.kubernetes.io/version": "latest", + "operator.opentelemetry.io/collector-service-type": "base", }, Annotations: nil, }, @@ -805,6 +812,7 @@ service: "app.kubernetes.io/name": "test-collector", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", + "operator.opentelemetry.io/collector-service-type": "headless", "operator.opentelemetry.io/collector-headless-service": "Exists", }, Annotations: map[string]string{ @@ -834,6 +842,7 @@ service: "app.kubernetes.io/name": "test-collector-monitoring", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", + "operator.opentelemetry.io/collector-service-type": "monitoring", "operator.opentelemetry.io/collector-monitoring-service": "Exists", }, Annotations: nil, @@ -1317,6 +1326,7 @@ service: "app.kubernetes.io/name": "test-collector-monitoring", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", + "operator.opentelemetry.io/collector-service-type": "monitoring", "operator.opentelemetry.io/collector-monitoring-service": "Exists", }, Annotations: nil, @@ -1711,6 +1721,7 @@ prometheus_cr: "app.kubernetes.io/name": "test-collector-monitoring", "app.kubernetes.io/part-of": "opentelemetry", "app.kubernetes.io/version": "latest", + "operator.opentelemetry.io/collector-service-type": "monitoring", "operator.opentelemetry.io/collector-monitoring-service": "Exists", }, Annotations: nil, diff --git a/internal/manifests/collector/collector.go b/internal/manifests/collector/collector.go index 9cb2302bba..65a19cdc9e 100644 --- a/internal/manifests/collector/collector.go +++ b/internal/manifests/collector/collector.go @@ -57,7 +57,7 @@ func Build(params manifests.Params) ([]client.Object, error) { if params.OtelCol.Spec.Mode == v1beta1.ModeSidecar { manifestFactories = append(manifestFactories, manifests.Factory(PodMonitor)) } else { - manifestFactories = append(manifestFactories, manifests.Factory(ServiceMonitor)) + manifestFactories = append(manifestFactories, manifests.Factory(ServiceMonitor), manifests.Factory(ServiceMonitorMonitoring)) } } diff --git a/internal/manifests/collector/podmonitor.go b/internal/manifests/collector/podmonitor.go index 86157c4138..761f7d307c 100644 --- a/internal/manifests/collector/podmonitor.go +++ b/internal/manifests/collector/podmonitor.go @@ -31,28 +31,14 @@ import ( // PodMonitor returns the pod monitor for the given instance. func PodMonitor(params manifests.Params) (*monitoringv1.PodMonitor, error) { - if !params.OtelCol.Spec.Observability.Metrics.EnableMetrics { - params.Log.V(2).Info("Metrics disabled for this OTEL Collector", - "params.OtelCol.name", params.OtelCol.Name, - "params.OtelCol.namespace", params.OtelCol.Namespace, - ) - return nil, nil - } else if params.Config.PrometheusCRAvailability() == prometheus.NotAvailable { - params.Log.V(1).Info("Cannot enable PodMonitor when prometheus CRDs are unavailable", - "params.OtelCol.name", params.OtelCol.Name, - "params.OtelCol.namespace", params.OtelCol.Namespace, - ) + if !shouldCreatePodMonitor(params) { return nil, nil } - var pm monitoringv1.PodMonitor - if params.OtelCol.Spec.Mode != v1beta1.ModeSidecar { - return nil, nil - } name := naming.PodMonitor(params.OtelCol.Name) labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, nil) selectorLabels := manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector) - pm = monitoringv1.PodMonitor{ + pm := monitoringv1.PodMonitor{ ObjectMeta: metav1.ObjectMeta{ Namespace: params.OtelCol.Namespace, Name: name, @@ -107,3 +93,22 @@ func metricsEndpointsFromConfig(logger logr.Logger, otelcol v1beta1.OpenTelemetr } return metricsEndpoints } + +func shouldCreatePodMonitor(params manifests.Params) bool { + l := params.Log.WithValues( + "params.OtelCol.name", params.OtelCol.Name, + "params.OtelCol.namespace", params.OtelCol.Namespace, + ) + + if !params.OtelCol.Spec.Observability.Metrics.EnableMetrics { + l.V(2).Info("Metrics disabled for this OTEL Collector. PodMonitor will not ve created") + return false + } else if params.Config.PrometheusCRAvailability() == prometheus.NotAvailable { + l.V(2).Info("Cannot enable PodMonitor when prometheus CRDs are unavailable") + return false + } else if params.OtelCol.Spec.Mode != v1beta1.ModeSidecar { + l.V(2).Info("Not using sidecar mode. PodMonitor will not be created") + return false + } + return true +} diff --git a/internal/manifests/collector/service.go b/internal/manifests/collector/service.go index 10d3ae15ab..d66e4bfe99 100644 --- a/internal/manifests/collector/service.go +++ b/internal/manifests/collector/service.go @@ -29,13 +29,26 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) -// headless and monitoring labels are to differentiate the headless/monitoring services from the clusterIP service. +// headless and monitoring labels are to differentiate the base/headless/monitoring services from the clusterIP service. const ( - headlessLabel = "operator.opentelemetry.io/collector-headless-service" - monitoringLabel = "operator.opentelemetry.io/collector-monitoring-service" - valueExists = "Exists" + headlessLabel = "operator.opentelemetry.io/collector-headless-service" + monitoringLabel = "operator.opentelemetry.io/collector-monitoring-service" + serviceTypeLabel = "operator.opentelemetry.io/collector-service-type" + valueExists = "Exists" ) +type ServiceType int + +const ( + BaseServiceType ServiceType = iota + HeadlessServiceType + MonitoringServiceType +) + +func (s ServiceType) String() string { + return [...]string{"base", "headless", "monitoring"}[s] +} + func HeadlessService(params manifests.Params) (*corev1.Service, error) { h, err := Service(params) if h == nil || err != nil { @@ -44,6 +57,7 @@ func HeadlessService(params manifests.Params) (*corev1.Service, error) { h.Name = naming.HeadlessService(params.OtelCol.Name) h.Labels[headlessLabel] = valueExists + h.Labels[serviceTypeLabel] = HeadlessServiceType.String() // copy to avoid modifying params.OtelCol.Annotations annotations := map[string]string{ @@ -63,6 +77,7 @@ func MonitoringService(params manifests.Params) (*corev1.Service, error) { name := naming.MonitoringService(params.OtelCol.Name) labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{}) labels[monitoringLabel] = valueExists + labels[serviceTypeLabel] = MonitoringServiceType.String() metricsPort, err := params.OtelCol.Spec.Config.Service.MetricsPort() if err != nil { @@ -90,6 +105,7 @@ func MonitoringService(params manifests.Params) (*corev1.Service, error) { func Service(params manifests.Params) (*corev1.Service, error) { name := naming.Service(params.OtelCol.Name) labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{}) + labels[serviceTypeLabel] = BaseServiceType.String() out, err := params.OtelCol.Spec.Config.Yaml() if err != nil { diff --git a/internal/manifests/collector/service_test.go b/internal/manifests/collector/service_test.go index 0e3c125be5..2a5cd8d08f 100644 --- a/internal/manifests/collector/service_test.go +++ b/internal/manifests/collector/service_test.go @@ -286,6 +286,7 @@ func service(name string, ports []v1beta1.PortsSpec) v1.Service { func serviceWithInternalTrafficPolicy(name string, ports []v1beta1.PortsSpec, internalTrafficPolicy v1.ServiceInternalTrafficPolicyType) v1.Service { params := deploymentParams() labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{}) + labels[serviceTypeLabel] = BaseServiceType.String() svcPorts := []v1.ServicePort{} for _, p := range ports { diff --git a/internal/manifests/collector/servicemonitor.go b/internal/manifests/collector/servicemonitor.go index 1713ccfe50..2c1088f44c 100644 --- a/internal/manifests/collector/servicemonitor.go +++ b/internal/manifests/collector/servicemonitor.go @@ -15,6 +15,7 @@ package collector import ( + "fmt" "strings" "github.com/go-logr/logr" @@ -29,30 +30,40 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) -// ServiceMonitor returns the service monitor for the given instance. +// ServiceMonitor returns the service monitor for the collector. func ServiceMonitor(params manifests.Params) (*monitoringv1.ServiceMonitor, error) { - if !params.OtelCol.Spec.Observability.Metrics.EnableMetrics { - params.Log.V(2).Info("Metrics disabled for this OTEL Collector", - "params.OtelCol.name", params.OtelCol.Name, - "params.OtelCol.namespace", params.OtelCol.Namespace, - ) - return nil, nil - } else if params.Config.PrometheusCRAvailability() == prometheus.NotAvailable { - params.Log.V(1).Info("Cannot enable ServiceMonitor when prometheus CRDs are unavailable", - "params.OtelCol.name", params.OtelCol.Name, - "params.OtelCol.namespace", params.OtelCol.Namespace, - ) - return nil, nil + name := naming.ServiceMonitor(params.OtelCol.Name) + endpoints := endpointsFromConfig(params.Log, params.OtelCol) + if len(endpoints) > 0 { + return createServiceMonitor(name, params, BaseServiceType, endpoints) } - var sm monitoringv1.ServiceMonitor + return nil, nil +} + +// ServiceMonitor returns the service monitor for the monitoring service of the collector. +func ServiceMonitorMonitoring(params manifests.Params) (*monitoringv1.ServiceMonitor, error) { + name := naming.ServiceMonitor(fmt.Sprintf("%s-monitoring", params.OtelCol.Name)) + endpoints := []monitoringv1.Endpoint{ + { + Port: "monitoring", + }, + } + return createServiceMonitor(name, params, MonitoringServiceType, endpoints) +} - if params.OtelCol.Spec.Mode == v1beta1.ModeSidecar { +// createServiceMonitor creates a Service Monitor using the provided name, the params from the instance, a label to identify the service +// to target (like the monitoring or the collector services) and the endpoints to scrape. +func createServiceMonitor(name string, params manifests.Params, serviceType ServiceType, endpoints []monitoringv1.Endpoint) (*monitoringv1.ServiceMonitor, error) { + if !shouldCreateServiceMonitor(params) { return nil, nil } - name := naming.ServiceMonitor(params.OtelCol.Name) + + var sm monitoringv1.ServiceMonitor + labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{}) selectorLabels := manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector) - selectorLabels[monitoringLabel] = valueExists + // This label is the one which differentiates the services + selectorLabels[serviceTypeLabel] = serviceType.String() sm = monitoringv1.ServiceMonitor{ ObjectMeta: metav1.ObjectMeta{ @@ -61,11 +72,7 @@ func ServiceMonitor(params manifests.Params) (*monitoringv1.ServiceMonitor, erro Labels: labels, }, Spec: monitoringv1.ServiceMonitorSpec{ - Endpoints: append([]monitoringv1.Endpoint{ - { - Port: "monitoring", - }, - }, endpointsFromConfig(params.Log, params.OtelCol)...), + Endpoints: endpoints, NamespaceSelector: monitoringv1.NamespaceSelector{ MatchNames: []string{params.OtelCol.Namespace}, }, @@ -78,6 +85,25 @@ func ServiceMonitor(params manifests.Params) (*monitoringv1.ServiceMonitor, erro return &sm, nil } +func shouldCreateServiceMonitor(params manifests.Params) bool { + l := params.Log.WithValues( + "params.OtelCol.name", params.OtelCol.Name, + "params.OtelCol.namespace", params.OtelCol.Namespace, + ) + + if !params.OtelCol.Spec.Observability.Metrics.EnableMetrics { + l.V(2).Info("Metrics disabled for this OTEL Collector. ServiceMonitor will not ve created") + return false + } else if params.Config.PrometheusCRAvailability() == prometheus.NotAvailable { + l.V(2).Info("Cannot enable ServiceMonitor when prometheus CRDs are unavailable") + return false + } else if params.OtelCol.Spec.Mode == v1beta1.ModeSidecar { + l.V(2).Info("Using sidecar mode. ServiceMonitor will not be created") + return false + } + return true +} + func endpointsFromConfig(logger logr.Logger, otelcol v1beta1.OpenTelemetryCollector) []monitoringv1.Endpoint { // TODO: https://github.com/open-telemetry/opentelemetry-operator/issues/2603 cfgStr, err := otelcol.Spec.Config.Yaml() diff --git a/internal/manifests/collector/servicemonitor_test.go b/internal/manifests/collector/servicemonitor_test.go index 8b0cc7f117..63f1b216c2 100644 --- a/internal/manifests/collector/servicemonitor_test.go +++ b/internal/manifests/collector/servicemonitor_test.go @@ -34,18 +34,24 @@ func TestDesiredServiceMonitors(t *testing.T) { params.OtelCol.Spec.Observability.Metrics.EnableMetrics = true actual, err = ServiceMonitor(params) assert.NoError(t, err) + assert.Nil(t, actual) + + // Check the monitoring SM + actual, err = ServiceMonitorMonitoring(params) + assert.NoError(t, err) assert.NotNil(t, actual) - assert.Equal(t, fmt.Sprintf("%s-collector", params.OtelCol.Name), actual.Name) + assert.Equal(t, fmt.Sprintf("%s-monitoring-collector", params.OtelCol.Name), actual.Name) assert.Equal(t, params.OtelCol.Namespace, actual.Namespace) assert.Equal(t, "monitoring", actual.Spec.Endpoints[0].Port) - expectedSelectorLabels := map[string]string{ - "app.kubernetes.io/component": "opentelemetry-collector", - "app.kubernetes.io/instance": "default.test", - "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/part-of": "opentelemetry", - "operator.opentelemetry.io/collector-monitoring-service": "Exists", + expectedSelectorLabelsMonitor := map[string]string{ + "app.kubernetes.io/component": "opentelemetry-collector", + "app.kubernetes.io/instance": "default.test", + "app.kubernetes.io/managed-by": "opentelemetry-operator", + "app.kubernetes.io/part-of": "opentelemetry", + "operator.opentelemetry.io/collector-service-type": "monitoring", } - assert.Equal(t, expectedSelectorLabels, actual.Spec.Selector.MatchLabels) + assert.Equal(t, expectedSelectorLabelsMonitor, actual.Spec.Selector.MatchLabels) + } func TestDesiredServiceMonitorsWithPrometheus(t *testing.T) { @@ -57,15 +63,14 @@ func TestDesiredServiceMonitorsWithPrometheus(t *testing.T) { assert.NotNil(t, actual) assert.Equal(t, fmt.Sprintf("%s-collector", params.OtelCol.Name), actual.Name) assert.Equal(t, params.OtelCol.Namespace, actual.Namespace) - assert.Equal(t, "monitoring", actual.Spec.Endpoints[0].Port) - assert.Equal(t, "prometheus-dev", actual.Spec.Endpoints[1].Port) - assert.Equal(t, "prometheus-prod", actual.Spec.Endpoints[2].Port) + assert.Equal(t, "prometheus-dev", actual.Spec.Endpoints[0].Port) + assert.Equal(t, "prometheus-prod", actual.Spec.Endpoints[1].Port) expectedSelectorLabels := map[string]string{ - "app.kubernetes.io/component": "opentelemetry-collector", - "app.kubernetes.io/instance": "default.test", - "app.kubernetes.io/managed-by": "opentelemetry-operator", - "app.kubernetes.io/part-of": "opentelemetry", - "operator.opentelemetry.io/collector-monitoring-service": "Exists", + "app.kubernetes.io/component": "opentelemetry-collector", + "app.kubernetes.io/instance": "default.test", + "app.kubernetes.io/managed-by": "opentelemetry-operator", + "app.kubernetes.io/part-of": "opentelemetry", + "operator.opentelemetry.io/collector-service-type": "base", } assert.Equal(t, expectedSelectorLabels, actual.Spec.Selector.MatchLabels) } diff --git a/tests/e2e-openshift/kafka/03-assert.yaml b/tests/e2e-openshift/kafka/03-assert.yaml index 0152057fd0..34cfabbea3 100644 --- a/tests/e2e-openshift/kafka/03-assert.yaml +++ b/tests/e2e-openshift/kafka/03-assert.yaml @@ -53,6 +53,7 @@ metadata: app.kubernetes.io/instance: chainsaw-kafka.kafka-exporter app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/name: kafka-exporter-collector + operator.opentelemetry.io/collector-service-type: headless operator.opentelemetry.io/collector-headless-service: Exists name: kafka-exporter-collector-headless namespace: chainsaw-kafka diff --git a/tests/e2e-openshift/monitoring/01-assert.yaml b/tests/e2e-openshift/monitoring/01-assert.yaml index 170c0f4148..aefeb5e82d 100644 --- a/tests/e2e-openshift/monitoring/01-assert.yaml +++ b/tests/e2e-openshift/monitoring/01-assert.yaml @@ -15,22 +15,21 @@ status: availableReplicas: 1 readyReplicas: 1 replicas: 1 - --- apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: labels: app.kubernetes.io/managed-by: opentelemetry-operator - app.kubernetes.io/name: cluster-collector-collector - name: cluster-collector-collector + app.kubernetes.io/name: cluster-collector-monitoring-collector + name: cluster-collector-monitoring-collector spec: endpoints: - port: monitoring selector: matchLabels: app.kubernetes.io/managed-by: opentelemetry-operator - + operator.opentelemetry.io/collector-service-type: monitoring --- apiVersion: v1 kind: Service @@ -68,6 +67,7 @@ metadata: app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/name: cluster-collector-collector app.kubernetes.io/part-of: opentelemetry + operator.opentelemetry.io/collector-service-type: headless operator.opentelemetry.io/collector-headless-service: Exists name: cluster-collector-collector-headless spec: @@ -87,7 +87,6 @@ spec: app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/part-of: opentelemetry type: ClusterIP - --- apiVersion: v1 kind: Service diff --git a/tests/e2e-openshift/monitoring/04-assert.yaml b/tests/e2e-openshift/monitoring/04-assert.yaml new file mode 100644 index 0000000000..0b72375c3b --- /dev/null +++ b/tests/e2e-openshift/monitoring/04-assert.yaml @@ -0,0 +1,14 @@ +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: cluster-collector2-collector + name: cluster-collector2-collector +spec: + endpoints: + - port: prometheus + selector: + matchLabels: + app.kubernetes.io/managed-by: opentelemetry-operator + operator.opentelemetry.io/collector-service-type: base diff --git a/tests/e2e-openshift/monitoring/04-use-prometheus-exporter.yaml b/tests/e2e-openshift/monitoring/04-use-prometheus-exporter.yaml new file mode 100644 index 0000000000..4eb57f2c9a --- /dev/null +++ b/tests/e2e-openshift/monitoring/04-use-prometheus-exporter.yaml @@ -0,0 +1,25 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: cluster-collector2 +spec: + mode: deployment + observability: + metrics: + enableMetrics: true + config: | + receivers: + otlp: + protocols: + grpc: + http: + processors: + exporters: + prometheus: + endpoint: "0.0.0.0:8091" + service: + pipelines: + metrics: + receivers: [otlp] + processors: [] + exporters: [prometheus] diff --git a/tests/e2e-openshift/monitoring/chainsaw-test.yaml b/tests/e2e-openshift/monitoring/chainsaw-test.yaml index 232e9a2522..0cf36e93f0 100755 --- a/tests/e2e-openshift/monitoring/chainsaw-test.yaml +++ b/tests/e2e-openshift/monitoring/chainsaw-test.yaml @@ -35,3 +35,9 @@ spec: - script: timeout: 5m content: ./check_metrics.sh + - name: step-04 + try: + - apply: + file: 04-use-prometheus-exporter.yaml + - assert: + file: 04-assert.yaml \ No newline at end of file diff --git a/tests/e2e-openshift/multi-cluster/02-assert.yaml b/tests/e2e-openshift/multi-cluster/02-assert.yaml index 7ba79cbe56..c4dae4d27f 100644 --- a/tests/e2e-openshift/multi-cluster/02-assert.yaml +++ b/tests/e2e-openshift/multi-cluster/02-assert.yaml @@ -58,6 +58,7 @@ metadata: app.kubernetes.io/name: otlp-receiver-collector app.kubernetes.io/part-of: opentelemetry app.kubernetes.io/version: latest + operator.opentelemetry.io/collector-service-type: headless operator.opentelemetry.io/collector-headless-service: Exists name: otlp-receiver-collector-headless namespace: chainsaw-multi-cluster-receive diff --git a/tests/e2e-openshift/multi-cluster/03-assert.yaml b/tests/e2e-openshift/multi-cluster/03-assert.yaml index bc3a130380..a22efdb841 100644 --- a/tests/e2e-openshift/multi-cluster/03-assert.yaml +++ b/tests/e2e-openshift/multi-cluster/03-assert.yaml @@ -58,6 +58,7 @@ metadata: app.kubernetes.io/name: otel-sender-collector app.kubernetes.io/part-of: opentelemetry app.kubernetes.io/version: latest + operator.opentelemetry.io/collector-service-type: headless operator.opentelemetry.io/collector-headless-service: Exists name: otel-sender-collector-headless namespace: chainsaw-multi-cluster-send diff --git a/tests/e2e-openshift/otlp-metrics-traces/02-assert.yaml b/tests/e2e-openshift/otlp-metrics-traces/02-assert.yaml index 057820e934..c2403ae18f 100644 --- a/tests/e2e-openshift/otlp-metrics-traces/02-assert.yaml +++ b/tests/e2e-openshift/otlp-metrics-traces/02-assert.yaml @@ -11,6 +11,27 @@ status: --- apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/instance: chainsaw-otlp-metrics.cluster-collector + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: cluster-collector-monitoring-collector + name: cluster-collector-monitoring-collector + namespace: chainsaw-otlp-metrics +spec: + endpoints: + - port: monitoring + namespaceSelector: + matchNames: + - chainsaw-otlp-metrics + selector: + matchLabels: + app.kubernetes.io/instance: chainsaw-otlp-metrics.cluster-collector + app.kubernetes.io/managed-by: opentelemetry-operator + operator.opentelemetry.io/collector-service-type: monitoring +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor metadata: labels: app.kubernetes.io/instance: chainsaw-otlp-metrics.cluster-collector @@ -20,7 +41,6 @@ metadata: namespace: chainsaw-otlp-metrics spec: endpoints: - - port: monitoring - port: prometheus namespaceSelector: matchNames: @@ -29,3 +49,4 @@ spec: matchLabels: app.kubernetes.io/instance: chainsaw-otlp-metrics.cluster-collector app.kubernetes.io/managed-by: opentelemetry-operator + operator.opentelemetry.io/collector-service-type: base \ No newline at end of file diff --git a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/01-assert.yaml b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/01-assert.yaml index eb0652f517..0b2bd613d3 100644 --- a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/01-assert.yaml +++ b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/01-assert.yaml @@ -1,5 +1,28 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: simplest-monitoring-collector + name: simplest-monitoring-collector + namespace: create-sm-prometheus +spec: + endpoints: + - port: monitoring + namespaceSelector: + matchNames: + - create-sm-prometheus + selector: + matchLabels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + operator.opentelemetry.io/collector-service-type: monitoring +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor metadata: labels: app.kubernetes.io/instance: create-sm-prometheus.simplest @@ -9,7 +32,6 @@ metadata: namespace: create-sm-prometheus spec: endpoints: - - port: monitoring - port: prometheus-dev - port: prometheus-prod namespaceSelector: @@ -21,7 +43,7 @@ spec: app.kubernetes.io/instance: create-sm-prometheus.simplest app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/part-of: opentelemetry - operator.opentelemetry.io/collector-monitoring-service: "Exists" + operator.opentelemetry.io/collector-service-type: base --- apiVersion: v1 kind: Service @@ -58,7 +80,7 @@ metadata: app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/name: simplest-collector-monitoring app.kubernetes.io/part-of: opentelemetry - operator.opentelemetry.io/collector-monitoring-service: "Exists" + operator.opentelemetry.io/collector-service-type: "monitoring" name: simplest-collector-monitoring namespace: create-sm-prometheus spec: diff --git a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/02-assert.yaml b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/02-assert.yaml index 4c5b8bd5b8..61f74dd1e1 100644 --- a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/02-assert.yaml +++ b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/02-assert.yaml @@ -1,5 +1,28 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: simplest-monitoring-collector + name: simplest-monitoring-collector + namespace: create-sm-prometheus +spec: + endpoints: + - port: monitoring + namespaceSelector: + matchNames: + - create-sm-prometheus + selector: + matchLabels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + operator.opentelemetry.io/collector-service-type: monitoring +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor metadata: labels: app.kubernetes.io/instance: create-sm-prometheus.simplest @@ -9,7 +32,6 @@ metadata: namespace: create-sm-prometheus spec: endpoints: - - port: monitoring - port: prometheus-prod namespaceSelector: matchNames: @@ -20,8 +42,7 @@ spec: app.kubernetes.io/instance: create-sm-prometheus.simplest app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/part-of: opentelemetry - operator.opentelemetry.io/collector-monitoring-service: "Exists" - + operator.opentelemetry.io/collector-service-type: base --- apiVersion: v1 kind: Service @@ -54,6 +75,7 @@ metadata: app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/name: simplest-collector-monitoring app.kubernetes.io/part-of: opentelemetry + operator.opentelemetry.io/collector-service-type: "monitoring" operator.opentelemetry.io/collector-monitoring-service: "Exists" name: simplest-collector-monitoring namespace: create-sm-prometheus diff --git a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/04-error.yaml b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/04-error.yaml index 61ad50e38b..263dbb3c64 100644 --- a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/04-error.yaml +++ b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/04-error.yaml @@ -1,19 +1,5 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: - labels: - app.kubernetes.io/instance: create-sm-prometheus.simplest - app.kubernetes.io/managed-by: opentelemetry-operator - app.kubernetes.io/name: simplest-collector name: simplest-collector namespace: create-sm-prometheus -spec: - endpoints: - - port: monitoring - - port: prometheus-prod - namespaceSelector: - matchNames: - - create-sm-prometheus - selector: - matchLabels: - app.kubernetes.io/managed-by: opentelemetry-operator diff --git a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/05-assert.yaml b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/05-assert.yaml index 3e8205803c..a0b8ebcda6 100644 --- a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/05-assert.yaml +++ b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/05-assert.yaml @@ -1,5 +1,28 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: simplest-monitoring-collector + name: simplest-monitoring-collector + namespace: create-sm-prometheus +spec: + endpoints: + - port: monitoring + namespaceSelector: + matchNames: + - create-sm-prometheus + selector: + matchLabels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + operator.opentelemetry.io/collector-service-type: monitoring +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor metadata: labels: app.kubernetes.io/instance: create-sm-prometheus.simplest @@ -9,7 +32,6 @@ metadata: namespace: create-sm-prometheus spec: endpoints: - - port: monitoring - port: prometheus-dev - port: prometheus-prod namespaceSelector: @@ -17,11 +39,11 @@ spec: - create-sm-prometheus selector: matchLabels: + app.kubernetes.io/component: opentelemetry-collector app.kubernetes.io/instance: create-sm-prometheus.simplest app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/part-of: opentelemetry - app.kubernetes.io/component: opentelemetry-collector - operator.opentelemetry.io/collector-monitoring-service: "Exists" + operator.opentelemetry.io/collector-service-type: base --- apiVersion: v1 kind: Service @@ -32,6 +54,7 @@ metadata: app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/name: simplest-collector-monitoring app.kubernetes.io/part-of: opentelemetry + operator.opentelemetry.io/collector-service-type: "monitoring" operator.opentelemetry.io/collector-monitoring-service: "Exists" name: simplest-collector-monitoring namespace: create-sm-prometheus diff --git a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/05-error.yaml b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/05-error.yaml index ecb59ba1fd..c97ae2597d 100644 --- a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/05-error.yaml +++ b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/05-error.yaml @@ -1,5 +1,28 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: simplest-monitoring-collector + name: simplest-monitoring-collector + namespace: create-sm-prometheus +spec: + endpoints: + - port: monitoring + namespaceSelector: + matchNames: + - create-sm-prometheus + selector: + matchLabels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + operator.opentelemetry.io/collector-service-type: monitoring +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor metadata: labels: app.kubernetes.io/instance: create-sm-prometheus.simplest @@ -9,7 +32,6 @@ metadata: namespace: create-sm-prometheus spec: endpoints: - - port: monitoring - port: prometheus-dev - port: prometheus-prod - port: prometheusremotewrite/prometheus @@ -18,5 +40,8 @@ spec: - create-sm-prometheus selector: matchLabels: - app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/component: opentelemetry-collector app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + operator.opentelemetry.io/collector-service-type: base diff --git a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/06-assert.yaml b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/06-assert.yaml index dcfecf5d81..be594e1a1d 100644 --- a/tests/e2e-prometheuscr/create-sm-prometheus-exporters/06-assert.yaml +++ b/tests/e2e-prometheuscr/create-sm-prometheus-exporters/06-assert.yaml @@ -1,5 +1,28 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: simplest-monitoring-collector + name: simplest-monitoring-collector + namespace: create-sm-prometheus +spec: + endpoints: + - port: monitoring + namespaceSelector: + matchNames: + - create-sm-prometheus + selector: + matchLabels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: create-sm-prometheus.simplest + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + operator.opentelemetry.io/collector-service-type: monitoring +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor metadata: labels: app.kubernetes.io/instance: create-sm-prometheus.simplest @@ -9,7 +32,6 @@ metadata: namespace: create-sm-prometheus spec: endpoints: - - port: monitoring - port: prometheus-dev namespaceSelector: matchNames: @@ -20,7 +42,7 @@ spec: app.kubernetes.io/instance: create-sm-prometheus.simplest app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/part-of: opentelemetry - operator.opentelemetry.io/collector-monitoring-service: "Exists" + operator.opentelemetry.io/collector-service-type: base --- apiVersion: v1 kind: Service @@ -31,6 +53,7 @@ metadata: app.kubernetes.io/managed-by: opentelemetry-operator app.kubernetes.io/name: simplest-collector-monitoring app.kubernetes.io/part-of: opentelemetry + operator.opentelemetry.io/collector-service-type: "monitoring" operator.opentelemetry.io/collector-monitoring-service: "Exists" name: simplest-collector-monitoring namespace: create-sm-prometheus