Skip to content

Commit c2f6117

Browse files
committed
Refactor docker compose setups (monolithic vs microservices) and (cloud vs cloud.otlp)
1 parent 83ac986 commit c2f6117

8 files changed

+129
-232
lines changed

.env.local

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
PUBLIC_BACKEND_ENDPOINT=http://localhost:3333
2-
PUBLIC_BACKEND_WS_ENDPOINT=ws://localhost:3333
3-
4-
# Override the default Alloy configuration file used by docker-compose-local.yaml or docker-compose-cloud.yaml
1+
# Override the default Alloy configuration file used by docker compose files
52
# ALLOY_FILE_NAME=
63

74
# To use a custom localimage (e.g., locally built)
85
# Example: docker build -t local-quickpizza:latest .
96
# QUICKPIZZA_IMAGE=local-quickpizza:latest
107

11-
# docker-compose-cloud.yaml env variables
128
QUICKPIZZA_CONF_FARO_URL=GRAFANA_CLOUD_FARO_URL
139

1410
# https://github.com/grafana/alloy-modules/tree/main/modules/cloud/grafana/cloud

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,21 @@ The [docker-compose-local.yaml](./docker-compose-local.yaml) file is set up to r
109109

110110
Grafana Alloy collects traces, metrics, logs and profiling data from the QuickPizza app, forwarding them to the Tempo, Prometheus and Loki. Finally, you can visualize and correlate data stored in these containers with the locally running Grafana instance.
111111

112-
To start the local environment, use the following command:
112+
To start the local environment with the complete observability stack, use the following command:
113113

114114
```bash
115-
docker compose -f docker-compose-local.yaml up -d
115+
docker compose -f compose.grafana-local-stack.monolithic.yaml up -d
116116
```
117117

118+
This setup runs QuickPizza in monolithic mode, where all QuickPizza components run in a single instance.
119+
118120
Like before, QuickPizza is available at [localhost:3333](http://localhost:3333). It's time to discover some fancy pizzas!
119121

120122
Then, you can visit the Grafana instance running at [localhost:3000](http://localhost:3000) and use **Explore** or **Drilldown apps** to access QuickPizza data.
121123

122124
![Use Profiles Drilldown](./docs/images/drilldown-profiles.png)
123125

124-
To find the labels applied to the telemetry data, refer to [local.alloy](./alloy/local.alloy) and [docker-compose-local.yaml](./docker-compose-local.yaml).
126+
To find the labels applied to the telemetry data, refer to [local.alloy](./alloy/local.alloy) and [compose.grafana-local-stack.monolithic.yaml](./compose.grafana-local-stack.monolithic.yaml).
125127

126128
### Send k6 Test Results to Prometheus and visualize them in Grafana with prebuilt dashboards
127129

@@ -139,9 +141,9 @@ For detailed instructions about the different options of the k6 Prometheus outpu
139141

140142
## Run locally and observe with Grafana Cloud ☁📊
141143

142-
The [docker-compose-cloud.yaml](./docker-compose-cloud.yaml) file is set up to run the QuickPizza and Grafana Alloy containers.
144+
The [compose.grafana-cloud.microservices.yaml](./compose.grafana-cloud.microservices.yaml) file is set up to run QuickPizza in microservice mode with a Grafana Alloy instance.
143145

144-
In this setup, Grafana Alloy collects observability data from the QuickPizza app and forwards it to [Grafana Cloud](https://grafana.com/products/cloud/).
146+
In this setup, Grafana Alloy collects observability data from the QuickPizza microservices and forwards it to [Grafana Cloud](https://grafana.com/products/cloud/).
145147

146148
You will need the following settings:
147149

@@ -157,10 +159,10 @@ GRAFANA_CLOUD_STACK=
157159
GRAFANA_CLOUD_TOKEN=
158160
```
159161

160-
Finally, execute the Docker Compose command using the `docker-compose-cloud.yaml` file, just as in the local setup:
162+
Finally, execute the Docker Compose command using the `compose.grafana-cloud.microservices.yaml` file, just as in the local setup:
161163

162164
```bash
163-
docker compose -f docker-compose-cloud.yaml up -d
165+
docker compose -f compose.grafana-cloud.microservices.yaml up -d
164166
```
165167

166168
QuickPizza is available at [localhost:3333](http://localhost:3333). Click the `Pizza, Please!` button and discover some awesome pizzas!
@@ -171,7 +173,7 @@ Now, you can log in to [Grafana Cloud](https://grafana.com/products/cloud/) and
171173

172174
![Use Profiles Drilldown](./docs/images/grafana-cloud-drilldown-profiles.png)
173175

174-
To find the labels applied to the telemetry data, refer to [cloud.alloy](./alloy/cloud.alloy) and [docker-compose-cloud.yaml](./docker-compose-cloud.yaml) .
176+
To find the labels applied to the telemetry data, refer to [cloud.alloy](./alloy/cloud.alloy) and [compose.grafana-cloud.microservices.yaml](./compose.grafana-cloud.microservices.yaml) .
175177

176178
### Monitor QuickPizza with Grafana Cloud Application and Frontend Observability
177179

@@ -199,11 +201,11 @@ QUICKPIZZA_CONF_FARO_URL=
199201
QUICKPIZZA_CONF_FARO_APP_NAME=
200202
```
201203

202-
4. Restart the `docker-compose-cloud.yaml` environment:
204+
4. Restart the `compose.grafana-cloud.microservices.yaml` environment:
203205

204206
```bash
205-
docker compose -f docker-compose-cloud.yaml down
206-
docker compose -f docker-compose-cloud.yaml up -d
207+
docker compose -f compose.grafana-cloud.microservices.yaml down
208+
docker compose -f compose.grafana-cloud.microservices.yaml up -d
207209
```
208210

209211
![Frontend Observability](./docs/images/grafana-cloud-frontend-observability-quickpizza.png)

alloy/cloud-microservices.alloy

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

alloy/cloud.alloy

Lines changed: 82 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,85 @@
1-
// Receive traces
1+
2+
import.git "grafana_cloud" {
3+
repository = "https://github.com/grafana/alloy-modules.git"
4+
revision = "main"
5+
path = "modules/cloud/grafana/cloud/module.alloy"
6+
pull_frequency = "0s"
7+
}
8+
9+
grafana_cloud.stack "receivers" {
10+
stack_name = env("GRAFANA_CLOUD_STACK")
11+
token = env("GRAFANA_CLOUD_TOKEN")
12+
}
13+
14+
// discover containers running QuickPizza
15+
discovery.docker "application_containers" {
16+
host = "unix:///var/run/docker.sock"
17+
filter {
18+
name = "label"
19+
values = ["service.type=application"]
20+
}
21+
}
22+
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+
}
33+
rule {
34+
target_label = "instance"
35+
source_labels = [
36+
"__meta_docker_container_name",
37+
]
38+
regex = "/(.*)"
39+
replacement = "${1}"
40+
}
41+
rule {
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"
52+
source_labels = [
53+
"__meta_docker_container_name",
54+
]
55+
regex = "/(.*)"
56+
replacement = "${1}"
57+
}
58+
targets = discovery.docker.application_containers.targets
59+
}
60+
61+
// Metrics
62+
prometheus.scrape "application_containers" {
63+
scrape_interval = "10s"
64+
targets = discovery.relabel.application_containers.output
65+
forward_to = [grafana_cloud.stack.receivers.metrics]
66+
}
67+
// Logs
68+
loki.source.docker "application_containers" {
69+
host = "unix:///var/run/docker.sock"
70+
targets = discovery.relabel.application_containers.output
71+
forward_to = [grafana_cloud.stack.receivers.logs]
72+
}
73+
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
79+
forward_to = [grafana_cloud.stack.receivers.profiles]
80+
}
81+
82+
// Traces
283
otelcol.receiver.otlp "default" {
384
grpc {
485
endpoint = "0.0.0.0:4317"
@@ -29,80 +110,8 @@ otelcol.exporter.prometheus "otlp_metrics" {
29110
grafana_cloud.stack.receivers.metrics,
30111
]
31112
}
32-
33113
otelcol.processor.batch "default" {
34114
output {
35115
traces = [grafana_cloud.stack.receivers.traces]
36116
}
37-
}
38-
39-
// Scrape Metrics
40-
prometheus.scrape "default" {
41-
forward_to = [
42-
grafana_cloud.stack.receivers.metrics,
43-
]
44-
targets = [
45-
{
46-
"__address__" = env("QUICKPIZZA_HOST"),
47-
"job" = "quickpizza",
48-
"instance" = "local",
49-
"service_name" = "quickpizza",
50-
"service_namespace" = "quickpizza",
51-
},
52-
]
53-
}
54-
55-
discovery.docker "all_containers" {
56-
host = "unix:///var/run/docker.sock"
57-
}
58-
59-
discovery.relabel "quickpizza" {
60-
rule {
61-
target_label = "instance"
62-
source_labels = [
63-
"__meta_docker_container_name",
64-
]
65-
regex ="/(.*)"
66-
action = "replace"
67-
}
68-
rule {
69-
target_label = "job"
70-
source_labels = [
71-
"__meta_docker_container_label_com_docker_compose_project",
72-
]
73-
regex = ".*quickpizza.*"
74-
action = "keep"
75-
}
76-
targets = discovery.docker.all_containers.targets
77-
}
78-
79-
loki.source.docker "default" {
80-
host = "unix:///var/run/docker.sock"
81-
targets = discovery.relabel.quickpizza.output
82-
forward_to = [grafana_cloud.stack.receivers.logs]
83-
labels = {
84-
service_name = "quickpizza",
85-
service_namespace = "quickpizza",
86-
}
87-
}
88-
89-
import.git "grafana_cloud" {
90-
repository = "https://github.com/grafana/alloy-modules.git"
91-
revision = "main"
92-
path = "modules/cloud/grafana/cloud/module.alloy"
93-
pull_frequency = "0s"
94-
}
95-
96-
// Receive profiling data
97-
pyroscope.receive_http "default" {
98-
http {
99-
listen_address = "0.0.0.0"
100-
listen_port = 9999
101-
}
102-
forward_to = [grafana_cloud.stack.receivers.profiles]
103-
}
104-
105-
grafana_cloud.stack "receivers" {
106-
stack_name = env("GRAFANA_CLOUD_STACK")
107-
token = env("GRAFANA_CLOUD_TOKEN")
108117
}

0 commit comments

Comments
 (0)