Skip to content

Commit

Permalink
Add unit tests for the new Grafana cloud validators. (#1204)
Browse files Browse the repository at this point in the history
utilize dig that handles undefined fields

Signed-off-by: Pete Wall <[email protected]>
  • Loading branch information
petewall authored Feb 4, 2025
1 parent 4acceba commit 5a5be35
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@

{{/* Check if OTLP destination using Grafana Cloud OTLP gateway has protocol set */}}
{{- if and (eq $destination.type "otlp") (ne $destination.protocol "http") (regexMatch "otlp-gateway-.+grafana\\.net" $destination.url) }}
{{ fail (printf "\nDestination #%d (%s) is using Grafana Cloud OTLP gateway but has incorrect protocol '%s', the gateway only supports 'http'.\nPlease set:\ndestinations:\n - name: %s\n type: otlp\n url: %s\n protocol: http" $i $destination.name ($destination.protocol | default "grpc (default)") $destination.name $destination.url) }}
{{ fail (printf "\nDestination #%d (%s) is using Grafana Cloud OTLP gateway but has incorrect protocol '%s'. The gateway requires 'http'.\nPlease set:\ndestinations:\n - name: %s\n type: otlp\n url: %s\n protocol: http" $i $destination.name ($destination.protocol | default "grpc (default)") $destination.name $destination.url) }}
{{- end }}

{{/* Check if OTLP destination using Grafana Cloud Tempo checks */}}
{{- if and (eq $destination.type "otlp") (regexMatch "tempo-.+grafana\\.net" $destination.url) }}
{{- if ne $destination.protocol "grpc" }}
{{ fail (printf "\nDestination #%d (%s) is using Grafana Cloud Traces but has incorrect protocol '%s', the Tempo only supports 'grpc'.\nPlease set:\ndestinations:\n - name: %s\n type: otlp\n url: %s\n protocol: grpc" $i $destination.name ($destination.protocol | default "grpc (default)") $destination.name $destination.url) }}
{{ fail (printf "\nDestination #%d (%s) is using Grafana Cloud Traces but has incorrect protocol '%s'. Grafana Cloud Traces requires 'grpc'.\nPlease set:\ndestinations:\n - name: %s\n type: otlp\n url: %s\n protocol: grpc" $i $destination.name ($destination.protocol | default "grpc (default)") $destination.name $destination.url) }}
{{- end }}
{{- if eq $destination.metrics.enabled "true" }}
{{ fail (printf "\nDestination #%d (%s) is using Grafana Cloud Traces but has metrics enabled, the Tempo only supports traces.\nPlease set:\ndestinations:\n - name: %s\n type: otlp\n url: %s\n metrics:\n enabled: false" $i $destination.name $destination.name $destination.url) }}
{{- if eq (dig "metrics" "enabled" true $destination) true }}
{{ fail (printf "\nDestination #%d (%s) is using Grafana Cloud Traces but has metrics enabled. Tempo only supports traces.\nPlease set:\ndestinations:\n - name: %s\n type: otlp\n url: %s\n metrics:\n enabled: false" $i $destination.name $destination.name $destination.url) }}
{{- end }}
{{- if eq $destination.logs.enabled "true" }}
{{ fail (printf "\nDestination #%d (%s) is using Grafana Cloud Traces but has logs enabled, the Tempo only supports traces.\nPlease set:\ndestinations:\n - name: %s\n type: otlp\n url: %s\n logs:\n enabled: false" $i $destination.name $destination.name $destination.url) }}
{{- if eq (dig "logs" "enabled" true $destination) true }}
{{ fail (printf "\nDestination #%d (%s) is using Grafana Cloud Traces but has logs enabled. Tempo only supports traces.\nPlease set:\ndestinations:\n - name: %s\n type: otlp\n url: %s\n logs:\n enabled: false" $i $destination.name $destination.name $destination.url) }}
{{- end }}
{{- if eq (dig "traces" "enabled" true $destination) false }}
{{ fail (printf "\nDestination #%d (%s) is using Grafana Cloud Traces but has traces disabled.\nPlease set:\ndestinations:\n - name: %s\n type: otlp\n url: %s\n traces:\n enabled: true" $i $destination.name $destination.name $destination.url) }}
{{- end }}
{{- end }}

Expand Down
116 changes: 116 additions & 0 deletions charts/k8s-monitoring/tests/destination_validations_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,119 @@ tests:
type: prometheus
asserts:
- notFailedTemplate: {}

- it: detects if you're using the Grafana Cloud OTLP endpoint with the wrong protocol
set:
cluster:
name: test-cluster
destinations:
- name: OTLP Endpoint
type: otlp
url: https://otlp-gateway-test.grafana.net
asserts:
- failedTemplate:
errorMessage: |-
execution error at (k8s-monitoring/templates/validations.yaml:5:4):
Destination #0 (OTLP Endpoint) is using Grafana Cloud OTLP gateway but has incorrect protocol 'grpc (default)'. The gateway requires 'http'.
Please set:
destinations:
- name: OTLP Endpoint
type: otlp
url: https://otlp-gateway-test.grafana.net
protocol: http
- it: detects if you're using Grafana Cloud Traces with the wrong protocol
set:
cluster:
name: test-cluster
destinations:
- name: Grafana Cloud Traces
type: otlp
url: https://tempo-test.grafana.net
protocol: http
asserts:
- failedTemplate:
errorMessage: |-
execution error at (k8s-monitoring/templates/validations.yaml:5:4):
Destination #0 (Grafana Cloud Traces) is using Grafana Cloud Traces but has incorrect protocol 'http'. Grafana Cloud Traces requires 'grpc'.
Please set:
destinations:
- name: Grafana Cloud Traces
type: otlp
url: https://tempo-test.grafana.net
protocol: grpc
- it: detects if metrics are enabled for Grafana Cloud Traces
set:
cluster:
name: test-cluster
destinations:
- name: Grafana Cloud Traces
type: otlp
url: https://tempo-test.grafana.net
protocol: grpc
metrics: {enabled: true}
logs: {enabled: false}
traces: {enabled: true}
asserts:
- failedTemplate:
errorMessage: |-
execution error at (k8s-monitoring/templates/validations.yaml:5:4):
Destination #0 (Grafana Cloud Traces) is using Grafana Cloud Traces but has metrics enabled. Tempo only supports traces.
Please set:
destinations:
- name: Grafana Cloud Traces
type: otlp
url: https://tempo-test.grafana.net
metrics:
enabled: false
- it: detects if logs are enabled for Grafana Cloud Traces
set:
cluster:
name: test-cluster
destinations:
- name: Grafana Cloud Traces
type: otlp
url: https://tempo-test.grafana.net
protocol: grpc
metrics: {enabled: false}
logs: {enabled: true}
traces: {enabled: true}
asserts:
- failedTemplate:
errorMessage: |-
execution error at (k8s-monitoring/templates/validations.yaml:5:4):
Destination #0 (Grafana Cloud Traces) is using Grafana Cloud Traces but has logs enabled. Tempo only supports traces.
Please set:
destinations:
- name: Grafana Cloud Traces
type: otlp
url: https://tempo-test.grafana.net
logs:
enabled: false
- it: detects if traces are disabled for Grafana Cloud Traces
set:
cluster:
name: test-cluster
destinations:
- name: Grafana Cloud Traces
type: otlp
url: https://tempo-test.grafana.net
protocol: grpc
metrics: {enabled: false}
logs: {enabled: false}
traces: {enabled: false}
asserts:
- failedTemplate:
errorMessage: |-
execution error at (k8s-monitoring/templates/validations.yaml:5:4):
Destination #0 (Grafana Cloud Traces) is using Grafana Cloud Traces but has traces disabled.
Please set:
destinations:
- name: Grafana Cloud Traces
type: otlp
url: https://tempo-test.grafana.net
traces:
enabled: true

0 comments on commit 5a5be35

Please sign in to comment.