Skip to content

Commit 239db7d

Browse files
committed
set up opentelemetry metrics
1 parent 5588409 commit 239db7d

27 files changed

+1155
-69
lines changed

Cargo.lock

Lines changed: 173 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ comrak = { version = "0.48.0", default-features = false }
4141
syntect = { version = "5.0.0", default-features = false, features = ["parsing", "html", "dump-load", "regex-onig"] }
4242
toml = "0.9.2"
4343
prometheus = { version = "0.14.0", default-features = false }
44+
opentelemetry = "0.31.0"
45+
opentelemetry-otlp = { version = "0.31.0", features = ["grpc-tonic", "metrics"] }
46+
opentelemetry-resource-detectors = "0.10.0"
47+
opentelemetry_sdk = { version = "0.31.0", features = ["rt-tokio"] }
4448
rustwide = { version = "0.20.0", features = ["unstable-toolchain-ci", "unstable"] }
4549
mime_guess = "2"
4650
zstd = "0.13.0"
@@ -123,6 +127,7 @@ rand = "0.9"
123127
mockito = "1.0.2"
124128
test-case = "3.0.0"
125129
tower = { version = "0.5.1", features = ["util"] }
130+
opentelemetry_sdk = { version = "0.31.0", features = ["rt-tokio", "testing"] }
126131
aws-smithy-types = "1.0.1"
127132
aws-smithy-runtime = {version = "1.0.1", features = ["client", "test-util"]}
128133
aws-smithy-http = "0.62.0"

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#
2323
# optional profile: `metrics`:
2424
# * `prometheus` -> configured prometheus instance
25+
# * `opentelemetry` -> a debug opentelemetry receiver
2526
#
2627
# optional profile: `full`: all of the above.
2728
#
@@ -296,6 +297,23 @@ services:
296297
- metrics
297298
- full
298299

300+
opentelemetry:
301+
build:
302+
context: ./dockerfiles
303+
dockerfile: ./Dockerfile-opentelemetry
304+
<<: *docker-cache
305+
ports:
306+
- "127.0.0.1:4317:4317"
307+
healthcheck:
308+
<<: *healthcheck-interval
309+
test: curl --silent --fail http://localhost:13133/health
310+
311+
profiles:
312+
# we rarely need to test with actual prometheus, so always running
313+
# it is a waste.
314+
- metrics
315+
- full
316+
299317
gui_tests:
300318
platform: "linux/amd64"
301319
build:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM otel/opentelemetry-collector-contrib:0.139.0 AS base
2+
COPY collector-config-dev.yaml /etc/otelcol-contrib/config.yaml
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
endpoint: 0.0.0.0:4317
6+
7+
exporters:
8+
debug:
9+
# the debug exporter will just print everything to the console
10+
verbosity: detailed
11+
12+
extensions:
13+
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/09d7cdeb075f51bf90a604c95b106521bba9962e/extension/healthcheckextension
14+
health_check:
15+
endpoint: "0.0.0.0:13133"
16+
17+
service:
18+
pipelines:
19+
traces:
20+
receivers: [otlp]
21+
processors: []
22+
exporters: [debug]
23+
metrics:
24+
receivers: [otlp]
25+
processors: []
26+
exporters: [debug]
27+
logs:
28+
receivers: [otlp]
29+
processors: []
30+
exporters: [debug]

src/bin/cratesfyi.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ use docs_rs::{
55
db::{self, CrateId, Overrides, ReleaseId, add_path_into_database, types::version::Version},
66
start_background_metrics_webserver, start_web_server,
77
utils::{
8-
ConfigName, get_config, get_crate_pattern_and_priority, list_crate_priorities,
9-
queue_builder, remove_crate_priority, set_config, set_crate_priority,
8+
ConfigName, daemon::start_background_service_metric_collector, get_config,
9+
get_crate_pattern_and_priority, list_crate_priorities, queue_builder,
10+
remove_crate_priority, set_config, set_crate_priority,
1011
},
1112
};
1213
use futures_util::StreamExt;
@@ -199,6 +200,10 @@ impl CommandLine {
199200
docs_rs::utils::daemon::start_background_queue_rebuild(&ctx)?;
200201
}
201202

203+
// When people run the services separately, we assume that we can collect service
204+
// metrics from the registry watcher, which should only run once, and all the time.
205+
start_background_service_metric_collector(&ctx)?;
206+
202207
start_background_metrics_webserver(Some(metric_server_socket_addr), &ctx)?;
203208

204209
ctx.runtime.block_on(async move {

0 commit comments

Comments
 (0)