From 19720d88cdf651926167ade2f17140e653f8a820 Mon Sep 17 00:00:00 2001 From: qiyang Date: Mon, 18 Nov 2024 21:11:27 +0800 Subject: [PATCH] e2e test prometheus operator scrape config and probes Signed-off-by: qiyang --- ...install-targetallocator-prometheus-crds.sh | 2 + .../02-assert.yaml | 57 +++++++ .../02-install.yaml | 141 ++++++++++++++++++ .../chainsaw-test.yaml | 6 + 4 files changed, 206 insertions(+) create mode 100644 tests/e2e-targetallocator/targetallocator-prometheuscr/02-assert.yaml create mode 100644 tests/e2e-targetallocator/targetallocator-prometheuscr/02-install.yaml 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/tests/e2e-targetallocator/targetallocator-prometheuscr/02-assert.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/02-assert.yaml new file mode 100644 index 0000000000..9fb8738acc --- /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'])) ): true + ( 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..7c3e72c9f0 --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/02-install.yaml @@ -0,0 +1,141 @@ +--- +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: {} + 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-metrics-cr +spec: + template: + spec: + restartPolicy: OnFailure + containers: + - name: check-metrics + image: curlimages/curl + args: + - /bin/sh + - -c + - | + for i in $(seq 30); do + if curl -m 1 -s http://prometheus-cr-v1beta1-collector:9090/metrics | grep "otelcol"; then exit 0; fi + sleep 5 + done + exit 1 +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: check-ta-scrape-config-v1beta1 +spec: + template: + 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: + 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: + 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: + 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..28f94d2e33 100755 --- a/tests/e2e-targetallocator/targetallocator-prometheuscr/chainsaw-test.yaml +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/chainsaw-test.yaml @@ -22,3 +22,9 @@ spec: file: 01-install.yaml - assert: file: 01-assert.yaml + - name: step-02 + try: + - apply: + file: 02-install.yaml + - assert: + file: 02-assert.yaml