diff --git a/.chloggen/scrape_config_probe.yaml b/.chloggen/scrape_config_probe.yaml new file mode 100755 index 0000000000..524fa01fb0 --- /dev/null +++ b/.chloggen/scrape_config_probe.yaml @@ -0,0 +1,16 @@ +# 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: collector + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: enables support for pulling scrape config and probe CRDs in the target allocator + +# One or more tracking issues related to the change +issues: [1842] + +# (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/apis/v1beta1/targetallocator_types.go b/apis/v1beta1/targetallocator_types.go index 5eceb5664e..ca9bc9aa0c 100644 --- a/apis/v1beta1/targetallocator_types.go +++ b/apis/v1beta1/targetallocator_types.go @@ -42,6 +42,18 @@ type TargetAllocatorPrometheusCR struct { // label selector matches no objects. // +optional ServiceMonitorSelector *metav1.LabelSelector `json:"serviceMonitorSelector,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"` + // 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"` } type ( diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go index b508f0be76..8d2402a809 100644 --- a/apis/v1beta1/zz_generated.deepcopy.go +++ b/apis/v1beta1/zz_generated.deepcopy.go @@ -787,6 +787,16 @@ func (in *TargetAllocatorPrometheusCR) DeepCopyInto(out *TargetAllocatorPromethe *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.ProbeSelector != nil { + in, out := &in.ProbeSelector, &out.ProbeSelector + *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 6ccb1c9e5f..8279c4550b 100644 --- a/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/community/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -7909,6 +7909,58 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeSelector: + 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: + 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 scrapeInterval: default: 30s format: duration diff --git a/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml index 6ccb1c9e5f..8279c4550b 100644 --- a/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/openshift/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -7909,6 +7909,58 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeSelector: + 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: + 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 scrapeInterval: default: 30s format: duration diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index fc36f4deb5..6a32030d4f 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -7895,6 +7895,58 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeSelector: + 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: + 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 scrapeInterval: default: 30s format: duration diff --git a/config/crd/bases/opentelemetry.io_targetallocators.yaml b/config/crd/bases/opentelemetry.io_targetallocators.yaml index 5ce85e459c..89c0c32134 100644 --- a/config/crd/bases/opentelemetry.io_targetallocators.yaml +++ b/config/crd/bases/opentelemetry.io_targetallocators.yaml @@ -2269,6 +2269,58 @@ spec: type: object type: object x-kubernetes-map-type: atomic + probeSelector: + 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: + 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 scrapeInterval: default: 30s format: duration diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 793bc217e2..053bf6966a 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -1513,6 +1513,8 @@ filter_strategy: relabel-config prometheus_cr: enabled: true pod_monitor_selector: null + probe_selector: null + scrape_config_selector: null service_monitor_selector: null `, }, @@ -1546,7 +1548,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "9d78d2ecfad18bad24dec7e9a825b4ce45657ecbb2e6b32845b585b7c15ea407", + "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", }, }, Spec: corev1.PodSpec{ @@ -1678,7 +1680,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "9d78d2ecfad18bad24dec7e9a825b4ce45657ecbb2e6b32845b585b7c15ea407", + "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -1970,6 +1972,8 @@ filter_strategy: relabel-config prometheus_cr: enabled: true pod_monitor_selector: null + probe_selector: null + scrape_config_selector: null service_monitor_selector: null `, }, @@ -2003,7 +2007,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "9d78d2ecfad18bad24dec7e9a825b4ce45657ecbb2e6b32845b585b7c15ea407", + "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", }, }, Spec: corev1.PodSpec{ @@ -2135,7 +2139,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "9d78d2ecfad18bad24dec7e9a825b4ce45657ecbb2e6b32845b585b7c15ea407", + "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -2472,6 +2476,8 @@ https: prometheus_cr: enabled: true pod_monitor_selector: null + probe_selector: null + scrape_config_selector: null service_monitor_selector: null `, }, @@ -2505,7 +2511,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f1ce0fdbf69924576576d1d6eb2a3cc91a3f72675b3facbb36702d57027bc6ae", + "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", }, }, Spec: corev1.PodSpec{ @@ -2663,7 +2669,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f1ce0fdbf69924576576d1d6eb2a3cc91a3f72675b3facbb36702d57027bc6ae", + "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -3539,6 +3545,8 @@ filter_strategy: relabel-config prometheus_cr: enabled: true pod_monitor_selector: null + probe_selector: null + scrape_config_selector: null service_monitor_selector: null `, }, @@ -3572,7 +3580,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "88ab06aab167d58ae2316ddecc9cf0600b9094d27054781dd6aa6e44dcf902fc", + "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", }, }, Spec: corev1.PodSpec{ @@ -3704,7 +3712,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "88ab06aab167d58ae2316ddecc9cf0600b9094d27054781dd6aa6e44dcf902fc", + "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -3812,6 +3820,8 @@ filter_strategy: relabel-config prometheus_cr: enabled: true pod_monitor_selector: null + probe_selector: null + scrape_config_selector: null service_monitor_selector: null `, }, @@ -3845,7 +3855,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "88ab06aab167d58ae2316ddecc9cf0600b9094d27054781dd6aa6e44dcf902fc", + "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", }, }, Spec: corev1.PodSpec{ @@ -3977,7 +3987,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "88ab06aab167d58ae2316ddecc9cf0600b9094d27054781dd6aa6e44dcf902fc", + "opentelemetry-targetallocator-config/hash": "f80c054419fe2f9030368557da143e200c70772d1d5f1be50ed55ae960b4b17d", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -4135,6 +4145,8 @@ filter_strategy: relabel-config prometheus_cr: enabled: true pod_monitor_selector: null + probe_selector: null + scrape_config_selector: null service_monitor_selector: null `, }, @@ -4168,7 +4180,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "9d78d2ecfad18bad24dec7e9a825b4ce45657ecbb2e6b32845b585b7c15ea407", + "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", }, }, Spec: corev1.PodSpec{ @@ -4300,7 +4312,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "9d78d2ecfad18bad24dec7e9a825b4ce45657ecbb2e6b32845b585b7c15ea407", + "opentelemetry-targetallocator-config/hash": "286a5a4e7ec6d2ce652a4ce23e135c10053b4c87fd080242daa5bf21dcd5a337", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ @@ -4432,6 +4444,8 @@ https: prometheus_cr: enabled: true pod_monitor_selector: null + probe_selector: null + scrape_config_selector: null service_monitor_selector: null `, }, @@ -4465,7 +4479,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f1ce0fdbf69924576576d1d6eb2a3cc91a3f72675b3facbb36702d57027bc6ae", + "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", }, }, Spec: corev1.PodSpec{ @@ -4623,7 +4637,7 @@ prometheus_cr: "app.kubernetes.io/version": "latest", }, Annotations: map[string]string{ - "opentelemetry-targetallocator-config/hash": "f1ce0fdbf69924576576d1d6eb2a3cc91a3f72675b3facbb36702d57027bc6ae", + "opentelemetry-targetallocator-config/hash": "3e2818ab54d866289de7837779e86e9c95803c43c0c4b58b25123e809ae9b771", }, }, Spec: policyV1.PodDisruptionBudgetSpec{ diff --git a/docs/api.md b/docs/api.md index 9601cca2fd..5a15a4c945 100644 --- a/docs/api.md +++ b/docs/api.md @@ -48094,6 +48094,26 @@ All CR instances which the ServiceAccount has access to will be retrieved. This PodMonitors 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.
+ + false + + probeSelector + object + + 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.
+ + false + + scrapeConfigSelector + object + + 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.
false @@ -48168,6 +48188,176 @@ 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.probeSelector +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) + + + +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. + + + + + + + + + + + + + + + + + + + + + +
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.probeSelector.matchExpressions[index] +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscrprobeselector) + + + +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.scrapeConfigSelector +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscr-1) + + + +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. + + + + + + + + + + + + + + + + + + + + + +
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.scrapeConfigSelector.matchExpressions[index] +[↩ Parent](#opentelemetrycollectorspectargetallocatorprometheuscrscrapeconfigselector) + + + A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. diff --git a/hack/install-targetallocator-prometheus-crds.sh b/hack/install-targetallocator-prometheus-crds.sh index a905925eb0..1e0ad04d8f 100755 --- a/hack/install-targetallocator-prometheus-crds.sh +++ b/hack/install-targetallocator-prometheus-crds.sh @@ -5,4 +5,6 @@ if [[ "$(kubectl api-resources --api-group=monitoring.coreos.com -o name)" ]]; t else kubectl create -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml kubectl create -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml + kubectl create -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/example/prometheus-operator-crd/monitoring.coreos.com_scrapeconfigs.yaml + kubectl create -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/example/prometheus-operator-crd/monitoring.coreos.com_probes.yaml fi diff --git a/internal/manifests/targetallocator/configmap.go b/internal/manifests/targetallocator/configmap.go index 36defd088e..27eb606b47 100644 --- a/internal/manifests/targetallocator/configmap.go +++ b/internal/manifests/targetallocator/configmap.go @@ -109,6 +109,10 @@ func ConfigMap(params Params) (*corev1.ConfigMap, error) { prometheusCRConfig["pod_monitor_selector"] = taSpec.PrometheusCR.PodMonitorSelector + prometheusCRConfig["scrape_config_selector"] = taSpec.PrometheusCR.ScrapeConfigSelector + + prometheusCRConfig["probe_selector"] = taSpec.PrometheusCR.ProbeSelector + taConfig["prometheus_cr"] = prometheusCRConfig } diff --git a/internal/manifests/targetallocator/configmap_test.go b/internal/manifests/targetallocator/configmap_test.go index 967eef25e8..7cd6318b25 100644 --- a/internal/manifests/targetallocator/configmap_test.go +++ b/internal/manifests/targetallocator/configmap_test.go @@ -171,6 +171,14 @@ prometheus_cr: matchlabels: release: my-instance matchexpressions: [] + probe_selector: + matchlabels: + release: my-instance + matchexpressions: [] + scrape_config_selector: + matchlabels: + release: my-instance + matchexpressions: [] service_monitor_selector: matchlabels: release: my-instance @@ -188,6 +196,14 @@ prometheus_cr: MatchLabels: map[string]string{ "release": "my-instance", }} + targetAllocator.Spec.PrometheusCR.ScrapeConfigSelector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "release": "my-instance", + }} + targetAllocator.Spec.PrometheusCR.ProbeSelector = &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "release": "my-instance", + }} targetAllocator.Spec.GlobalConfig = v1beta1.AnyConfig{ Object: map[string]interface{}{ "scrape_interval": "30s", @@ -224,6 +240,8 @@ filter_strategy: relabel-config prometheus_cr: enabled: true pod_monitor_selector: null + probe_selector: null + scrape_config_selector: null scrape_interval: 30s service_monitor_selector: null `, @@ -285,6 +303,8 @@ https: prometheus_cr: enabled: true pod_monitor_selector: null + probe_selector: null + scrape_config_selector: null scrape_interval: 30s service_monitor_selector: null `, @@ -342,6 +362,8 @@ https: prometheus_cr: enabled: true pod_monitor_selector: null + probe_selector: null + scrape_config_selector: null scrape_interval: 30s service_monitor_selector: null `, diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/00-install.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/00-install.yaml index 201491ec56..2afb2b9fb3 100644 --- a/tests/e2e-targetallocator/targetallocator-prometheuscr/00-install.yaml +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/00-install.yaml @@ -60,6 +60,8 @@ rules: resources: - servicemonitors - podmonitors + - scrapeconfigs + - probes verbs: - get - watch diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/02-assert.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/02-assert.yaml new file mode 100644 index 0000000000..91f960eedb --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/02-assert.yaml @@ -0,0 +1,57 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: prometheus-cr-v1beta1-collector +status: + readyReplicas: 1 + replicas: 1 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: prometheus-cr-v1beta1-targetallocator +status: + observedGeneration: 1 + readyReplicas: 1 + replicas: 1 +--- +apiVersion: v1 +data: + targetallocator.yaml: + ( contains(@, join(':', ['service_monitor_selector', ' null'])) ): true + ( contains(@, join(':', ['pod_monitor_selector', ' null'])) ): true + ( contains(@, join(':', ['probe_selector', ' null'])) ): false + ( contains(@, join(':', ['scrape_config_selector', ' null'])) ): false + ( contains(@, join(':', ['matchlabels', ' {}}'])) ): false + ( contains(@, join(':', ['matchexpressions', ' {}}'])) ): false +kind: ConfigMap +metadata: + name: prometheus-cr-v1beta1-targetallocator +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: check-ta-scrape-config-v1beta1 +status: + succeeded: 1 +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: check-ta-jobs-scrape-configs-v1beta1 +status: + succeeded: 1 +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: check-ta-probe-config-v1beta1 +status: + succeeded: 1 +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: check-ta-jobs-probes-v1beta1 +status: + succeeded: 1 \ No newline at end of file diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/02-install.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/02-install.yaml new file mode 100644 index 0000000000..b9fcab2889 --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/02-install.yaml @@ -0,0 +1,133 @@ +--- +apiVersion: opentelemetry.io/v1beta1 +kind: OpenTelemetryCollector +metadata: + name: prometheus-cr-v1beta1 +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 + scrapeConfigSelector: {} + probeSelector: {} + serviceAccount: ta +--- +apiVersion: monitoring.coreos.com/v1alpha1 +kind: ScrapeConfig +metadata: + name: scrape-config-cr +spec: + kubernetesSDConfigs: + - role: Node +--- +apiVersion: monitoring.coreos.com/v1 +kind: Probe +metadata: + name: blackbox-exporter +spec: + jobName: http-get + interval: 60s + module: http_2xx + prober: + url: blackbox-exporter.monitoring-system.svc:19115 + scheme: http + path: /probe + targets: + staticConfig: + static: + - https://example.com +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: check-ta-scrape-config-v1beta1 +spec: + template: + metadata: + labels: + checker: "true" + spec: + restartPolicy: OnFailure + containers: + - name: check-metrics + image: curlimages/curl + args: + - /bin/sh + - -c + - curl -s http://prometheus-cr-v1beta1-targetallocator/scrape_configs | grep "scrape-config-cr" +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: check-ta-jobs-scrape-configs-v1beta1 +spec: + template: + metadata: + labels: + checker: "true" + spec: + restartPolicy: OnFailure + containers: + - name: check-metrics + image: curlimages/curl + args: + - /bin/sh + - -c + - curl -s http://prometheus-cr-v1beta1-targetallocator/jobs | grep "scrape-config-cr" +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: check-ta-probe-config-v1beta1 +spec: + template: + metadata: + labels: + checker: "true" + spec: + restartPolicy: OnFailure + containers: + - name: check-metrics + image: curlimages/curl + args: + - /bin/sh + - -c + - curl -s http://prometheus-cr-v1beta1-targetallocator/scrape_configs | grep "blackbox-exporter" +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: check-ta-jobs-probes-v1beta1 +spec: + template: + metadata: + labels: + checker: "true" + spec: + restartPolicy: OnFailure + containers: + - name: check-metrics + image: curlimages/curl + args: + - /bin/sh + - -c + - curl -s http://prometheus-cr-v1beta1-targetallocator/jobs | grep "blackbox-exporter" \ No newline at end of file diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/chainsaw-test.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/chainsaw-test.yaml index c361477488..2e10e2ca11 100755 --- a/tests/e2e-targetallocator/targetallocator-prometheuscr/chainsaw-test.yaml +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/chainsaw-test.yaml @@ -22,3 +22,12 @@ spec: file: 01-install.yaml - assert: file: 01-assert.yaml + - name: step-02 + try: + - apply: + file: 02-install.yaml + - assert: + file: 02-assert.yaml + catch: + - podLogs: + selector: checker=true