New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
otel: simple OTEL collector/Prometheus stack for testing purposes #5026
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Sample stack for testing OTEL functionality with the CLI | ||
|
||
To 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? | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
Comment on lines
+34
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for this one (also not a blocker) |
||
|
||
volumes: | ||
prom_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker for this PR, but I know that bind-mounting files can sometimes be problematic, so looking if we could have a directory to mount (which contains the config-file). Looks like
/etc/prometheus
already has some files in the image though, so if we do, we probably should use a different location for the config-file (but good news is that we already define it as a custom location above, so ... could still be an option);The alternative could be to define it as a
config:
in the compose-file (but those are still implemented as bind-mounts in compose, so won't solve the "don't bind individual files" part)