From 628ae1fb85ecd49fd9b08841c0177b3519b322e0 Mon Sep 17 00:00:00 2001 From: Christopher Petito Date: Fri, 19 Apr 2024 10:00:08 +0000 Subject: [PATCH] Simple OTEL collector/prometheus stack for testing purposes Signed-off-by: Christopher Petito --- hack/otel/compose.yaml | 39 +++++++++++++++++++++++++++++++++++++++ hack/otel/otelcol.yaml | 21 +++++++++++++++++++++ hack/otel/prom.yaml | 6 ++++++ hack/otel/usage.md | 25 +++++++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 hack/otel/compose.yaml create mode 100644 hack/otel/otelcol.yaml create mode 100644 hack/otel/prom.yaml create mode 100644 hack/otel/usage.md diff --git a/hack/otel/compose.yaml b/hack/otel/compose.yaml new file mode 100644 index 000000000000..15f2cd68075e --- /dev/null +++ b/hack/otel/compose.yaml @@ -0,0 +1,39 @@ +name: cli-otel + +services: + + prometheus: + image: prom/prometheus:latest + command: + - "--config.file=/etc/prometheus/prom.yaml" + ports: + # Publish the Prometheus frontend on localhost:9091 + - 9091:9090 + restart: always + volumes: + # Store Prometheus data in a volume: + - prom_data:/prometheus + # Mount the prom.yml config file + - ./prom.yaml:/etc/prometheus/prom.yaml + + aspire-dashboard: + image: mcr.microsoft.com/dotnet/nightly/aspire-dashboard:8.0-preview + ports: + - 18888:18888 + environment: + DOTNET_DASHBOARD_UNSECURED_ALLOW_ANONYMOUS: 'true' + + otelcol: + image: otel/opentelemetry-collector:latest + restart: always + depends_on: + - prometheus + - aspire-dashboard + ports: + - 4317:4317 + volumes: + # Mount the otelcol.yml config file + - ./otelcol.yaml:/etc/otelcol/config.yaml + +volumes: + prom_data: diff --git a/hack/otel/otelcol.yaml b/hack/otel/otelcol.yaml new file mode 100644 index 000000000000..ad0c3b3e49cc --- /dev/null +++ b/hack/otel/otelcol.yaml @@ -0,0 +1,21 @@ +# Receive signals over gRPC and HTTP +receivers: + otlp: + protocols: + grpc: + http: + +# Establish an endpoint for Prometheus to scrape from +exporters: + prometheus: + endpoint: "0.0.0.0:8889" + otlp/aspire: + endpoint: aspire-dashboard:18889 + tls::insecure: true + +service: + pipelines: + metrics: + receivers: [otlp] + exporters: [prometheus, otlp/aspire] + \ No newline at end of file diff --git a/hack/otel/prom.yaml b/hack/otel/prom.yaml new file mode 100644 index 000000000000..20166047ebb9 --- /dev/null +++ b/hack/otel/prom.yaml @@ -0,0 +1,6 @@ +# Configure Prometheus to scrape the OTel collector endpoint +scrape_configs: + - job_name: "otel-collector" + scrape_interval: 1s + static_configs: + - targets: ["otelcol:8889"] diff --git a/hack/otel/usage.md b/hack/otel/usage.md new file mode 100644 index 000000000000..f7843bb4fb4e --- /dev/null +++ b/hack/otel/usage.md @@ -0,0 +1,25 @@ +# Sample stack for testing OTEL functionality with the CLI + +To easily test the OTEL functionality present in the CLI, you can spin up a small demo compose stack that includes: +- an OTEL collector container; +- a Prometheus container; +- an Aspire Dashboard container + +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. + +## How can I use it? + +1) Start the compose stack by running `docker compose up -d` in the `hack/otel/` directory; +2) Export the env var used to override the OTLP endpoint: + `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); +3) Run the CLI to send some metrics to the endpoint; +4) Browse Prometheus at `http://localhost:9091/graph` or the Aspire Dashboard at `http://localhost:18888/metrics`; +5) In Prometheus, query `command_time_milliseconds_total` to see some metrics. In Aspire, select the resource in the dropdown. + +> **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... ) + +## Cleanup? + +Simply run `docker compose down` in the `hack/otel/` directory. + +You can also run `unset DOCKER_CLI_OTEL_EXPORTER_OTLP_ENDPOINT` to get rid of the OTLP override from your environment.