Skip to content

Commit

Permalink
Fix the alloy integration and improve all integrations
Browse files Browse the repository at this point in the history
Signed-off-by: Pete Wall <pete.wall@grafana.com>
  • Loading branch information
petewall committed Nov 10, 2024
1 parent b09a319 commit b7b4a5a
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 36 deletions.
13 changes: 13 additions & 0 deletions charts/feature-integrations/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,16 @@ If release name contains chart name it will be used as a full name.
{{- define "pod_label" -}}
{{ printf "__meta_kubernetes_pod_label_%s" (include "escape_label" .) }}
{{- end }}

{{- define "english_list" }}
{{- if eq (len .) 0 }}
{{- else if eq (len .) 1 }}
{{- index . 0 }}
{{- else if eq (len .) 2 }}
{{- index . 0 }} and {{ index . 1 }}
{{- else }}
{{- $last := index . (sub (len .) 1) }}
{{- $rest := slice . 0 (sub (len .) 1) }}
{{- join ", " $rest }}, and {{ $last }}
{{- end }}
{{- end }}
39 changes: 23 additions & 16 deletions charts/feature-integrations/templates/_integration_alloy.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
{{- define "integrations.alloy.type.logs" }}false{{- end }}

{{/* Returns the allowed metrics */}}
{{/* Inputs: integration (Alloy integration definition) Files (Files object) */}}
{{/* Inputs: instance (Alloy integration instance) Files (Files object) */}}
{{- define "integrations.alloy.allowList" }}
{{- if .integration.metricsTuning.useDefaultAllowList }}
{{ "default-allow-lists/alloy.yaml" | .Files.Get }}
{{- end }}
{{- if .integration.metricsTuning.useIntegrationAllowList }}
{{ "default-allow-lists/alloy-integration.yaml" | .Files.Get }}
{{- end }}
{{- if .integration.metricsTuning.includeMetrics }}
{{ .integration.metricsTuning.includeMetrics | toYaml }}
{{- end }}
{{- end }}
{{- $allowList := list "up" }}
{{- if .instance.metricsTuning.useDefaultAllowList -}}
{{- $allowList = concat $allowList (.Files.Get "default-allow-lists/alloy.yaml" | fromYamlArray) -}}
{{- end -}}
{{- if .instance.metricsTuning.useIntegrationAllowList -}}
{{- $allowList = concat $allowList (.Files.Get "default-allow-lists/alloy-integration.yaml" | fromYamlArray) -}}
{{- end -}}
{{- if .instance.metricsTuning.includeMetrics -}}
{{- $allowList = concat $allowList .instance.metricsTuning.includeMetrics -}}
{{- end -}}
{{ $allowList | uniq | toYaml }}
{{- end -}}

{{/* Loads the Alloy module and instances */}}
{{/* Inputs: Values (all values), Files (Files object) */}}
Expand Down Expand Up @@ -175,14 +177,19 @@ declare "alloy_integration" {
optional = true
}

argument "clustering" {
comment = "Whether or not clustering should be enabled (default: false)"
optional = true
}

prometheus.scrape "alloy" {
job_name = "integrations/alloy"
forward_to = [prometheus.relabel.alloy.receiver]
targets = argument.targets.value
scrape_interval = coalesce(argument.scrape_interval.value, "60s")
clustering {
enabled = true
enabled = coalesce(argument.clustering.value, false)
}
}

Expand Down Expand Up @@ -272,7 +279,7 @@ declare "alloy_integration" {
}
}
{{- range $instance := $.Values.alloy.instances }}
{{- include "integrations.alloy.include.metrics" (deepCopy $ | merge (dict "integration" $instance)) | nindent 2 }}
{{- include "integrations.alloy.include.metrics" (deepCopy $ | merge (dict "instance" $instance)) | nindent 2 }}
{{- end }}
}
{{- end }}
Expand All @@ -281,8 +288,8 @@ 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 deepCopy .integration | merge $defaultValues }}
{{- $metricAllowList := include "integrations.alloy.allowList" (dict "integration" . "Files" $.Files) }}
{{- with $defaultValues | merge (deepCopy .instance) }}
{{- $metricAllowList := include "integrations.alloy.allowList" (dict "instance" . "Files" $.Files) | fromYamlArray }}
{{- $metricDenyList := .excludeMetrics }}
{{- $labelSelectors := list }}
{{- range $k, $v := .labelSelectors }}
Expand All @@ -298,7 +305,7 @@ alloy_integration_scrape {{ include "helper.alloy_name" .name | quote }} {
targets = alloy_integration_discovery.{{ include "helper.alloy_name" .name }}.output
clustering = true
{{- if $metricAllowList }}
keep_metrics = "up|{{ $metricAllowList | fromYamlArray | join "|" }}"
keep_metrics = {{ $metricAllowList | join "|" | quote }}
{{- end }}
{{- if $metricDenyList }}
drop_metrics = {{ $metricDenyList | join "|" | quote }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare "cert_manager_integration" {
{{- include "alloyModules.load" (deepCopy $ | merge (dict "name" "cert_manager" "path" "modules/kubernetes/cert-manager/metrics.alloy")) | nindent 2 }}

{{- range $instance := (index $.Values "cert-manager").instances }}
{{- include "integrations.cert-manager.include.metrics" (deepCopy $ | merge (dict "integration" $instance)) | nindent 2 }}
{{- include "integrations.cert-manager.include.metrics" (deepCopy $ | merge (dict "instance" $instance)) | nindent 2 }}
{{- end }}
}
{{- end }}
Expand All @@ -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 deepCopy .integration | merge $defaultValues }}
{{- with $defaultValues | merge (deepCopy .instance) }}
{{- $metricAllowList := .metricsTuning.includeMetrics }}
{{- $metricDenyList := .metricsTuning.excludeMetrics }}
{{- $labelSelectors := list }}
Expand Down Expand Up @@ -49,7 +49,7 @@ cert_manager.scrape {{ include "helper.alloy_name" .name | quote }} {
clustering = true
job_label = {{ .jobName | quote }}
{{- if $metricAllowList }}
keep_metrics = "up|{{ $metricAllowList | join "|" | join "|" }}"
keep_metrics = "up|{{ $metricAllowList | join "|" }}"
{{- end }}
{{- if $metricDenyList }}
drop_metrics = {{ $metricDenyList | join "|" | quote }}
Expand Down
4 changes: 2 additions & 2 deletions charts/feature-integrations/templates/_integration_etcd.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare "etcd_integration" {
{{- include "alloyModules.load" (deepCopy $ | merge (dict "name" "etcd" "path" "modules/databases/kv/etcd/metrics.alloy")) | nindent 2 }}

{{- range $instance := (index $.Values "etcd").instances }}
{{- include "integrations.etcd.include.metrics" (deepCopy $ | merge (dict "integration" $instance)) | nindent 2 }}
{{- include "integrations.etcd.include.metrics" (deepCopy $ | merge (dict "instance" $instance)) | nindent 2 }}
{{- end }}
}
{{- end }}
Expand All @@ -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 deepCopy .integration | merge $defaultValues }}
{{- with $defaultValues | merge (deepCopy .instance) }}
{{- $metricAllowList := .metricsTuning.includeMetrics }}
{{- $metricDenyList := .metricsTuning.excludeMetrics }}
{{- $labelSelectors := list }}
Expand Down
16 changes: 14 additions & 2 deletions charts/feature-integrations/templates/_notes.tpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
{{- define "feature.integrations.notes.deployments" }}{{- end }}

{{/* TODO: add details about the actual integrations */}}
{{- define "feature.integrations.notes.task" }}
Gather data from service integrations
{{- $sources := list }}
{{- if .Values.alloy.instances -}}{{- $sources = append $sources "Alloy" -}}{{- end -}}
{{- if (index .Values "cert-manager").instances -}}{{- $sources = append $sources "cert-manager" -}}{{- end -}}
{{- if .Values.etcd.instances -}}{{- $sources = append $sources "etcd" -}}{{- end -}}
{{- if .Values.mysql.instances -}}{{- $sources = append $sources "MySql" -}}{{- end -}}
{{- if $sources }}
Gather data from the {{ include "english_list" $sources }} {{ if eq (len $sources) 1 }}integration{{ else }}integrations{{ end }}.
{{- end }}
{{- end }}

{{- define "feature.integrations.notes.actions" }}{{- end }}

{{- define "feature.integrations.summary" -}}
{{- $sources := list }}
{{- if .Values.alloy.instances -}}{{- $sources = append $sources "alloy" -}}{{- end -}}
{{- if (index .Values "cert-manager").instances -}}{{- $sources = append $sources "cert-manager" -}}{{- end -}}
{{- if .Values.etcd.instances -}}{{- $sources = append $sources "etcd" -}}{{- end -}}
{{- if .Values.mysql.instances -}}{{- $sources = append $sources "mysql" -}}{{- end -}}
version: {{ .Chart.Version }}
sources: {{ $sources | join "," }}
{{- end }}
29 changes: 26 additions & 3 deletions charts/feature-integrations/tests/alloy_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ suite: Test Alloy integration
templates:
- configmap.yaml
tests:
- it: should create the alloy config
- it: should create the Alloy config
set:
deployAsConfigMap: true
alloy:
instances:
- name: alloy-metrics
labelSelectors:
app.kubernetes.io/name: alloy-metrics
asserts:
- isKind:
of: ConfigMap
Expand Down Expand Up @@ -172,14 +174,19 @@ tests:
optional = true
}
argument "clustering" {
comment = "Whether or not clustering should be enabled (default: false)"
optional = true
}
prometheus.scrape "alloy" {
job_name = "integrations/alloy"
forward_to = [prometheus.relabel.alloy.receiver]
targets = argument.targets.value
scrape_interval = coalesce(argument.scrape_interval.value, "60s")
clustering {
enabled = true
enabled = coalesce(argument.clustering.value, false)
}
}
Expand Down Expand Up @@ -272,7 +279,7 @@ tests:
alloy_integration_discovery "alloy_metrics" {
port_name = "http-metrics"
label_selectors = ["app.kubernetes.io/name=alloy"]
label_selectors = ["app.kubernetes.io/name=alloy-metrics"]
}
alloy_integration_scrape "alloy_metrics" {
Expand All @@ -284,3 +291,19 @@ tests:
forward_to = argument.metrics_destinations.value
}
}
- it: should create the Alloy config with the integration allow list
set:
deployAsConfigMap: true
alloy:
instances:
- name: alloy-metrics
metricsTuning:
useIntegrationAllowList: true
labelSelectors:
app.kubernetes.io/name: alloy-metrics
asserts:
- isKind:
of: ConfigMap
- matchRegex:
path: data["metrics.alloy"]
pattern: alloy_component_controller_running_components
2 changes: 1 addition & 1 deletion charts/k8s-monitoring/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ dependencies:
repository: https://grafana.github.io/helm-charts
version: 0.9.2
digest: sha256:f5738b270a715d0fd122f5db19a928aceb4470a21314366cd91b8535fbcdbbee
generated: "2024-11-10T13:09:21.587275-06:00"
generated: "2024-11-10T13:59:55.03445-06:00"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b7b4a5a

Please sign in to comment.