Skip to content

Commit 35d451f

Browse files
authored
docs(grafana-agent,ebpf): do not use undocumented features, used discovery.process (#2972)
1 parent ba9d6e7 commit 35d451f

File tree

7 files changed

+204
-13
lines changed

7 files changed

+204
-13
lines changed

docs/sources/configure-client/grafana-agent/ebpf/setup-linux.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,23 @@ We're [working on a more flexible configuration](https://github.com/grafana/agen
6262
Create a file named `agent.river` with the following content:
6363

6464
```river
65+
discovery.process "all" {
66+
67+
}
68+
69+
discovery.relabel "agent" {
70+
targets = discovery.process.all.targets
71+
// Filter needed processes
72+
rule {
73+
source_labels = ["__meta_process_exe"]
74+
regex = ".*/grafana-agent"
75+
action = "keep"
76+
}
77+
}
78+
6579
pyroscope.ebpf "instance" {
6680
forward_to = [pyroscope.write.endpoint.receiver]
67-
targets_only = false
68-
default_target = {"service_name" = "local"}
81+
targets = discovery.relabel.agent.targets
6982
}
7083
7184
pyroscope.scrape "local" {
@@ -124,3 +137,4 @@ To verify that the profiles are received by the Pyroscope server, go to the Pyro
124137
[pyroscope-ds]: /docs/grafana/latest/datasources/grafana-pyroscope/
125138
[config-reference]: ../configuration/
126139
[gcloud]: /products/cloud/
140+
[discovery.process](/docs/agent/next/flow/reference/components/discovery.process/)

examples/ebpf/config.river

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/ebpf/docker/config.river

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
discovery.docker "all" {
3+
host = "unix:///var/run/docker.sock"
4+
}
5+
6+
discovery.relabel "pyroscope" {
7+
targets = discovery.docker.all.targets
8+
// Filter needed containers based on docker labels
9+
// See more info at reference doc https://grafana.com/docs/agent/next/flow/reference/components/discovery.docker/
10+
rule {
11+
source_labels = ["__meta_docker_container_name"]
12+
regex = ".*pyroscope.*"
13+
action = "keep"
14+
}
15+
// provide arbitrary service_name label, otherwise it will default to value of __meta_docker_container_name
16+
rule {
17+
source_labels = ["__meta_docker_container_name"]
18+
regex = ".*pyroscope.*"
19+
action = "replace"
20+
target_label = "service_name"
21+
replacement = "ebpf/docker/pyroscope"
22+
}
23+
}
24+
25+
26+
pyroscope.ebpf "instance" {
27+
forward_to = [pyroscope.write.endpoint.receiver]
28+
targets = discovery.relabel.pyroscope.output
29+
}
30+
31+
pyroscope.write "endpoint" {
32+
endpoint {
33+
url = "http://pyroscope:4040"
34+
// url = "<Grafana Cloud URL>"
35+
// basic_auth {
36+
// username = "<Grafana Cloud User>"
37+
// password = "<Grafana Cloud Password>"
38+
// }
39+
}
40+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
version: '3.9'
3+
services:
4+
pyroscope:
5+
image: grafana/pyroscope
6+
ports:
7+
- '4040:4040'
8+
9+
grafana-agent:
10+
image: 'grafana/agent:main'
11+
user: root
12+
privileged: true
13+
pid: 'host'
14+
environment:
15+
- AGENT_MODE=flow
16+
volumes:
17+
- '/var/run/docker.sock:/var/run/docker.sock'
18+
- ./config.river:/config.river
19+
ports:
20+
- '12345:12345'
21+
command:
22+
- 'run'
23+
- '/config.river'
24+
- '--storage.path=/tmp/agent'
25+
- '--server.http.listen-addr=0.0.0.0:12345'

examples/ebpf/k8s/config.river

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// This is an example grafana agent config to set up eBPF profiling in kubernetes.
2+
// for more info see https://grafana.com/docs/pyroscope/latest/configure-client/grafana-agent/ebpf/setup-kubernetes/
3+
4+
discovery.kubernetes "local_pods" {
5+
selectors {
6+
field = "spec.nodeName=" + env("HOSTNAME") // Note: this assume HOSTNAME is set to the node name
7+
role = "pod"
8+
}
9+
role = "pod"
10+
}
11+
12+
discovery.relabel "specific_pods" {
13+
targets = discovery.kubernetes.all_pods.targets
14+
rule {
15+
action = "drop"
16+
regex = "Succeeded|Failed|Completed"
17+
source_labels = ["__meta_kubernetes_pod_phase"]
18+
}
19+
rule {
20+
action = "replace"
21+
source_labels = ["__meta_kubernetes_namespace"]
22+
target_label = "namespace"
23+
}
24+
rule {
25+
action = "replace"
26+
source_labels = ["__meta_kubernetes_pod_name"]
27+
target_label = "pod"
28+
}
29+
rule {
30+
action = "replace"
31+
source_labels = ["__meta_kubernetes_pod_node_name"]
32+
target_label = "node"
33+
}
34+
rule {
35+
action = "replace"
36+
source_labels = ["__meta_kubernetes_pod_container_name"]
37+
target_label = "container"
38+
}
39+
// provide arbitrary service_name label, otherwise it will be set to {__meta_kubernetes_namespace}/{__meta_kubernetes_pod_container_name}
40+
rule {
41+
action = "replace"
42+
regex = "(.*)@(.*)"
43+
replacement = "ebpf/k8s/${1}/${2}"
44+
separator = "@"
45+
source_labels = ["__meta_kubernetes_namespace", "__meta_kubernetes_pod_container_name"]
46+
target_label = "service_name"
47+
}
48+
// Filter specific targets to profile
49+
rule {
50+
source_labels = ["service_name"]
51+
regex = "(ebpf/grafana-agent/agent|ebpf/pyroscope/pyroscope)"
52+
action = "keep"
53+
}
54+
}
55+
56+
pyroscope.ebpf "instance" {
57+
forward_to = [pyroscope.write.endpoint.receiver]
58+
targets = discovery.relabel.specific_pods.targets
59+
}
60+
61+
pyroscope.write "endpoint" {
62+
url = "http://pyroscope:4040"
63+
// url = "<Grafana Cloud URL>"
64+
// basic_auth {
65+
// username = "<Grafana Cloud User>"
66+
// password = "<Grafana Cloud Password>"
67+
// }
68+
}

examples/ebpf/local/config.river

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
// discovery.process produces targets with the following labels:`
3+
// "__process_pid__"
4+
// "__meta_process_exe"
5+
// "__meta_process_cwd"
6+
// "__meta_process_commandline"
7+
// "__meta_process_username"
8+
// "__meta_process_uid"
9+
// "__container_id__"
10+
// See reference doc for more info https://grafana.com/docs/agent/next/flow/reference/components/discovery.process/
11+
12+
discovery.process "all" {
13+
14+
}
15+
16+
discovery.relabel "agent" {
17+
targets = discovery.process.all.targets
18+
// Filter needed processes
19+
rule {
20+
source_labels = ["__meta_process_exe"]
21+
regex = ".*/grafana-agent"
22+
action = "keep"
23+
}
24+
// provide arbitrary service_name label, otherwise it will be "unspecified"
25+
rule {
26+
source_labels = ["__meta_process_exe"]
27+
target_label = "service_name"
28+
regex = ".*/grafana-agent"
29+
action = "replace"
30+
replacement = "ebpf/local/grafana-agent"
31+
}
32+
}
33+
34+
35+
pyroscope.ebpf "instance" {
36+
forward_to = [pyroscope.write.endpoint.receiver]
37+
targets = concat(
38+
discovery.relabel.agent.output,
39+
[{"__process_pid__" = "1", "service_name" = "ebpf/local/init"}],
40+
)
41+
}
42+
43+
44+
pyroscope.write "endpoint" {
45+
endpoint {
46+
url = "http://pyroscope:4040"
47+
// url = "<Grafana Cloud URL>"
48+
// basic_auth {
49+
// username = "<Grafana Cloud User>"
50+
// password = "<Grafana Cloud Password>"
51+
// }
52+
}
53+
}
54+

examples/ebpf/docker-compose.yml renamed to examples/ebpf/local/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
- '4040:4040'
88

99
app:
10-
image: 'grafana/agent:latest'
10+
image: 'grafana/agent:main'
1111
user: root
1212
privileged: true
1313
pid: 'host'

0 commit comments

Comments
 (0)