Skip to content

Commit

Permalink
e2e test prometheus operator scrape config and probes
Browse files Browse the repository at this point in the history
Signed-off-by: qiyang <[email protected]>
  • Loading branch information
dominicqi committed Nov 22, 2024
1 parent d87da69 commit 19720d8
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hack/install-targetallocator-prometheus-crds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
141 changes: 141 additions & 0 deletions tests/e2e-targetallocator/targetallocator-prometheuscr/02-install.yaml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 19720d8

Please sign in to comment.