Skip to content

Commit aa2ae9d

Browse files
authored
Create the option for loading alloy modules embedded in the chart, rather than from git (#843)
Signed-off-by: Pete Wall <[email protected]>
1 parent 4e826a7 commit aa2ae9d

File tree

77 files changed

+22664
-975
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+22664
-975
lines changed

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ installing them for a better experience:
3131
- [helm-docs](https://github.com/norwoodj/helm-docs) - Used for generating Helm chart README.md files.
3232
- [helm unittest](https://github.com/helm-unittest/helm-unittest) - Used for executing Helm chart unit tests.
3333
- [shellspec](https://github.com/shellspec/shellspec) - Used for executing some unit tests.
34+
- [vendir](https://carvel.dev/vendir/) - Used for downloading Alloy Module
3435

3536
Each chart has a Makefile with targets to automate much of the process.
3637

charts/feature-annotation-autodiscovery/templates/_module.alloy.tpl

+2
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,5 @@ declare "annotation_autodiscovery" {
230230
}
231231
}
232232
{{- end -}}
233+
234+
{{- define "feature.annotationAutodiscovery.alloyModules" }}{{- end }}

charts/feature-application-observability/templates/_module.alloy.tpl

+2
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,5 @@ declare "application_observability" {
8282
{{- end }}
8383
}
8484
{{- end }}
85+
86+
{{- define "feature.applicationObservability.alloyModules" }}{{- end }}

charts/feature-cluster-events/templates/_module.alloy.tpl

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ declare "cluster_events" {
2020
forward_to = argument.logs_destinations.value
2121
}
2222
}
23-
{{- end -}}
23+
{{- end -}}
24+
25+
{{- define "feature.clusterEvents.alloyModules" }}{{- end }}

charts/feature-cluster-metrics/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ Actual integration testing in a live environment should be done in the main [k8s
214214

215215
| Key | Type | Default | Description |
216216
|-----|------|---------|-------------|
217+
| global.alloyModules.branch | string | `"main"` | If using git, the branch of the git repository to use. |
218+
| global.alloyModules.source | string | `"git"` | The source of the Alloy modules. The valid options are "configMap" or "git" |
217219
| global.maxCacheSize | int | `100000` | Sets the max_cache_size for every prometheus.relabel component. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.relabel/#arguments)) This should be at least 2x-5x your largest scrape target or samples appended rate. |
218220
| global.platform | string | `""` | The specific platform for this cluster. Will enable compatibility for some platforms. Supported options: (empty) or "openshift". |
219221
| global.scrapeInterval | string | `"60s"` | How frequently to scrape metrics. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{{/* Loads a module from Alloy Modules*/}}
2+
{{/* Inputs: . ($), name (string), path (string)*/}}
3+
{{- define "alloyModules.load" }}
4+
{{- if eq .Values.global.alloyModules.source "configMap" }}
5+
{{- $pathParts := regexSplit "/" .path -1 }}
6+
{{- $configMapName := printf "%s-alloy-module-%s" $.Release.Name (index $pathParts 1) }}
7+
{{- $moduleFile := (slice $pathParts 2) | join "_" }}
8+
remote.kubernetes.configmap {{ .name | quote }} {
9+
name = {{ $configMapName | quote }}
10+
namespace = {{ .Release.Namespace | quote }}
11+
}
12+
13+
import.string {{ .name | quote }} {
14+
content = remote.kubernetes.configmap.{{ .name }}.data[{{ $moduleFile | quote }}]
15+
}
16+
{{- else if eq .Values.global.alloyModules.source "git" }}
17+
import.git {{ .name | quote }} {
18+
repository = "https://github.com/grafana/alloy-modules.git"
19+
revision = "main"
20+
path = {{ .path | quote }}
21+
pull_frequency = "15m"
22+
}
23+
{{- end }}
24+
{{- end }}

charts/feature-cluster-metrics/templates/_kube_state_metrics.alloy.tpl

+1-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@
1111
{{- if (index .Values "kube-state-metrics").enabled }}
1212
{{- $metricAllowList := include "feature.clusterMetrics.kube_state_metrics.allowList" . }}
1313
{{- $metricDenyList := (index .Values "kube-state-metrics").metricsTuning.excludeMetrics }}
14-
15-
import.git "kube_state_metrics" {
16-
repository = "https://github.com/grafana/alloy-modules.git"
17-
revision = "main"
18-
path = "modules/kubernetes/kube-state-metrics/metrics.alloy"
19-
pull_frequency = "15m"
20-
}
14+
{{- include "alloyModules.load" (deepCopy $ | merge (dict "name" "kube_state_metrics" "path" "modules/kubernetes/kube-state-metrics/metrics.alloy")) | nindent 0 }}
2115

2216
kube_state_metrics.kubernetes "targets" {
2317
label_selectors = [

charts/feature-cluster-metrics/templates/_module.alloy.tpl

+14-7
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ declare "cluster_metrics" {
55
}
66

77
{{- if or .Values.cadvisor.enabled .Values.kubelet.enabled .Values.kubeletResource.enabled (or .Values.apiServer.enabled (and .Values.controlPlane.enabled (not (eq .Values.apiServer.enabled false)))) }}
8-
import.git "kubernetes" {
9-
repository = "https://github.com/grafana/alloy-modules.git"
10-
revision = "main"
11-
path = "modules/kubernetes/core/metrics.alloy"
12-
pull_frequency = "15m"
13-
}
8+
{{- include "alloyModules.load" (deepCopy $ | merge (dict "name" "kubernetes" "path" "modules/kubernetes/core/metrics.alloy")) | nindent 2 }}
149
{{- end }}
1510
{{- include "feature.clusterMetrics.kubelet.alloy" . | indent 2 }}
1611
{{- include "feature.clusterMetrics.kubeletResource.alloy" . | indent 2 }}
@@ -24,4 +19,16 @@ declare "cluster_metrics" {
2419
{{- include "feature.clusterMetrics.windows_exporter.alloy" . | indent 2 }}
2520
{{- include "feature.clusterMetrics.kepler.alloy" . | indent 2 }}
2621
}
27-
{{- end -}}
22+
{{- end -}}
23+
24+
{{- define "feature.clusterMetrics.alloyModules" }}
25+
{{- if or .Values.cadvisor.enabled .Values.kubelet.enabled .Values.kubeletResource.enabled (or .Values.apiServer.enabled (and .Values.controlPlane.enabled (not (eq .Values.apiServer.enabled false)))) }}
26+
- modules/kubernetes/core/metrics.alloy
27+
{{- end }}
28+
{{- if (index .Values "kube-state-metrics").enabled }}
29+
- modules/kubernetes/kube-state-metrics/metrics.alloy
30+
{{- end }}
31+
{{- if (index .Values "node-exporter").enabled }}
32+
- modules/system/node-exporter/metrics.alloy
33+
{{- end }}
34+
{{- end }}

charts/feature-cluster-metrics/templates/_node_exporter.alloy.tpl

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@
1414
{{- if (index .Values "node-exporter").enabled }}
1515
{{- $metricAllowList := include "feature.clusterMetrics.node_exporter.allowList" . }}
1616
{{- $metricDenyList := (index .Values "node-exporter").metricsTuning.excludeMetrics }}
17-
18-
import.git "node_exporter" {
19-
repository = "https://github.com/grafana/alloy-modules.git"
20-
revision = "main"
21-
path = "modules/system/node-exporter/metrics.alloy"
22-
pull_frequency = "15m"
23-
}
17+
{{- include "alloyModules.load" (deepCopy $ | merge (dict "name" "node_exporter" "path" "modules/system/node-exporter/metrics.alloy")) | nindent 0 }}
2418

2519
node_exporter.kubernetes "targets" {
2620
label_selectors = [

charts/feature-cluster-metrics/templates/_windows_exporter.alloy.tpl

+41-29
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,31 @@
1212

1313
{{- define "feature.clusterMetrics.windows_exporter.alloy" }}
1414
{{- if (index .Values "windows-exporter").enabled }}
15-
{{- $metricAllowList := include "feature.clusterMetrics.windows_exporter.allowList" . }}
15+
{{- $metricAllowList := include "feature.clusterMetrics.windows_exporter.allowList" . | fromYamlArray }}
1616
{{- $metricDenyList := (index .Values "windows-exporter").metricsTuning.excludeMetrics }}
17-
18-
import.git "windows_exporter" {
19-
repository = "https://github.com/grafana/alloy-modules.git"
20-
revision = "main"
21-
path = "modules/system/node-exporter/metrics.alloy"
22-
pull_frequency = "15m"
23-
}
24-
25-
windows_exporter.kubernetes "targets" {
26-
label_selectors = [
17+
{{- $labelSelectors := list }}
2718
{{- range $label, $value := (index .Values "windows-exporter").labelMatchers }}
28-
{{ printf "%s=%s" $label $value | quote }},
19+
{{- $labelSelectors = append $labelSelectors (printf "%s=%s" $label $value) }}
2920
{{- end }}
3021
{{- if (index .Values "windows-exporter").deploy }}
31-
{{ printf "release=%s" .Release.Name | quote }},
22+
{{- $labelSelectors = append $labelSelectors (printf "release=%s" .Release.Name) }}
23+
{{- end }}
24+
25+
discovery.kubernetes "windows_exporter_pods" {
26+
role = "pod"
27+
{{- if (index .Values "windows-exporter").deploy }}
28+
namespaces {
29+
names = [{{ .Release.Namespace | quote }}]
30+
}
3231
{{- end }}
33-
]
32+
selectors {
33+
role = "pod"
34+
label = {{ $labelSelectors | join "," | quote }}
35+
}
3436
}
3537

3638
discovery.relabel "windows_exporter" {
37-
targets = windows_exporter.kubernetes.targets.output
39+
targets = discovery.kubernetes.windows_exporter_pods.targets
3840
rule {
3941
source_labels = ["__meta_kubernetes_pod_node_name"]
4042
action = "replace"
@@ -45,26 +47,36 @@ discovery.relabel "windows_exporter" {
4547
{{- end }}
4648
}
4749

48-
windows_exporter.scrape "metrics" {
49-
targets = discovery.relabel.windows_exporter.output
50-
clustering = true
51-
{{- if $metricAllowList }}
52-
keep_metrics = "up|{{ $metricAllowList | fromYamlArray | join "|" }}"
53-
{{- end }}
54-
{{- if $metricDenyList }}
55-
drop_metrics = {{ $metricDenyList | join "|" | quote }}
56-
{{- end }}
50+
prometheus.scrape "windows_exporter" {
51+
job_name = "integrations/windows-exporter"
52+
targets = discovery.relabel.windows_exporter.output
5753
scrape_interval = {{ (index .Values "windows-exporter").scrapeInterval | default .Values.global.scrapeInterval | quote }}
58-
max_cache_size = {{ (index .Values "windows-exporter").maxCacheSize | default .Values.global.maxCacheSize | int }}
59-
{{- if (index .Values "windows-exporter").extraMetricProcessingRules }}
54+
clustering {
55+
enabled = true
56+
}
57+
{{- if or $metricAllowList $metricDenyList (index .Values "windows-exporter").extraMetricProcessingRules }}
6058
forward_to = [prometheus.relabel.windows_exporter.receiver]
6159
}
6260

6361
prometheus.relabel "windows_exporter" {
6462
max_cache_size = {{ (index .Values "windows-exporter").maxCacheSize | default .Values.global.maxCacheSize | int }}
65-
66-
{{(index .Values "windows-exporter").extraMetricProcessingRules}}
67-
63+
{{- if $metricAllowList }}
64+
rule {
65+
source_labels = ["__name__"]
66+
regex = "up|{{ $metricAllowList | join "|" }}"
67+
action = "keep"
68+
}
69+
{{- end }}
70+
{{- if $metricDenyList }}
71+
rule {
72+
source_labels = ["__name__"]
73+
regex = {{ $metricDenyList | join "|" | quote }}
74+
action = "drop"
75+
}
76+
{{- end }}
77+
{{- if (index .Values "windows-exporter").extraMetricProcessingRules }}
78+
{{ (index .Values "windows-exporter").extraMetricProcessingRules | indent 2 }}
79+
{{- end }}
6880
{{- end }}
6981
forward_to = argument.metrics_destinations.value
7082
}

0 commit comments

Comments
 (0)