diff --git a/.chloggen/feat-add-prometheuscr-namespaceselectors.yaml b/.chloggen/feat-add-prometheuscr-namespaceselectors.yaml new file mode 100644 index 0000000000..d4bbbe20af --- /dev/null +++ b/.chloggen/feat-add-prometheuscr-namespaceselectors.yaml @@ -0,0 +1,17 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'enhancement' + +# 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: 'operator' + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Add Prometheus CR namespace selectors" + +# One or more tracking issues related to the change +issues: + - 3086 + +# (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: diff --git a/README.md b/README.md index 1ae0b4b561..f5918697d8 100644 --- a/README.md +++ b/README.md @@ -709,8 +709,15 @@ spec: serviceAccount: everything-prometheus-operator-needs prometheusCR: enabled: true + scrapeInterval: 30s serviceMonitorSelector: {} + serviceMonitorNamespaceSelector: {} podMonitorSelector: {} + podMonitorNamespaceSelector: {} + scrapeConfigSelector: {} + scrapeConfigNamespaceSelector: {} + probeSelector: {} + probeNamespaceSelector: {} config: receivers: prometheus: diff --git a/apis/v1beta1/targetallocator_types.go b/apis/v1beta1/targetallocator_types.go index ca9bc9aa0c..911ea4c10a 100644 --- a/apis/v1beta1/targetallocator_types.go +++ b/apis/v1beta1/targetallocator_types.go @@ -36,24 +36,52 @@ type TargetAllocatorPrometheusCR struct { // label selector matches no objects. // +optional PodMonitorSelector *metav1.LabelSelector `json:"podMonitorSelector,omitempty"` + // Namespaces to be selected to look for PodMonitors for target discovery. + // A label selector is a label query over a set of resources. The result of matchLabels and + // matchExpressions are ANDed. An empty label selector matches all objects. A null + // label selector matches no objects. + // +optional + // +kubebuilder:default:={} + PodMonitorNamespaceSelector *metav1.LabelSelector `json:"podMonitorNamespaceSelector,omitempty"` // ServiceMonitors to be selected for target discovery. // A label selector is a label query over a set of resources. The result of matchLabels and // matchExpressions are ANDed. An empty label selector matches all objects. A null // label selector matches no objects. // +optional ServiceMonitorSelector *metav1.LabelSelector `json:"serviceMonitorSelector,omitempty"` + // Namespaces to be selected to look for ServiceMonitors for target discovery. + // A label selector is a label query over a set of resources. The result of matchLabels and + // matchExpressions are ANDed. An empty label selector matches all objects. A null + // label selector matches no objects. + // +optional + // +kubebuilder:default:={} + ServiceMonitorNamespaceSelector *metav1.LabelSelector `json:"serviceMonitorNamespaceSelector,omitempty"` // ScrapeConfigs to be selected for target discovery. // A label selector is a label query over a set of resources. The result of matchLabels and // matchExpressions are ANDed. An empty label selector matches all objects. A null // label selector matches no objects. // +optional ScrapeConfigSelector *metav1.LabelSelector `json:"scrapeConfigSelector,omitempty"` + // Namespaces to be selected to look for ScrapeConfigs for target discovery. + // A label selector is a label query over a set of resources. The result of matchLabels and + // matchExpressions are ANDed. An empty label selector matches all objects. A null + // label selector matches no objects. + // +optional + // +kubebuilder:default:={} + ScrapeConfigNamespaceSelector *metav1.LabelSelector `json:"scrapeConfigNamespaceSelector,omitempty"` // Probes to be selected for target discovery. // A label selector is a label query over a set of resources. The result of matchLabels and // matchExpressions are ANDed. An empty label selector matches all objects. A null // label selector matches no objects. // +optional ProbeSelector *metav1.LabelSelector `json:"probeSelector,omitempty"` + // Namespaces to be selected to look for Probes for target discovery. + // A label selector is a label query over a set of resources. The result of matchLabels and + // matchExpressions are ANDed. An empty label selector matches all objects. A null + // label selector matches no objects. + // +optional + // +kubebuilder:default:={} + ProbeNamespaceSelector *metav1.LabelSelector `json:"probeNamespaceSelector,omitempty"` } type ( diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go index 8d2402a809..33e4acfa52 100644 --- a/apis/v1beta1/zz_generated.deepcopy.go +++ b/apis/v1beta1/zz_generated.deepcopy.go @@ -782,21 +782,41 @@ func (in *TargetAllocatorPrometheusCR) DeepCopyInto(out *TargetAllocatorPromethe *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } + if in.PodMonitorNamespaceSelector != nil { + in, out := &in.PodMonitorNamespaceSelector, &out.PodMonitorNamespaceSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } if in.ServiceMonitorSelector != nil { in, out := &in.ServiceMonitorSelector, &out.ServiceMonitorSelector *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } + if in.ServiceMonitorNamespaceSelector != nil { + in, out := &in.ServiceMonitorNamespaceSelector, &out.ServiceMonitorNamespaceSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } if in.ScrapeConfigSelector != nil { in, out := &in.ScrapeConfigSelector, &out.ScrapeConfigSelector *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } + if in.ScrapeConfigNamespaceSelector != nil { + in, out := &in.ScrapeConfigNamespaceSelector, &out.ScrapeConfigNamespaceSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } if in.ProbeSelector != nil { in, out := &in.ProbeSelector, &out.ProbeSelector *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } + if in.ProbeNamespaceSelector != nil { + in, out := &in.ProbeNamespaceSelector, &out.ProbeNamespaceSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorPrometheusCR. diff --git a/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml index 43d027ed6f..26f362d022 100644 --- a/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -7883,6 +7883,33 @@ spec: properties: enabled: type: boolean + podMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic podMonitorSelector: properties: matchExpressions: @@ -7909,6 +7936,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic probeSelector: properties: matchExpressions: @@ -7935,6 +7989,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + scrapeConfigNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic scrapeConfigSelector: properties: matchExpressions: @@ -7965,6 +8046,33 @@ spec: default: 30s format: duration type: string + serviceMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic serviceMonitorSelector: properties: matchExpressions: diff --git a/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml index 43d027ed6f..26f362d022 100644 --- a/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -7883,6 +7883,33 @@ spec: properties: enabled: type: boolean + podMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic podMonitorSelector: properties: matchExpressions: @@ -7909,6 +7936,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic probeSelector: properties: matchExpressions: @@ -7935,6 +7989,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + scrapeConfigNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic scrapeConfigSelector: properties: matchExpressions: @@ -7965,6 +8046,33 @@ spec: default: 30s format: duration type: string + serviceMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic serviceMonitorSelector: properties: matchExpressions: diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index 06baf367dc..8f1ffb3e57 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -7869,6 +7869,33 @@ spec: properties: enabled: type: boolean + podMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic podMonitorSelector: properties: matchExpressions: @@ -7895,6 +7922,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic probeSelector: properties: matchExpressions: @@ -7921,6 +7975,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + scrapeConfigNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic scrapeConfigSelector: properties: matchExpressions: @@ -7951,6 +8032,33 @@ spec: default: 30s format: duration type: string + serviceMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic serviceMonitorSelector: properties: matchExpressions: diff --git a/config/crd/bases/opentelemetry.io_targetallocators.yaml b/config/crd/bases/opentelemetry.io_targetallocators.yaml index 39af01073d..0bf3205c03 100644 --- a/config/crd/bases/opentelemetry.io_targetallocators.yaml +++ b/config/crd/bases/opentelemetry.io_targetallocators.yaml @@ -2243,6 +2243,33 @@ spec: properties: enabled: type: boolean + podMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic podMonitorSelector: properties: matchExpressions: @@ -2269,6 +2296,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic probeSelector: properties: matchExpressions: @@ -2295,6 +2349,33 @@ spec: type: object type: object x-kubernetes-map-type: atomic + scrapeConfigNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic scrapeConfigSelector: properties: matchExpressions: @@ -2325,6 +2406,33 @@ spec: default: 30s format: duration type: string + serviceMonitorNamespaceSelector: + default: {} + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + type: object + type: object + x-kubernetes-map-type: atomic serviceMonitorSelector: properties: matchExpressions: diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 372a75ae43..5c5f0b84cb 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,3 +1,2 @@ resources: - manager.yaml - diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 053bf6966a..1ee6f4e429 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -1512,9 +1512,13 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -1548,7 +1552,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: corev1.PodSpec{ @@ -1680,7 +1684,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -1971,9 +1975,13 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -2007,7 +2015,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: corev1.PodSpec{ @@ -2139,7 +2147,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -2475,9 +2483,13 @@ https: tls_key_file_path: /tls/tls.key prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -2511,7 +2523,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", + "opentelemetry-targetallocator-config/hash": "02ef308f21c5312c388985bd8ca91246d1df7a3a5031135ec176f3c975e2fa37", }, }, Spec: corev1.PodSpec{ @@ -2669,7 +2681,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", + "opentelemetry-targetallocator-config/hash": "02ef308f21c5312c388985bd8ca91246d1df7a3a5031135ec176f3c975e2fa37", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -3544,9 +3556,13 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -3580,7 +3596,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", + "opentelemetry-targetallocator-config/hash": "7a839fe32950e427672bf7038e88d953ceecf1531457af7c43dc78300dc85eca", }, }, Spec: corev1.PodSpec{ @@ -3712,7 +3728,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", + "opentelemetry-targetallocator-config/hash": "7a839fe32950e427672bf7038e88d953ceecf1531457af7c43dc78300dc85eca", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -3819,9 +3835,13 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -3855,7 +3875,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", + "opentelemetry-targetallocator-config/hash": "7a839fe32950e427672bf7038e88d953ceecf1531457af7c43dc78300dc85eca", }, }, Spec: corev1.PodSpec{ @@ -3987,7 +4007,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", + "opentelemetry-targetallocator-config/hash": "7a839fe32950e427672bf7038e88d953ceecf1531457af7c43dc78300dc85eca", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -4144,9 +4164,13 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -4180,7 +4204,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: corev1.PodSpec{ @@ -4312,7 +4336,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", + "opentelemetry-targetallocator-config/hash": "a81383bc4e7ebbf141d2fd9cde3dcd9758bc47f27af6cbaeb0f14ab6360e08c6", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -4443,9 +4467,13 @@ https: tls_key_file_path: /tls/tls.key prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null + service_monitor_namespace_selector: null service_monitor_selector: null `, }, @@ -4479,7 +4507,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", + "opentelemetry-targetallocator-config/hash": "02ef308f21c5312c388985bd8ca91246d1df7a3a5031135ec176f3c975e2fa37", }, }, Spec: corev1.PodSpec{ @@ -4637,7 +4665,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", + "opentelemetry-targetallocator-config/hash": "02ef308f21c5312c388985bd8ca91246d1df7a3a5031135ec176f3c975e2fa37", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ diff --git a/docs/api.md b/docs/api.md index e0c219d54d..65e63306e4 100644 --- a/docs/api.md +++ b/docs/api.md @@ -48086,6 +48086,18 @@ All CR instances which the ServiceAccount has access to will be retrieved. This Enabled indicates whether to use a PrometheusOperator custom resources as targets or not.
false + + podMonitorNamespaceSelector + object + + Namespaces to be selected to look for PodMonitors for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects.
+
+ Default: map[]
+ + false podMonitorSelector object @@ -48096,6 +48108,18 @@ matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects.
false + + probeNamespaceSelector + object + + Namespaces to be selected to look for Probes for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects.
+
+ Default: map[]
+ + false probeSelector object @@ -48106,6 +48130,18 @@ matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects.
false + + scrapeConfigNamespaceSelector + object + + Namespaces to be selected to look for ScrapeConfigs for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects.
+
+ Default: map[]
+ + false scrapeConfigSelector object @@ -48129,6 +48165,18 @@ Default: "30s"
Default: 30s
false + + serviceMonitorNamespaceSelector + object + + Namespaces to be selected to look for ServiceMonitors for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects.
+
+ Default: map[]
+ + false serviceMonitorSelector object @@ -48143,6 +48191,91 @@ label selector matches no objects.
+### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.podMonitorNamespaceSelector +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) + + + +Namespaces to be selected to look for PodMonitors for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
matchExpressions[]object + matchExpressions is a list of label selector requirements. The requirements are ANDed.
+
false
matchLabelsmap[string]string + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels +map is equivalent to an element of matchExpressions, whose key field is "key", the +operator is "In", and the values array contains only "value". The requirements are ANDed.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.podMonitorNamespaceSelector.matchExpressions[index] +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscrpodmonitornamespaceselector) + + + +A label selector requirement is a selector that contains values, a key, and an operator that +relates the key and values. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + key is the label key that the selector applies to.
+
true
operatorstring + operator represents a key's relationship to a set of values. +Valid operators are In, NotIn, Exists and DoesNotExist.
+
true
values[]string + values is an array of string values. If the operator is In or NotIn, +the values array must be non-empty. If the operator is Exists or DoesNotExist, +the values array must be empty. This array is replaced during a strategic +merge patch.
+
false
+ + ### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.podMonitorSelector [↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) @@ -48187,6 +48320,91 @@ operator is "In", and the values array contains only "value". The requirements a +A label selector requirement is a selector that contains values, a key, and an operator that +relates the key and values. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + key is the label key that the selector applies to.
+
true
operatorstring + operator represents a key's relationship to a set of values. +Valid operators are In, NotIn, Exists and DoesNotExist.
+
true
values[]string + values is an array of string values. If the operator is In or NotIn, +the values array must be non-empty. If the operator is Exists or DoesNotExist, +the values array must be empty. This array is replaced during a strategic +merge patch.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.probeNamespaceSelector +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) + + + +Namespaces to be selected to look for Probes for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
matchExpressions[]object + matchExpressions is a list of label selector requirements. The requirements are ANDed.
+
false
matchLabelsmap[string]string + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels +map is equivalent to an element of matchExpressions, whose key field is "key", the +operator is "In", and the values array contains only "value". The requirements are ANDed.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.probeNamespaceSelector.matchExpressions[index] +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscrprobenamespaceselector) + + + A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. @@ -48272,6 +48490,91 @@ operator is "In", and the values array contains only "value". The requirements a +A label selector requirement is a selector that contains values, a key, and an operator that +relates the key and values. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + key is the label key that the selector applies to.
+
true
operatorstring + operator represents a key's relationship to a set of values. +Valid operators are In, NotIn, Exists and DoesNotExist.
+
true
values[]string + values is an array of string values. If the operator is In or NotIn, +the values array must be non-empty. If the operator is Exists or DoesNotExist, +the values array must be empty. This array is replaced during a strategic +merge patch.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.scrapeConfigNamespaceSelector +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) + + + +Namespaces to be selected to look for ScrapeConfigs for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
matchExpressions[]object + matchExpressions is a list of label selector requirements. The requirements are ANDed.
+
false
matchLabelsmap[string]string + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels +map is equivalent to an element of matchExpressions, whose key field is "key", the +operator is "In", and the values array contains only "value". The requirements are ANDed.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.scrapeConfigNamespaceSelector.matchExpressions[index] +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscrscrapeconfignamespaceselector) + + + A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. @@ -48357,6 +48660,91 @@ operator is "In", and the values array contains only "value". The requirements a +A label selector requirement is a selector that contains values, a key, and an operator that +relates the key and values. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + key is the label key that the selector applies to.
+
true
operatorstring + operator represents a key's relationship to a set of values. +Valid operators are In, NotIn, Exists and DoesNotExist.
+
true
values[]string + values is an array of string values. If the operator is In or NotIn, +the values array must be non-empty. If the operator is Exists or DoesNotExist, +the values array must be empty. This array is replaced during a strategic +merge patch.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.serviceMonitorNamespaceSelector +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) + + + +Namespaces to be selected to look for ServiceMonitors for target discovery. +A label selector is a label query over a set of resources. The result of matchLabels and +matchExpressions are ANDed. An empty label selector matches all objects. A null +label selector matches no objects. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
matchExpressions[]object + matchExpressions is a list of label selector requirements. The requirements are ANDed.
+
false
matchLabelsmap[string]string + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels +map is equivalent to an element of matchExpressions, whose key field is "key", the +operator is "In", and the values array contains only "value". The requirements are ANDed.
+
false
+ + +### OpenTelemetryCollector.spec.targetAllocator.prometheusCR.serviceMonitorNamespaceSelector.matchExpressions[index] +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscrservicemonitornamespaceselector) + + + A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. diff --git a/internal/manifests/targetallocator/configmap.go b/internal/manifests/targetallocator/configmap.go index 27eb606b47..ea91fe1fc3 100644 --- a/internal/manifests/targetallocator/configmap.go +++ b/internal/manifests/targetallocator/configmap.go @@ -104,15 +104,14 @@ func ConfigMap(params Params) (*corev1.ConfigMap, error) { if taSpec.PrometheusCR.ScrapeInterval.Size() > 0 { prometheusCRConfig["scrape_interval"] = taSpec.PrometheusCR.ScrapeInterval.Duration } - prometheusCRConfig["service_monitor_selector"] = taSpec.PrometheusCR.ServiceMonitorSelector - + prometheusCRConfig["service_monitor_namespace_selector"] = taSpec.PrometheusCR.ServiceMonitorNamespaceSelector prometheusCRConfig["pod_monitor_selector"] = taSpec.PrometheusCR.PodMonitorSelector - + prometheusCRConfig["pod_monitor_namespace_selector"] = taSpec.PrometheusCR.PodMonitorNamespaceSelector prometheusCRConfig["scrape_config_selector"] = taSpec.PrometheusCR.ScrapeConfigSelector - + prometheusCRConfig["scrape_config_namespace_selector"] = taSpec.PrometheusCR.ScrapeConfigNamespaceSelector prometheusCRConfig["probe_selector"] = taSpec.PrometheusCR.ProbeSelector - + prometheusCRConfig["probe_namespace_selector"] = taSpec.PrometheusCR.ProbeNamespaceSelector taConfig["prometheus_cr"] = prometheusCRConfig } diff --git a/internal/manifests/targetallocator/configmap_test.go b/internal/manifests/targetallocator/configmap_test.go index 7cd6318b25..11a9a7f61c 100644 --- a/internal/manifests/targetallocator/configmap_test.go +++ b/internal/manifests/targetallocator/configmap_test.go @@ -167,18 +167,22 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: matchlabels: release: my-instance matchexpressions: [] + probe_namespace_selector: null probe_selector: matchlabels: release: my-instance matchexpressions: [] + scrape_config_namespace_selector: null scrape_config_selector: matchlabels: release: my-instance matchexpressions: [] + service_monitor_namespace_selector: null service_monitor_selector: matchlabels: release: my-instance @@ -217,6 +221,89 @@ prometheus_cr: assert.Equal(t, expectedLabels, actual.Labels) assert.Equal(t, expectedData, actual.Data) + }) + t.Run("should return expected target allocator config map with namespace label selectors", func(t *testing.T) { + expectedData := map[string]string{ + targetAllocatorFilename: `allocation_strategy: consistent-hashing +collector_selector: + matchlabels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: default.my-instance + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + matchexpressions: [] +config: + global: + scrape_interval: 30s + scrape_protocols: + - PrometheusProto + - OpenMetricsText1.0.0 + - OpenMetricsText0.0.1 + - PrometheusText0.0.4 + scrape_configs: + - job_name: otel-collector + scrape_interval: 10s + static_configs: + - targets: + - 0.0.0.0:8888 + - 0.0.0.0:9999 +filter_strategy: relabel-config +prometheus_cr: + enabled: true + pod_monitor_namespace_selector: + matchlabels: + release: my-instance + matchexpressions: [] + pod_monitor_selector: null + probe_namespace_selector: + matchlabels: + release: my-instance + matchexpressions: [] + probe_selector: null + scrape_config_namespace_selector: + matchlabels: + release: my-instance + matchexpressions: [] + scrape_config_selector: null + service_monitor_namespace_selector: + matchlabels: + release: my-instance + matchexpressions: [] + service_monitor_selector: null +`, + } + targetAllocator = targetAllocatorInstance() + targetAllocator.Spec.PrometheusCR.Enabled = true + targetAllocator.Spec.PrometheusCR.PodMonitorNamespaceSelector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "release": "my-instance", + }, + } + targetAllocator.Spec.PrometheusCR.ServiceMonitorNamespaceSelector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "release": "my-instance", + }} + targetAllocator.Spec.PrometheusCR.ScrapeConfigNamespaceSelector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "release": "my-instance", + }} + targetAllocator.Spec.PrometheusCR.ProbeNamespaceSelector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "release": "my-instance", + }} + targetAllocator.Spec.GlobalConfig = v1beta1.AnyConfig{ + Object: map[string]interface{}{ + "scrape_interval": "30s", + "scrape_protocols": []string{"PrometheusProto", "OpenMetricsText1.0.0", "OpenMetricsText0.0.1", "PrometheusText0.0.4"}, + }, + } + params.TargetAllocator = targetAllocator + actual, err := ConfigMap(params) + assert.NoError(t, err) + assert.Equal(t, "my-instance-targetallocator", actual.Name) + assert.Equal(t, expectedLabels, actual.Labels) + assert.Equal(t, expectedData, actual.Data) + }) t.Run("should return expected target allocator config map with scrape interval set", func(t *testing.T) { expectedData := map[string]string{ @@ -239,10 +326,14 @@ config: filter_strategy: relabel-config prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, } @@ -302,10 +393,14 @@ https: tls_key_file_path: /tls/tls.key prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, } @@ -361,10 +456,14 @@ https: tls_key_file_path: /tls/tls.key prometheus_cr: enabled: true + pod_monitor_namespace_selector: null pod_monitor_selector: null + probe_namespace_selector: null probe_selector: null + scrape_config_namespace_selector: null scrape_config_selector: null scrape_interval: 30s + service_monitor_namespace_selector: null service_monitor_selector: null `, } diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml new file mode 100644 index 0000000000..2a4db9ff15 --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-assert.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +data: + targetallocator.yaml: + ( contains(@, join(':', ['service_monitor_namespace_selector', ' {}'])) ): true + ( contains(@, join(':', ['pod_monitor_namespace_selector', ' {}'])) ): true + ( contains(@, join(':', ['probe_namespace_selector', ' {}'])) ): true + ( contains(@, join(':', ['scrape_config_namespace_selector', '{}'])) ): true +kind: ConfigMap +metadata: + name: prometheus-cr-v1beta1-targetallocator \ No newline at end of file diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml new file mode 100644 index 0000000000..a4e2aca6d6 --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/03-install.yaml @@ -0,0 +1,29 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: prometheus-cr +spec: + config: | + receivers: + prometheus: + config: + scrape_configs: [] + + processors: + + exporters: + prometheus: + endpoint: 0.0.0.0:9090 + service: + pipelines: + metrics: + receivers: [prometheus] + exporters: [prometheus] + mode: statefulset + serviceAccount: collector + targetAllocator: + enabled: true + prometheusCR: + enabled: true + scrapeInterval: 1s + serviceAccount: ta