Skip to content

Commit 628ae1f

Browse files
committed
Simple OTEL collector/prometheus stack for testing purposes
Signed-off-by: Christopher Petito <chrisjpetito@gmail.com>
1 parent b982833 commit 628ae1f

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

hack/otel/compose.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: cli-otel
2+
3+
services:
4+
5+
prometheus:
6+
image: prom/prometheus:latest
7+
command:
8+
- "--config.file=/etc/prometheus/prom.yaml"
9+
ports:
10+
# Publish the Prometheus frontend on localhost:9091
11+
- 9091:9090
12+
restart: always
13+
volumes:
14+
# Store Prometheus data in a volume:
15+
- prom_data:/prometheus
16+
# Mount the prom.yml config file
17+
- ./prom.yaml:/etc/prometheus/prom.yaml
18+
19+
aspire-dashboard:
20+
image: mcr.microsoft.com/dotnet/nightly/aspire-dashboard:8.0-preview
21+
ports:
22+
- 18888:18888
23+
environment:
24+
DOTNET_DASHBOARD_UNSECURED_ALLOW_ANONYMOUS: 'true'
25+
26+
otelcol:
27+
image: otel/opentelemetry-collector:latest
28+
restart: always
29+
depends_on:
30+
- prometheus
31+
- aspire-dashboard
32+
ports:
33+
- 4317:4317
34+
volumes:
35+
# Mount the otelcol.yml config file
36+
- ./otelcol.yaml:/etc/otelcol/config.yaml
37+
38+
volumes:
39+
prom_data:

hack/otel/otelcol.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Receive signals over gRPC and HTTP
2+
receivers:
3+
otlp:
4+
protocols:
5+
grpc:
6+
http:
7+
8+
# Establish an endpoint for Prometheus to scrape from
9+
exporters:
10+
prometheus:
11+
endpoint: "0.0.0.0:8889"
12+
otlp/aspire:
13+
endpoint: aspire-dashboard:18889
14+
tls::insecure: true
15+
16+
service:
17+
pipelines:
18+
metrics:
19+
receivers: [otlp]
20+
exporters: [prometheus, otlp/aspire]
21+

hack/otel/prom.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Configure Prometheus to scrape the OTel collector endpoint
2+
scrape_configs:
3+
- job_name: "otel-collector"
4+
scrape_interval: 1s
5+
static_configs:
6+
- targets: ["otelcol:8889"]

hack/otel/usage.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Sample stack for testing OTEL functionality with the CLI
2+
3+
To easily test the OTEL functionality present in the CLI, you can spin up a small demo compose stack that includes:
4+
- an OTEL collector container;
5+
- a Prometheus container;
6+
- an Aspire Dashboard container
7+
8+
The `hack/otel` directory contains the compose file with the services configured, along with 2 basic configuration files: one for the OTEL collector and one for Prometheus.
9+
10+
## How can I use it?
11+
12+
1) Start the compose stack by running `docker compose up -d` in the `hack/otel/` directory;
13+
2) Export the env var used to override the OTLP endpoint:
14+
`export DOCKER_CLI_OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317` (if running the CLI in a devcontainer or in other ways, you might have to change how you pass this env var);
15+
3) Run the CLI to send some metrics to the endpoint;
16+
4) Browse Prometheus at `http://localhost:9091/graph` or the Aspire Dashboard at `http://localhost:18888/metrics`;
17+
5) In Prometheus, query `command_time_milliseconds_total` to see some metrics. In Aspire, select the resource in the dropdown.
18+
19+
> **Note**: The precise steps may vary based on how you're working on the codebase (buiding a binary and executing natively, running/debugging in a devcontainer, running the normal CLI as usual, etc... )
20+
21+
## Cleanup?
22+
23+
Simply run `docker compose down` in the `hack/otel/` directory.
24+
25+
You can also run `unset DOCKER_CLI_OTEL_EXPORTER_OTLP_ENDPOINT` to get rid of the OTLP override from your environment.

0 commit comments

Comments
 (0)