-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Support for Alloy Module Imports
Resolves #537
- Loading branch information
Showing
12 changed files
with
52,861 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
charts/k8s-monitoring/templates/alloy_config/_alloy-modules.alloy.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{{ define "alloy.config.alloyMetricModules" }} | ||
// Alloy Modules | ||
{{- $connections := .Values.metrics.alloyModules.connections }} | ||
{{- /* Determine the default connection */}} | ||
{{- $defaultConnection := dict }} | ||
{{- range $connections }} | ||
{{- if .default }} | ||
{{- $defaultConnection = . }} | ||
{{- end }} | ||
{{- end }} | ||
{{- $extraRelabelingRules := .Values.metrics.extraRelabelingRules | default "" }} | ||
{{- $extraMetricRelabelingRules := .Values.metrics.extraMetricRelabelingRules | default "" }} | ||
{{- $defaultMaxCacheSize := .Values.metrics.maxCacheSize }} | ||
{{- $defaultScrapeInterval := .Values.metrics.scrapeInterval }} | ||
{{- $clustering := .Values.alloy.alloy.clustering.enabled }} | ||
|
||
{{- range $module := .Values.metrics.alloyModules.modules }} | ||
{{- $moduleName := $module.alias }} | ||
{{- /* Find the connection for the module or use the default */}} | ||
{{- $moduleConnection := $defaultConnection }} | ||
{{- range $conn := $connections }} | ||
{{- if and $module.connection (eq $conn.alias $module.connection) }} | ||
{{- $moduleConnection = $conn }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
// {{ $moduleName }}: import the module | ||
import.git "module_{{ $moduleName }}" { | ||
repository = "{{ $moduleConnection.repository }}" | ||
revision = "{{ $moduleConnection.revision }}" | ||
path = "{{ $module.path }}" | ||
pull_frequency = "{{ $moduleConnection.pull_frequency }}" | ||
|
||
{{- with $moduleConnection.basic_auth }} | ||
basic_auth { | ||
{{ if .username }}username = "{{ .username }}"{{ end }} | ||
{{ if .password }}password = "{{ .password }}"{{ end }} | ||
{{ if .password_file }}password_file = "{{ .password_file }}"{{ end }} | ||
} | ||
{{- end }} | ||
|
||
{{- with $moduleConnection.ssh_key }} | ||
ssh_key { | ||
{{ if .username }}username = "{{ .username }}"{{ end }} | ||
{{ if .key }}key = "{{ .key }}"{{ end }} | ||
{{ if .key_file }}key_file = "{{ .key_file }}"{{ end }} | ||
{{ if .passphrase }}passphrase = "{{ .passphrase }}"{{ end }} | ||
} | ||
{{- end }} | ||
} | ||
|
||
// {{ $moduleName }}: call the targets component | ||
module_{{ $moduleName }}.kubernetes "targets" { | ||
{{- if $module.targets }} | ||
{{- range $key, $value := $module.targets }} | ||
{{ $key }} = {{ if kindIs "slice" $value }}[{{ range $index, $item := $value }}"{{ $item }}"{{ if lt $index (sub (len $value) 1) }}, {{ end }}{{ end }}]{{ else }}"{{ $value }}"{{ end }} | ||
{{- end }} | ||
{{- end }} | ||
} | ||
|
||
// {{ $moduleName }}: additional service discovery relabelings | ||
discovery.relabel "module_{{ $moduleName }}" { | ||
targets = module_{{ $moduleName }}.kubernetes.targets.output | ||
// global discovery relabelings | ||
{{- if $extraRelabelingRules }} | ||
{{ $extraRelabelingRules | indent 2 }} | ||
{{- end }} | ||
// {{ $moduleName }}: additional discovery relabelings | ||
{{- if $module.extraRelabelingRules }} | ||
{{ $module.extraRelabelingRules | indent 2 }} | ||
{{- end }} | ||
} | ||
|
||
// {{ $moduleName }}: call the scrape component | ||
module_{{ $moduleName }}.scrape "metrics" { | ||
targets = discovery.relabel.module_{{ $moduleName }}.output | ||
forward_to = [prometheus.relabel.module_{{ $moduleName }}.receiver] | ||
clustering = {{ $clustering }} | ||
scrape_interval = "{{ if and (hasKey $module "scrape") (hasKey $module.scrape "scrape_interval") }}{{ index $module.scrape "scrape_interval" }}{{- else }}{{ $defaultScrapeInterval }}{{- end }}" | ||
{{- if $module.scrape }} | ||
{{- range $key, $value := $module.scrape }} | ||
{{- if not (eq $key "scrape_interval") }} | ||
{{ $key }} = {{ if kindIs "slice" $value }}[{{ range $index, $item := $value }}"{{ $item }}"{{ if lt $index (sub (len $value) 1) }}, {{ end }}{{ end }}]{{ else }}"{{ $value }}"{{ end }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
} | ||
|
||
// {{ $moduleName }}: additional metric relabelings | ||
prometheus.relabel "module_{{ $moduleName }}" { | ||
max_cache_size = {{ if and (hasKey $module "scrape") (hasKey $module.scrape "max_cache_size") }}{{ index $module.scrape "max_cache_size" | int }}{{- else }}{{ $defaultMaxCacheSize | int }}{{- end }} | ||
// global metric relabelings | ||
{{- if $extraMetricRelabelingRules }} | ||
{{ $extraMetricRelabelingRules | indent 2 }} | ||
{{- end }} | ||
// additional {{ $moduleName }} module specific metric relabelings | ||
{{- if $module.extraMetricRelabelingRules }} | ||
{{ $module.extraMetricRelabelingRules | indent 2 }} | ||
{{- end }} | ||
forward_to = [prometheus.relabel.metrics_service.receiver] | ||
} | ||
{{- end }} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Alloy Modules | ||
|
||
This example shows a how to leverage the [Alloy Modules](https://github.com/grafana/alloy-modules) for collecting metrics. These modules are opinionated, where each module has at least the following two components defined: | ||
|
||
1. `kubernetes` Used to find targets in the cluster | ||
2. `scrape` Used to scrape the found targets. | ||
|
||
```yaml | ||
cluster: | ||
name: metric-module-imports | ||
|
||
externalServices: | ||
prometheus: | ||
host: https://prometheus.example.com | ||
basicAuth: | ||
username: 12345 | ||
password: "It's a secret to everyone" | ||
loki: | ||
host: https://loki.example.com | ||
basicAuth: | ||
username: 12345 | ||
password: "It's a secret to everyone" | ||
|
||
metrics: | ||
alloyModules: | ||
connections: | ||
- alias: grafana | ||
repository: https://github.com/grafana/alloy-modules.git | ||
revision: main | ||
pull_frequency: 15m | ||
default: true | ||
modules: | ||
- alias: memcached | ||
path: modules/databases/kv/memcached/metrics.alloy | ||
- alias: loki | ||
path: modules/databases/timeseries/loki/metrics.alloy | ||
- alias: mimir | ||
path: modules/databases/timeseries/mimir/metrics.alloy | ||
- alias: tempo | ||
path: modules/databases/timeseries/tempo/metrics.alloy | ||
- alias: grafana | ||
path: modules/ui/grafana/metrics.alloy | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.