Skip to content

Commit

Permalink
Use mergeOverwrite which allows explicitly set false's to override tr…
Browse files Browse the repository at this point in the history
…ue's (#1155)

Signed-off-by: Pete Wall <[email protected]>
  • Loading branch information
petewall authored Jan 22, 2025
1 parent 6c1b8e7 commit 08caa5f
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ declare "alloy_integration" {
{{/* Inputs: integration (Alloy integration definition), Values (all values), Files (Files object) */}}
{{- define "integrations.alloy.include.metrics" }}
{{- $defaultValues := "integrations/alloy-values.yaml" | .Files.Get | fromYaml }}
{{- with $defaultValues | merge (deepCopy .instance) }}
{{- with mergeOverwrite $defaultValues (deepCopy .instance) }}
{{- $metricAllowList := include "integrations.alloy.allowList" (dict "instance" . "Files" $.Files) | fromYamlArray }}
{{- $metricDenyList := .metrics.tuning.excludeMetrics }}
{{- $labelSelectors := list }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ declare "cert_manager_integration" {
{{/* Inputs: integration (cert-manager integration definition), Values (all values), Files (Files object) */}}
{{- define "integrations.cert-manager.include.metrics" }}
{{- $defaultValues := "integrations/cert-manager-values.yaml" | .Files.Get | fromYaml }}
{{- with $defaultValues | merge (deepCopy .instance) }}
{{- with mergeOverwrite $defaultValues (deepCopy .instance) }}
{{- $metricAllowList := .metrics.tuning.includeMetrics }}
{{- $metricDenyList := .metrics.tuning.excludeMetrics }}
{{- $labelSelectors := list }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ declare "etcd_integration" {
{{/* Inputs: integration (etcd integration definition), Values (all values), Files (Files object) */}}
{{- define "integrations.etcd.include.metrics" }}
{{- $defaultValues := "integrations/etcd-values.yaml" | .Files.Get | fromYaml }}
{{- with $defaultValues | merge (deepCopy .instance) }}
{{- with mergeOverwrite $defaultValues (deepCopy .instance) }}
{{- $metricAllowList := .metrics.tuning.includeMetrics }}
{{- $metricDenyList := .metrics.tuning.excludeMetrics }}
{{- $labelSelectors := list }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{- define "integrations.grafana.logs.discoveryRules" }}
{{- $defaultValues := "integrations/grafana-values.yaml" | .Files.Get | fromYaml }}
{{- range $instance := $.Values.grafana.instances }}
{{- with $defaultValues | merge (deepCopy $instance) }}
{{- with mergeOverwrite $defaultValues (deepCopy $instance) }}
{{- if .logs.enabled }}
{{- $labelList := list }}
{{- $valueList := list }}
Expand Down Expand Up @@ -54,7 +54,7 @@ rule {
{{- $defaultValues := "integrations/grafana-values.yaml" | .Files.Get | fromYaml }}
// Integration: Loki
{{- range $instance := $.Values.grafana.instances }}
{{- with $defaultValues | merge (deepCopy $instance) }}
{{- with mergeOverwrite $defaultValues (deepCopy $instance) }}
{{- if .logs.enabled }}
stage.match {
{{- if $instance.namespaces }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ declare "grafana_integration" {
{{/* Inputs: integration (grafana integration definition), Values (all values), Files (Files object) */}}
{{- define "integrations.grafana.include.metrics" }}
{{- $defaultValues := "integrations/grafana-values.yaml" | .Files.Get | fromYaml }}
{{- with $defaultValues | merge (deepCopy .instance) }}
{{- with mergeOverwrite $defaultValues (deepCopy .instance) }}
{{- $metricAllowList := include "integrations.grafana.allowList" (dict "instance" . "Files" $.Files) | fromYamlArray }}
{{- $metricDenyList := .excludeMetrics }}
{{- $labelSelectors := list }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{- define "integrations.loki.logs.discoveryRules" }}
{{- $defaultValues := "integrations/loki-values.yaml" | .Files.Get | fromYaml }}
{{- range $instance := $.Values.loki.instances }}
{{- with $defaultValues | merge (deepCopy $instance) }}
{{- with mergeOverwrite $defaultValues (deepCopy $instance) }}
{{- if .logs.enabled }}
{{- $labelList := list }}
{{- $valueList := list }}
Expand Down Expand Up @@ -67,7 +67,7 @@ rule {
{{- $defaultValues := "integrations/loki-values.yaml" | .Files.Get | fromYaml }}
// Integration: Loki
{{- range $instance := $.Values.loki.instances }}
{{- with $defaultValues | merge (deepCopy $instance) }}
{{- with mergeOverwrite $defaultValues (deepCopy $instance) }}
{{- if .logs.enabled }}
stage.match {
{{- if $instance.namespaces }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ declare "loki_integration" {
{{/* Inputs: integration (loki integration definition), Values (all values), Files (Files object) */}}
{{- define "integrations.loki.include.metrics" }}
{{- $defaultValues := "integrations/loki-values.yaml" | .Files.Get | fromYaml }}
{{- with $defaultValues | merge (deepCopy .instance) }}
{{- with mergeOverwrite $defaultValues (deepCopy .instance) }}
{{- $metricAllowList := include "integrations.loki.allowList" (dict "instance" . "Files" $.Files) | fromYamlArray }}
{{- $metricDenyList := .metrics.tuning.excludeMetrics }}
{{- $labelSelectors := list }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare "mysql_integration" {

{{- define "integrations.mysql.include.metrics" }}
{{- $defaultValues := "integrations/mysql-values.yaml" | .Files.Get | fromYaml }}
{{- with merge .instance $defaultValues (dict "type" "integration.mysql") }}
{{- with mergeOverwrite $defaultValues .instance (dict "type" "integration.mysql") }}
{{- if eq (include "secrets.usesKubernetesSecret" .) "true" }}
{{- include "secret.alloy" (deepCopy $ | merge (dict "object" .)) | nindent 0 }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,21 @@ tests:
forward_to = argument.metrics_destinations.value
}
}
- it: can create Alloy config with a single allowed metric
set:
deployAsConfigMap: true
alloy:
instances:
- name: alloy-metrics
labelSelectors:
app.kubernetes.io/name: alloy-metrics
metrics:
tuning:
useDefaultAllowList: false
includeMetrics: ["example_metric"]
asserts:
- isKind:
of: ConfigMap
- matchRegex:
path: data["metrics.alloy"]
pattern: \s+keep_metrics \= "up\|scrape_samples_scraped\|example_metric"

0 comments on commit 08caa5f

Please sign in to comment.