Skip to content

Commit 83ac986

Browse files
committed
Refactor to two Alloy versions: cloud-stack and cloud-otlp
1 parent 0eeaa77 commit 83ac986

File tree

11 files changed

+89
-217
lines changed

11 files changed

+89
-217
lines changed
Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,85 @@
11

2-
// Enable this config by setting the env var ALLOY_FILE_NAME to cloud-otel.alloy for the docker-compose-cloud.yaml
3-
42
import.git "grafana_cloud" {
53
repository = "https://github.com/grafana/alloy-modules.git"
64
revision = "main"
75
path = "modules/cloud/grafana/cloud/module.alloy"
8-
pull_frequency = "24h"
6+
pull_frequency = "0s"
97
}
8+
109
grafana_cloud.stack "receivers" {
1110
stack_name = env("GRAFANA_CLOUD_STACK")
1211
token = env("GRAFANA_CLOUD_TOKEN")
1312
}
1413

15-
otelcol.auth.basic "grafana_cloud" {
16-
username = grafana_cloud.stack.receivers.info["htInstanceId"]
17-
password = env("GRAFANA_CLOUD_TOKEN")
18-
}
19-
20-
otelcol.exporter.otlphttp "grafana_cloud" {
21-
client {
22-
endpoint = grafana_cloud.stack.receivers.info["htInstanceUrl"] + ":443"
23-
auth = otelcol.auth.basic.grafana_cloud.handler
24-
}
25-
}
26-
27-
28-
discovery.docker "all_containers" {
14+
// discover containers running QuickPizza
15+
discovery.docker "application_containers" {
2916
host = "unix:///var/run/docker.sock"
17+
filter {
18+
name = "label"
19+
values = ["service.type=application"]
20+
}
3021
}
3122

32-
discovery.relabel "relabel_targets" {
23+
// set expected labels
24+
discovery.relabel "application_containers" {
25+
rule {
26+
target_label = "job"
27+
source_labels = [
28+
"__meta_docker_container_name",
29+
]
30+
regex = "/(.*)"
31+
replacement = "quickpizza/${1}"
32+
}
3333
rule {
3434
target_label = "instance"
3535
source_labels = [
3636
"__meta_docker_container_name",
3737
]
38-
regex ="/(.*)"
39-
action = "replace"
38+
regex = "/(.*)"
39+
replacement = "${1}"
4040
}
4141
rule {
42-
target_label = "job"
42+
target_label = "service_namespace"
43+
replacement = "quickpizza"
44+
}
45+
// the `namespace` label is for visualizing Profiles in Application Observability
46+
rule {
47+
target_label = "namespace"
48+
replacement = "quickpizza"
49+
}
50+
rule {
51+
target_label = "service_name"
4352
source_labels = [
44-
"__meta_docker_container_label_com_docker_compose_project",
53+
"__meta_docker_container_name",
4554
]
46-
regex = ".*quickpizza.*"
47-
action = "keep"
55+
regex = "/(.*)"
56+
replacement = "${1}"
4857
}
49-
targets = discovery.docker.all_containers.targets
58+
targets = discovery.docker.application_containers.targets
5059
}
5160

52-
5361
// Metrics
54-
prometheus.scrape "default" {
62+
prometheus.scrape "application_containers" {
63+
scrape_interval = "10s"
64+
targets = discovery.relabel.application_containers.output
5565
forward_to = [grafana_cloud.stack.receivers.metrics]
56-
targets = discovery.relabel.relabel_targets.output
5766
}
58-
59-
loki.source.docker "default" {
67+
// Logs
68+
loki.source.docker "application_containers" {
6069
host = "unix:///var/run/docker.sock"
61-
targets = discovery.relabel.relabel_targets.output
70+
targets = discovery.relabel.application_containers.output
6271
forward_to = [grafana_cloud.stack.receivers.logs]
63-
labels = {
64-
service_name = "quickpizza",
65-
service_namespace = "quickpizza",
66-
}
6772
}
6873

69-
pyroscope.scrape "scrape_profiles" {
74+
// Profiling Pull Mode
75+
pyroscope.scrape "application_containers" {
76+
// https://grafana.com/docs/pyroscope/latest/configure-client/grafana-alloy/go_pull/
77+
scrape_interval = "30s"
78+
targets = discovery.relabel.application_containers.output
7079
forward_to = [grafana_cloud.stack.receivers.profiles]
71-
targets = discovery.relabel.relabel_targets.output
72-
}
73-
74-
pyroscope.receive_http "default" {
75-
forward_to = [grafana_cloud.stack.receivers.profiles]
76-
http {
77-
listen_address = "0.0.0.0"
78-
listen_port = 9999
79-
}
8080
}
8181

82-
82+
// Traces
8383
otelcol.receiver.otlp "default" {
8484
// https://grafana.com/docs/alloy/latest/reference/components/otelcol.receiver.otlp/
8585

@@ -172,7 +172,6 @@ otelcol.processor.transform "drop_unneeded_resource_attributes" {
172172
otelcol.connector.host_info "default" {
173173
// https://grafana.com/docs/alloy/latest/reference/components/otelcol.connector.host_info/
174174
host_identifiers = ["container.name", "container.id", "service.name"]
175-
metrics_flush_interval = "10s"
176175

177176
output {
178177
metrics = [otelcol.processor.batch.default.input]
@@ -195,16 +194,26 @@ otelcol.processor.transform "add_resource_attributes_as_metric_attributes" {
195194
metrics = [otelcol.processor.batch.default.input]
196195
}
197196
}
198-
197+
199198
otelcol.processor.batch "default" {
200199
// https://grafana.com/docs/alloy/latest/reference/components/otelcol.processor.batch/
201200
output {
202201
metrics = [otelcol.exporter.otlphttp.grafana_cloud.input]
203202
logs = [otelcol.exporter.otlphttp.grafana_cloud.input]
204-
// traces = [otelcol.exporter.otlphttp.grafana_cloud.input]
205-
206-
//metrics = [grafana_cloud.stack.receivers.metrics]
207-
//logs = [grafana_cloud.stack.receivers.logs]
208-
traces = [grafana_cloud.stack.receivers.traces]
203+
traces = [otelcol.exporter.otlphttp.grafana_cloud.input]
209204
}
210205
}
206+
207+
otelcol.auth.basic "grafana_cloud" {
208+
// TODO: Fix info["htInstanceId"] not working, and need to pass GRAFANA_CLOUD_INSTANCE_ID.
209+
//username = grafana_cloud.stack.receivers.info["htInstanceId"]
210+
username = env("GRAFANA_CLOUD_INSTANCE_ID")
211+
password = env("GRAFANA_CLOUD_TOKEN")
212+
}
213+
214+
otelcol.exporter.otlphttp "grafana_cloud" {
215+
client {
216+
endpoint = env("GRAFANA_CLOUD_OTLP_ENDPOINT")
217+
auth = otelcol.auth.basic.grafana_cloud.handler
218+
}
219+
}

docker-compose-cloud.microservices.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ services:
2929
QUICKPIZZA_HOST: public-api:3333
3030
# must be set with an .env file
3131
GRAFANA_CLOUD_TOKEN: "${GRAFANA_CLOUD_TOKEN}"
32-
# must be set with an .env file
3332
GRAFANA_CLOUD_STACK: "${GRAFANA_CLOUD_STACK}"
33+
# set only when ALLOY_FILE_NAME=cloud-otlp-microservices.alloy
34+
GRAFANA_CLOUD_OTLP_ENDPOINT: "${GRAFANA_CLOUD_OTLP_ENDPOINT}"
35+
GRAFANA_CLOUD_INSTANCE_ID: "${GRAFANA_CLOUD_INSTANCE_ID}"
3436
depends_on:
3537
- catalog
3638
- config

kubernetes/cloud-otelcol/.env.local

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ GRAFANA_CLOUD_STACK=your-cloud-stack
66
# An Access Policy Token that includes the following scopes for the selected Grafana Cloud Stack: `stacks:read`, `metrics:write`, `logs:write`, `traces:write`, and `profiles:write`.
77
GRAFANA_CLOUD_TOKEN=your-cloud-token
88

9+
## Grafana Cloud OTLP Endpoint
10+
GRAFANA_CLOUD_OTLP_ENDPOINT=
11+
12+
# The Grafana Cloud OTLP endpoint for your stack, which can be found in the Grafana Cloud portal.
13+
GRAFANA_CLOUD_INSTANCE_ID=
14+
915

kubernetes/cloud-otelcol/config/config.alloy renamed to kubernetes/cloud-otlp/config/config.alloy

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ grafana_cloud.stack "receivers" {
1212
token = env("GRAFANA_CLOUD_TOKEN")
1313
}
1414

15-
otelcol.auth.basic "grafana_cloud" {
16-
username = grafana_cloud.stack.receivers.info["htInstanceId"]
17-
password = env("GRAFANA_CLOUD_TOKEN")
18-
}
19-
20-
otelcol.exporter.otlphttp "grafana_cloud" {
21-
client {
22-
endpoint = grafana_cloud.stack.receivers.info["htInstanceUrl"] + ":443"
23-
auth = otelcol.auth.basic.grafana_cloud.handler
24-
}
25-
}
2615

2716
// Metrics
2817
discovery.kubernetes "application_pods" {
@@ -191,9 +180,20 @@ otelcol.processor.batch "default" {
191180
output {
192181
metrics = [otelcol.exporter.otlphttp.grafana_cloud.input]
193182
logs = [otelcol.exporter.otlphttp.grafana_cloud.input]
194-
195-
// NOTE: Updated this from the initial implementation to send traces correctly
196-
//traces = [otelcol.exporter.otlphttp.grafana_cloud.input]
197-
traces = [grafana_cloud.stack.receivers.traces]
183+
traces = [otelcol.exporter.otlphttp.grafana_cloud.input]
184+
}
185+
}
186+
187+
otelcol.auth.basic "grafana_cloud" {
188+
// TODO: Fix info["htInstanceId"] not working, and need to pass GRAFANA_CLOUD_INSTANCE_ID.
189+
//username = grafana_cloud.stack.receivers.info["htInstanceId"]
190+
username = env("GRAFANA_CLOUD_INSTANCE_ID")
191+
password = env("GRAFANA_CLOUD_TOKEN")
192+
}
193+
194+
otelcol.exporter.otlphttp "grafana_cloud" {
195+
client {
196+
endpoint = env("GRAFANA_CLOUD_OTLP_ENDPOINT")
197+
auth = otelcol.auth.basic.grafana_cloud.handler
198198
}
199199
}

kubernetes/cloud-otelcol/kustomization.yaml renamed to kubernetes/cloud-otlp/kustomization.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ configMapGenerator:
2525
literals:
2626
# Enable tracing
2727
- QUICKPIZZA_OTLP_ENDPOINT=http://grafana-alloy:4318
28-
# TODO: pyroscope not working
29-
- QUICKPIZZA_PYROSCOPE_ENDPOINT=http://grafana-alloy:9999
3028
- name: alloy-config
3129
files:
3230
- ./config/config.alloy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ GRAFANA_CLOUD_STACK=your-cloud-stack
1313
GRAFANA_CLOUD_TOKEN=your-cloud-token
1414

1515

16+
1617
## QuickPizza Configuration
1718

1819
# FRONTEND OBSERVABILITY URL

kubernetes/cloud-dev/config/config.alloy renamed to kubernetes/cloud-stack/config/config.alloy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ grafana_cloud.stack "receivers" {
1010
token = env("GRAFANA_CLOUD_TOKEN")
1111
}
1212

13-
1413
discovery.kubernetes "application_pods" {
1514
selectors {
1615
label = "app.k8s.io/name=quickpizza"
@@ -83,6 +82,7 @@ pyroscope.scrape "application_pods" {
8382
forward_to = [grafana_cloud.stack.receivers.profiles]
8483
}
8584

85+
8686
// Traces
8787
otelcol.receiver.otlp "default" {
8888
grpc {
@@ -106,4 +106,4 @@ otelcol.processor.batch "default" {
106106
grafana_cloud.stack.receivers.traces,
107107
]
108108
}
109-
}
109+
}

kubernetes/cloud-telemetry/config/config.alloy

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

0 commit comments

Comments
 (0)