Skip to content

Commit 6448765

Browse files
committed
Add auto-instrumentation feature, which uses Grafana Beyla
Signed-off-by: Pete Wall <[email protected]>
1 parent b9f8745 commit 6448765

File tree

91 files changed

+3636
-76
lines changed

Some content is hidden

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

91 files changed

+3636
-76
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
docs
2+
schema-mods
3+
tests
4+
Makefile
5+
README.md
6+
README.md.gotmpl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Update dependency "beyla" for Helm chart "feature-auto-instrumentation"
3+
sources:
4+
beyla:
5+
name: Get latest "beyla" Helm chart version
6+
kind: helmchart
7+
spec:
8+
name: beyla
9+
url: https://grafana.github.io/helm-charts
10+
versionfilter:
11+
kind: semver
12+
pattern: '*'
13+
conditions:
14+
beyla:
15+
name: Ensure Helm chart dependency "beyla" is specified
16+
kind: yaml
17+
spec:
18+
file: charts/feature-auto-instrumentation/Chart.yaml
19+
key: $.dependencies[0].name
20+
value: beyla
21+
disablesourceinput: true
22+
targets:
23+
beyla:
24+
name: Bump Helm chart dependency "beyla" for Helm chart "feature-auto-instrumentation"
25+
kind: helmchart
26+
spec:
27+
file: Chart.yaml
28+
key: $.dependencies[0].version
29+
name: charts/feature-auto-instrumentation
30+
versionincrement: none
31+
sourceid: beyla
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: beyla
3+
repository: https://grafana.github.io/helm-charts
4+
version: 1.4.11
5+
digest: sha256:9b033f8958e90acc3d4d51f14cadf332be42b9c83a62a1492d2db421f946c650
6+
generated: "2024-11-12T16:42:11.373589-07:00"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: v2
3+
name: k8s-monitoring-feature-auto-instrumentation
4+
description: Gathers telemetry data via automatic instrumentation
5+
icon: https://raw.githubusercontent.com/grafana/grafana/main/public/img/grafana_icon.svg
6+
sources:
7+
- https://github.com/grafana/k8s-monitoring-helm/tree/main/charts/feature-annotation-autodiscovery
8+
version: 1.0.0
9+
appVersion: 1.0.0
10+
maintainers:
11+
12+
name: petewall
13+
dependencies:
14+
- name: beyla
15+
version: 1.4.11
16+
repository: https://grafana.github.io/helm-charts
17+
condition: beyla.enabled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
HAS_HELM_DOCS := $(shell command -v helm-docs;)
2+
HAS_HELM_UNITTEST := $(shell helm plugin list | grep unittest 2> /dev/null)
3+
UPDATECLI_FILES := $(shell yq -e '.dependencies[] | select(.repository == "http*") | ".updatecli-" + .name + ".yaml"' Chart.yaml 2>/dev/null | sort | uniq)
4+
5+
.SECONDEXPANSION:
6+
README.md: values.yaml Chart.yaml $$(wildcard README.md.gotmpl)
7+
ifdef HAS_HELM_DOCS
8+
helm-docs
9+
else
10+
docker run --rm --volume "$(shell pwd):/helm-docs" -u $(shell id -u) jnorwood/helm-docs:latest
11+
endif
12+
13+
Chart.lock: Chart.yaml
14+
helm dependency update .
15+
@touch Chart.lock # Ensure the timestamp is updated
16+
17+
values.schema.json: values.yaml $$(wildcard schema-mods/*)
18+
../../scripts/schema-gen.sh .
19+
20+
.updatecli-%.yaml: Chart.yaml
21+
../../scripts/charts-to-updatecli.sh Chart.yaml
22+
23+
.PHONY: clean
24+
clean:
25+
rm -f README.md values.schema.json $(UPDATECLI_FILES)
26+
27+
.PHONY: build
28+
build: README.md Chart.lock values.schema.json $(UPDATECLI_FILES)
29+
30+
.PHONY: test
31+
test: build
32+
helm repo add grafana https://grafana.github.io/helm-charts
33+
34+
helm lint .
35+
ct lint --lint-conf ../../.configs/lintconf.yaml --helm-dependency-extra-args=--skip-refresh --charts .
36+
ifdef HAS_HELM_UNITTEST
37+
helm unittest .
38+
else
39+
docker run --rm --volume $(shell pwd):/apps helmunittest/helm-unittest .
40+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!--
2+
(NOTE: Do not edit README.md directly. It is a generated file!)
3+
( To make changes, please modify README.md.gotmpl and run `helm-docs`)
4+
-->
5+
6+
# k8s-monitoring-feature-auto-instrumentation
7+
8+
![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![AppVersion: 1.0.0](https://img.shields.io/badge/AppVersion-1.0.0-informational?style=flat-square)
9+
Gathers telemetry data via automatic instrumentation
10+
11+
The auto-instrumentation feature deploys Grafana Beyla to automatically instrument programs running on this cluster
12+
using eBPF.
13+
14+
## Testing
15+
16+
This chart contains unit tests to verify the generated configuration. A hidden value, `deployAsConfigMap`, will render
17+
the generated configuration into a ConfigMap object. This ConfigMap is not used during regular operation, but it is
18+
useful for showing the outcome of a given values file.
19+
20+
The unit tests use this to create an object with the configuration that can be asserted against. To run the tests, use
21+
`helm test`.
22+
23+
Actual integration testing in a live environment should be done in the main [k8s-monitoring](../k8s-monitoring) chart.
24+
25+
## Maintainers
26+
27+
| Name | Email | Url |
28+
| ---- | ------ | --- |
29+
| petewall | <[email protected]> | |
30+
<!-- markdownlint-disable no-bare-urls -->
31+
<!-- markdownlint-disable list-marker-space -->
32+
## Source Code
33+
34+
* <https://github.com/grafana/k8s-monitoring-helm/tree/main/charts/feature-annotation-autodiscovery>
35+
36+
## Requirements
37+
38+
| Repository | Name | Version |
39+
|------------|------|---------|
40+
| https://grafana.github.io/helm-charts | beyla | 1.4.11 |
41+
<!-- markdownlint-enable list-marker-space -->
42+
<!-- markdownlint-enable no-bare-urls -->
43+
<!-- markdownlint-disable no-space-in-emphasis -->
44+
## Values
45+
46+
### Beyla
47+
48+
| Key | Type | Default | Description |
49+
|-----|------|---------|-------------|
50+
| beyla.extraDiscoveryRules | string | `""` | Rule blocks to be added to the discovery.relabel component for Beyla. These relabeling rules are applied pre-scrape against the targets from service discovery. Before the scrape, any remaining target labels that start with __ (i.e. __meta_kubernetes*) are dropped. ([docs](https://grafana.com/docs/alloy/latest/reference/components/discovery.relabel/#rule-block)) |
51+
| beyla.extraMetricProcessingRules | string | `""` | Rule blocks to be added to the prometheus.relabel component for Beyla. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus.relabel/#rule-block)) These relabeling rules are applied post-scrape against the metrics returned from the scraped target, no __meta* labels are present. |
52+
| beyla.labelMatchers | object | `{"app.kubernetes.io/name":"beyla"}` | Label matchers used to select the Beyla pods for scraping metrics. |
53+
| beyla.maxCacheSize | string | 100000 | Sets the max_cache_size for the prometheus.relabel component for Beyla. This should be at least 2x-5x your largest scrape target or samples appended rate. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus.relabel/#arguments)) Overrides metrics.maxCacheSize |
54+
| beyla.metricsTuning.excludeMetrics | list | `[]` | Metrics to drop. Can use regular expressions. |
55+
| beyla.metricsTuning.includeMetrics | list | `[]` | Metrics to keep. Can use regular expressions. |
56+
| beyla.preset | string | `"application"` | The configuration preset to use. Valid options are "application" or "network". |
57+
| beyla.scrapeInterval | string | 60s | How frequently to scrape metrics from Beyla. Overrides metrics.scrapeInterval |
58+
| beyla.service | object | `{"targetPort":9090}` | The port number for the Beyla service. |
59+
60+
### General settings
61+
62+
| Key | Type | Default | Description |
63+
|-----|------|---------|-------------|
64+
| fullnameOverride | string | `""` | Full name override |
65+
| nameOverride | string | `""` | Name override |
66+
67+
### Global Settings
68+
69+
| Key | Type | Default | Description |
70+
|-----|------|---------|-------------|
71+
| global.maxCacheSize | int | `100000` | Sets the max_cache_size for every prometheus.relabel component. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus.relabel/#arguments)) This should be at least 2x-5x your largest scrape target or samples appended rate. |
72+
| global.scrapeInterval | string | `"60s"` | How frequently to scrape metrics. |
73+
<!-- markdownlint-enable no-space-in-emphasis -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!--
2+
(NOTE: Do not edit README.md directly. It is a generated file!)
3+
( To make changes, please modify README.md.gotmpl and run `helm-docs`)
4+
-->
5+
6+
{{ template "chart.header" . }}
7+
{{ template "chart.deprecationWarning" . }}
8+
{{ template "chart.badgesSection" . }}
9+
{{ template "chart.description" . }}
10+
{{ template "chart.homepageLine" . }}
11+
12+
The auto-instrumentation feature deploys Grafana Beyla to automatically instrument programs running on this cluster
13+
using eBPF.
14+
15+
## Testing
16+
17+
This chart contains unit tests to verify the generated configuration. A hidden value, `deployAsConfigMap`, will render
18+
the generated configuration into a ConfigMap object. This ConfigMap is not used during regular operation, but it is
19+
useful for showing the outcome of a given values file.
20+
21+
The unit tests use this to create an object with the configuration that can be asserted against. To run the tests, use
22+
`helm test`.
23+
24+
Actual integration testing in a live environment should be done in the main [k8s-monitoring](../k8s-monitoring) chart.
25+
26+
{{ template "chart.maintainersSection" . }}
27+
<!-- markdownlint-disable no-bare-urls -->
28+
<!-- markdownlint-disable list-marker-space -->
29+
{{ template "chart.sourcesSection" . }}
30+
31+
{{ template "chart.requirementsSection" . }}
32+
<!-- markdownlint-enable list-marker-space -->
33+
<!-- markdownlint-enable no-bare-urls -->
34+
<!-- markdownlint-disable no-space-in-emphasis -->
35+
{{ template "chart.valuesSection" . }}
36+
<!-- markdownlint-enable no-space-in-emphasis -->
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"properties": {
3+
"beyla": {"properties": {"preset": {"enum": ["application", "network"]}}}
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{/*
2+
Create a default fully qualified name.
3+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
4+
If release name contains chart name it will be used as a full name.
5+
*/}}
6+
{{- define "feature.autoInstrumentation.fullname" -}}
7+
{{- if .Values.fullnameOverride }}
8+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" | lower }}
9+
{{- else }}
10+
{{- $name := default .Chart.Name .Values.nameOverride | lower }}
11+
{{- if contains $name .Release.Name }}
12+
{{- .Release.Name | trunc 63 | trimSuffix "-" | lower }}
13+
{{- else }}
14+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" | lower }}
15+
{{- end }}
16+
{{- end }}
17+
{{- end }}
18+
19+
{{- define "escape_annotation" -}}
20+
{{ . | replace "-" "_" | replace "." "_" | replace "/" "_" }}
21+
{{- end }}
22+
23+
{{- define "pod_annotation" -}}
24+
{{ printf "__meta_kubernetes_pod_annotation_%s" (include "escape_annotation" .) }}
25+
{{- end }}
26+
27+
{{- define "service_annotation" -}}
28+
{{ printf "__meta_kubernetes_service_annotation_%s" (include "escape_annotation" .) }}
29+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{{- define "feature.autoInstrumentation.module" }}
2+
{{- $metricAllowList := .Values.beyla.metricsTuning.includeMetrics }}
3+
{{- $metricDenyList := .Values.beyla.metricsTuning.excludeMetrics }}
4+
{{- $labelSelectors := list }}
5+
{{- range $k, $v := .Values.beyla.labelMatchers }}
6+
{{- $labelSelectors = append $labelSelectors (printf "%s=%s" $k $v) }}
7+
{{- end }}
8+
declare "auto_instrumentation" {
9+
argument "metrics_destinations" {
10+
comment = "Must be a list of metric destinations where collected metrics should be forwarded to"
11+
}
12+
13+
discovery.kubernetes "beyla_pods" {
14+
role = "pod"
15+
namespaces {
16+
own_namespace = true
17+
}
18+
selectors {
19+
role = "pod"
20+
label = {{ $labelSelectors | join "," | quote }}
21+
}
22+
}
23+
24+
discovery.relabel "beyla_pods" {
25+
targets = discovery.kubernetes.beyla_pods.targets
26+
rule {
27+
source_labels = ["__meta_kubernetes_pod_node_name"]
28+
action = "replace"
29+
target_label = "instance"
30+
}
31+
32+
{{- if .Values.beyla.extraDiscoveryRules }}
33+
{{ .Values.beyla.extraDiscoveryRules | indent 4 }}
34+
{{- end }}
35+
}
36+
37+
prometheus.scrape "beyla_applications" {
38+
targets = discovery.relabel.beyla_pods.output
39+
honor_labels = true
40+
scrape_interval = {{ .Values.beyla.scrapeInterval | default .Values.global.scrapeInterval | quote }}
41+
clustering {
42+
enabled = true
43+
}
44+
{{- if or $metricAllowList $metricDenyList .Values.beyla.extraMetricProcessingRules }}
45+
forward_to = [prometheus.relabel.beyla.receiver]
46+
{{- else }}
47+
forward_to = argument.metrics_destinations.value
48+
{{- end }}
49+
}
50+
51+
prometheus.scrape "beyla_internal" {
52+
targets = discovery.relabel.beyla_pods.output
53+
metrics_path = "/internal/metrics"
54+
job_name = "integrations/beyla"
55+
honor_labels = true
56+
scrape_interval = {{ .Values.beyla.scrapeInterval | default .Values.global.scrapeInterval | quote }}
57+
clustering {
58+
enabled = true
59+
}
60+
{{- if or $metricAllowList $metricDenyList .Values.beyla.extraMetricProcessingRules }}
61+
forward_to = [prometheus.relabel.beyla.receiver]
62+
}
63+
64+
prometheus.relabel "beyla" {
65+
max_cache_size = {{ .Values.beyla.maxCacheSize | default .Values.global.maxCacheSize | int }}
66+
{{- if $metricAllowList }}
67+
rule {
68+
source_labels = ["__name__"]
69+
regex = "up|{{ $metricAllowList | join "|" }}"
70+
action = "keep"
71+
}
72+
{{- end }}
73+
{{- if $metricDenyList }}
74+
rule {
75+
source_labels = ["__name__"]
76+
regex = {{ $metricDenyList | join "|" | quote }}
77+
action = "drop"
78+
}
79+
{{- end }}
80+
{{- if .Values.beyla.extraMetricProcessingRules }}
81+
{{ .Values.beyla.extraMetricProcessingRules | indent 4 }}
82+
{{- end }}
83+
{{- end }}
84+
forward_to = argument.metrics_destinations.value
85+
}
86+
}
87+
{{- end -}}
88+
89+
{{- define "feature.autoInstrumentation.alloyModules" }}{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- define "feature.autoInstrumentation.notes.deployments" }}
2+
* Grafana Beyla (Daemonset)
3+
{{- end }}
4+
5+
{{- define "feature.autoInstrumentation.notes.task" }}
6+
Automatically instrument applications and services running in the cluster with Grafana Beyla
7+
{{- end }}
8+
9+
{{- define "feature.autoInstrumentation.notes.actions" }}{{- end }}
10+
11+
{{- define "feature.autoInstrumentation.summary" -}}
12+
version: {{ .Chart.Version }}
13+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{- if .Values.deployAsConfigMap }}
2+
---
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: {{ include "feature.autoInstrumentation.fullname" . }}
7+
namespace: {{ .Release.Namespace }}
8+
data:
9+
module.alloy: |-
10+
{{- include "feature.autoInstrumentation.module" . | indent 4 }}
11+
{{- end }}

charts/feature-auto-instrumentation/tests/__snapshot__/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)