Skip to content

Commit 902617e

Browse files
authored
Test: query for $ and $$ label for CRs and external labels (#1050)
[comment]: # (Note that your PR title should follow the conventional commit format: https://conventionalcommits.org/en/v1.0.0/#summary) # PR Description Add to the query tests to check for $ and $$ labels on PodMonitor and ServiceMonitor and to check for external labels
1 parent 677596d commit 902617e

File tree

4 files changed

+114
-35
lines changed

4 files changed

+114
-35
lines changed

.pipelines/azure-pipeline-build.yml

+34-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ stages:
8484
WINDOWS_2019_BASE_IMAGE_VERSION=ltsc2019
8585
WINDOWS_2022_BASE_IMAGE_VERSION=ltsc2022
8686
87+
#Truncating this to 123 characters to add the conf prefix
88+
ARC_CONFORMANCE_TAG_SUFFIX=$(echo "${LINUX_IMAGE_TAG}" | cut -c1-123)
89+
ARC_CONFORMANCE_IMAGE_TAG=conf-$ARC_CONFORMANCE_TAG_SUFFIX
90+
8791
LINUX_FULL_IMAGE_NAME=$ACR_REGISTRY$ACR_REPOSITORY:$LINUX_IMAGE_TAG
8892
TARGET_ALLOCATOR_FULL_IMAGE_NAME=$ACR_REGISTRY$ACR_REPOSITORY:$TARGET_ALLOCATOR_IMAGE_TAG
8993
LINUX_CONFIG_READER_FULL_IMAGE_NAME=$ACR_REGISTRY$ACR_REPOSITORY:$LINUX_CONFIG_READER_IMAGE_TAG
@@ -95,6 +99,7 @@ stages:
9599
LINUX_REF_APP_PYTHON_FULL_IMAGE_NAME=$ACR_REGISTRY$ACR_REPOSITORY:$LINUX_REF_APP_PYTHON_IMAGE_TAG
96100
WINDOWS_REF_APP_GOLANG_FULL_IMAGE_NAME=$ACR_REGISTRY$ACR_REPOSITORY:$WIN_REF_APP_GOLANG_IMAGE_TAG
97101
WINDOWS_REF_APP_PYTHON_FULL_IMAGE_NAME=$ACR_REGISTRY$ACR_REPOSITORY:$WIN_REF_APP_PYTHON_IMAGE_TAG
102+
ARC_CONFORMANCE_FULL_IMAGE_NAME=$ACR_REGISTRY$ACR_REPOSITORY:$ARC_CONFORMANCE_IMAGE_TAG
98103
99104
echo "##vso[build.updatebuildnumber]$SEMVER"
100105
echo "##vso[task.setvariable variable=SEMVER;isOutput=true]$SEMVER"
@@ -116,6 +121,8 @@ stages:
116121
echo "##vso[task.setvariable variable=ARC_HELM_CHART_NAME;isOutput=true]$ARC_HELM_CHART_NAME"
117122
echo "##vso[task.setvariable variable=HELM_FULL_IMAGE_NAME;isOutput=true]$HELM_FULL_IMAGE_NAME"
118123
echo "##vso[task.setvariable variable=ARC_HELM_FULL_IMAGE_NAME;isOutput=true]$ARC_HELM_FULL_IMAGE_NAME"
124+
echo "##vso[task.setvariable variable=ARC_CONFORMANCE_FULL_IMAGE_NAME;isOutput=true]$ARC_CONFORMANCE_FULL_IMAGE_NAME"
125+
119126
displayName: 'Build: set image registry, repo, and tags'
120127
name: setup
121128
@@ -510,6 +517,31 @@ stages:
510517
displayName: "Download, install Oras and run oras attach"
511518
condition: succeeded()
512519
520+
- job: Arc_Conformace_Test_Image
521+
displayName: "Build: Arc Conformance Test Image"
522+
pool:
523+
name: Azure-Pipelines-CI-Test-EO
524+
dependsOn: Image_Tags_and_Ev2_Artifacts
525+
variables:
526+
skipComponentGovernanceDetection: true
527+
ARC_CONFORMANCE_FULL_IMAGE_NAME: $[ dependencies.Image_Tags_and_Ev2_Artifacts.outputs['setup.ARC_CONFORMANCE_FULL_IMAGE_NAME'] ]
528+
# This is necessary because of: https://github.com/moby/moby/issues/37965
529+
DOCKER_BUILDKIT: 1
530+
condition: and(succeeded(), and(eq(variables.IS_PR, false), eq(variables.IS_MAIN_BRANCH, true)))
531+
steps:
532+
- checkout: self
533+
persistCredentials: true
534+
- bash: |
535+
docker pull mcr.microsoft.com/azuremonitor/containerinsights/cidev/prometheus-collector/images:buildx-stable-1
536+
537+
docker buildx create --name dockerbuilder --driver docker-container --driver-opt image=mcr.microsoft.com/azuremonitor/containerinsights/cidev/prometheus-collector/images:buildx-stable-1 --use
538+
docker buildx inspect --bootstrap
539+
docker login containerinsightsprod.azurecr.io -u $(ACR_USERNAME) -p $(ACR_PASSWORD)
540+
docker buildx build . -f arc-conformance/Dockerfile -t $(ARC_CONFORMANCE_FULL_IMAGE_NAME) --push
541+
docker pull $(ARC_CONFORMANCE_FULL_IMAGE_NAME)
542+
workingDirectory: $(Build.SourcesDirectory)/otelcollector/test/
543+
displayName: "Build: build and push Arc conformance test image to dev ACR"
544+
513545
- job: SDL_Policheck_Scan
514546
displayName: "SDL: policheck scanning"
515547
pool:
@@ -1940,7 +1972,7 @@ stages:
19401972
kubectl apply -f ./testkube/testkube-test-crs-ci-dev-arc-wcus.yaml
19411973
kubectl apply -f ./test-cluster-yamls/configmaps/ama-metrics-prometheus-config-configmap.yaml
19421974
kubectl apply -f ./test-cluster-yamls/configmaps/ama-metrics-prometheus-config-node-configmap.yaml
1943-
kubectl apply -f ./test-cluster-yamls/configmaps/ama-metrics-prometheus-config-node-windows=configmap.yaml
1975+
kubectl apply -f ./test-cluster-yamls/configmaps/ama-metrics-prometheus-config-node-windows-configmap.yaml
19441976
kubectl apply -f ./test-cluster-yamls/configmaps/ama-metrics-settings-configmap.yaml
19451977
kubectl apply -f ./test-cluster-yamls/customresources/prometheus-reference-app.yaml
19461978
@@ -2191,7 +2223,7 @@ stages:
21912223
kubectl apply -f ./testkube/testkube-test-crs-ci-dev-aks-mac-eus.yaml
21922224
kubectl apply -f ./test-cluster-yamls/configmaps/ama-metrics-prometheus-config-configmap.yaml
21932225
kubectl apply -f ./test-cluster-yamls/configmaps/ama-metrics-prometheus-config-node-configmap.yaml
2194-
kubectl apply -f ./test-cluster-yamls/configmaps/ama-metrics-prometheus-config-node-windows=configmap.yaml
2226+
kubectl apply -f ./test-cluster-yamls/configmaps/ama-metrics-prometheus-config-node-windows-configmap.yaml
21952227
kubectl apply -f ./test-cluster-yamls/configmaps/ama-metrics-settings-configmap.yaml
21962228
kubectl apply -f ./test-cluster-yamls/customresources/prometheus-reference-app.yaml
21972229

otelcollector/test/ginkgo-e2e/querymetrics/query_metrics_test.go

+44-21
Original file line numberDiff line numberDiff line change
@@ -248,35 +248,58 @@ var _ = Describe("Query Metrics Test Suite", func() {
248248
)
249249

250250
DescribeTable("should return the expected labels for specified metrics in each job",
251-
func(job string, metric string, labels []string) {
252-
for _, label := range labels {
253-
query := fmt.Sprintf("%s{job=\"%s\"}", metric, job)
251+
func(job string, metric string, labels map[string]string) {
252+
query := fmt.Sprintf("%s{job=\"%s\"}", metric, job)
254253

255-
warnings, result, err := utils.InstantQuery(PrometheusQueryClient, query)
256-
Expect(err).NotTo(HaveOccurred())
257-
Expect(warnings).To(BeEmpty())
254+
warnings, result, err := utils.InstantQuery(PrometheusQueryClient, query)
255+
Expect(err).NotTo(HaveOccurred())
256+
Expect(warnings).To(BeEmpty())
258257

259-
vectorResult, ok := result.(model.Vector)
260-
Expect(ok).To(BeTrue(), "result should be of type model.Vector for metric %s", metric)
261-
Expect(vectorResult).NotTo(BeEmpty(), "Metric %s is missing", metric)
258+
vectorResult, ok := result.(model.Vector)
259+
Expect(ok).To(BeTrue(), "result should be of type model.Vector for metric %s", metric)
260+
Expect(vectorResult).NotTo(BeEmpty(), "Metric %s is missing", metric)
262261

263-
for _, sample := range vectorResult {
262+
for _, sample := range vectorResult {
263+
for label, expectedValue := range labels {
264264
val, ok := sample.Metric[model.LabelName(label)]
265-
Expect(ok).To(BeTrue(), fmt.Sprintf("Expected label %q not found in metric %q", label, metric))
266-
Expect(val).NotTo(BeEmpty(), fmt.Sprintf("Label %q is empty in metric %q", label, metric))
267-
Expect(sample.Value.String()).To(Equal("1"))
265+
Expect(ok).To(BeTrue(), fmt.Sprintf("Expected label %q not found in metric %q for the job %s", label, metric, job))
266+
Expect(string(val)).To(MatchRegexp(expectedValue), fmt.Sprintf("Label %q in metric %q for job %s has unexpected value: %s", label, metric, job, val))
268267
}
269268
}
270269
},
271-
Entry("Metric relabeling with dollar signs", "prometheus_ref_app", "up", []string{
272-
"double_dollar_sign",
273-
"single_dollar_sign",
270+
Entry("Relabeling with dollar signs", "prometheus_ref_app", "up", map[string]string{
271+
"double_dollar_sign": "prometheus-reference-app", // Legacy backwards compatibility for $$1 when single $ was not supported
272+
"single_dollar_sign": "prometheus-reference-app",
273+
}),
274+
Entry("Relabeling with $NODE_NAME and $NODE_IP", "node-configmap", "up", map[string]string{
275+
"node_name_single_dollar_sign": ".+", // Node Name and IP env var substitution is only for daemonset
276+
"node_ip_single_dollar_sign": "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}",
277+
"node_name_double_dollar_sign": ".+", // Legacy backwards compatibility for $$NODE_NAME when single $ was not supported
278+
"node_ip_double_dollar_sign": "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}", // Legacy backwards compatibility for $$NODE_IP when single $ was not supported
279+
}),
280+
Entry("Relabeling with dollar signs & external labels for PodMonitor", "default/referenceapp", "up", map[string]string{
281+
"double_dollar_sign": "\\$1", // PodMonitor does not have the legacy backwards compatibility for $$1
282+
"single_dollar_sign": "prometheus-reference-app", // $1 does work for PodMonitor
283+
"external_label_1": "external_label_value",
284+
"external_label_123": "external_label_value",
285+
}),
286+
Entry("Relabeling with dollar signs & external labels for ServiceMonitor", "prometheus-reference-service", "up", map[string]string{
287+
"double_dollar_sign": "\\$1", // ServiceMonitor does not have the legacy backwards compatibility for $$1
288+
"single_dollar_sign": "prometheus-reference-app", // $1 does work for ServiceMonitor
289+
"external_label_1": "external_label_value",
290+
"external_label_123": "external_label_value",
291+
}),
292+
Entry("External labels are applied from ReplicaSet Configmap", "prometheus_ref_app", "up", map[string]string{
293+
"external_label_1": "external_label_value",
294+
"external_label_123": "external_label_value",
295+
}),
296+
Entry("External labels are applied from DaemonSet Configmap", "node-configmap", "up", map[string]string{
297+
"external_label_1": "external_label_value",
298+
"external_label_123": "external_label_value",
274299
}),
275-
Entry("Metric relabeling with $NODE_NAME and $NODE_IP", "node-configmap", "up", []string{
276-
"node_name_single_dollar_sign",
277-
"node_ip_single_dollar_sign",
278-
"node_name_double_dollar_sign",
279-
"node_ip_double_dollar_sign",
300+
Entry("External labels are applied from Windows DaemonSet Configmap", "windows-node-configmap", "up", map[string]string{
301+
"external_label_1": "external_label_value",
302+
"external_label_123": "external_label_value",
280303
}),
281304
)
282305

otelcollector/test/test-cluster-yamls/configmaps/ama-metrics-prometheus-config-node-windows-configmap.yaml

+26-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,34 @@ kind: ConfigMap
22
apiVersion: v1
33
data:
44
prometheus-config: |-
5+
global:
6+
external_labels:
7+
external_label_1: "external_label_value"
8+
external_label_123: "external_label_value"
59
scrape_configs:
6-
- job_name: empty
10+
- job_name: windows-node-configmap
11+
scheme: https
12+
metrics_path: /metrics
13+
scrape_interval: 30s
14+
label_limit: 63
15+
label_name_length_limit: 511
16+
label_value_length_limit: 1023
17+
tls_config:
18+
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
19+
insecure_skip_verify: true
20+
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
21+
relabel_configs:
22+
- source_labels: [__metrics_path__]
23+
regex: (.*)
24+
target_label: metrics_path
25+
- source_labels: [__address__]
26+
replacement: '$NODE_NAME'
27+
target_label: instance
28+
- source_labels: [__address__]
29+
replacement: '$OS_TYPE'
30+
target_label: "kubernetes_io_os"
731
static_configs:
8-
- targets: []
32+
- targets: ['$NODE_IP:10250']
933
metadata:
1034
name: ama-metrics-prometheus-config-node-windows
1135
namespace: kube-system

otelcollector/test/test-cluster-yamls/customresources/prometheus-referernce-app.yaml otelcollector/test/test-cluster-yamls/customresources/prometheus-reference-app.yaml

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ spec:
1010
labelValueLengthLimit: 1023
1111
podMetricsEndpoints:
1212
- relabelings:
13-
- source_labels: [__meta_kubernetes_pod_label_app]
13+
- sourceLabels: [__meta_kubernetes_pod_label_app]
1414
action: replace
1515
regex: (.*)
1616
replacement: $$1
17-
target_label: double_dollar_sign
18-
- source_labels: [__meta_kubernetes_pod_label_app]
17+
targetLabel: double_dollar_sign
18+
- sourceLabels: [__meta_kubernetes_pod_label_app]
1919
action: replace
2020
regex: (.*)
2121
replacement: $1
22-
target_label: single_dollar_sign
23-
- metricRelabelings:
22+
targetLabel: single_dollar_sign
23+
metricRelabelings:
2424
- action: keep
2525
regex: up
2626
sourceLabels:
@@ -43,17 +43,17 @@ spec:
4343
# rest of the service monitor
4444
endpoints:
4545
- relabelings:
46-
- source_labels: [__meta_kubernetes_pod_label_app]
46+
- sourceLabels: [__meta_kubernetes_pod_label_app]
4747
action: replace
4848
regex: (.*)
4949
replacement: $$1
50-
target_label: double_dollar_sign
51-
- source_labels: [__meta_kubernetes_pod_label_app]
50+
targetLabel: double_dollar_sign
51+
- sourceLabels: [__meta_kubernetes_pod_label_app]
5252
action: replace
5353
regex: (.*)
5454
replacement: $1
55-
target_label: single_dollar_sign
56-
- metricRelabelings:
55+
targetLabel: single_dollar_sign
56+
metricRelabelings:
5757
- action: keep
5858
regex: up
5959
sourceLabels:

0 commit comments

Comments
 (0)