Skip to content

Commit 603e8e5

Browse files
committed
rename the metrics feature
Its dependencies are no longer implicit features
1 parent cbc9a17 commit 603e8e5

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

.github/workflows/docker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ jobs:
1818
features: ""
1919
image: ubuntu-latest
2020
- tag: metrics-amd64
21-
features: expose-metrics
21+
features: metrics
2222
image: ubuntu-latest
2323
- tag: armv8
2424
features: ""
2525
image: ubuntu-24.04-arm
2626
- tag: metrics-armv8
27-
features: expose-metrics
27+
features: metrics
2828
image: ubuntu-24.04-arm
2929

3030
runs-on: ${{ matrix.image }}

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ tracing = "0.1"
1818
tracing-subscriber = "0.3"
1919
twilight-http-ratelimiting = { version = "0.16.0" }
2020

21-
# Only used by the `expose-metrics` feature.
2221
metrics = { version = "0.24", optional = true }
2322
metrics-exporter-prometheus = { version = "0.17", default-features = false, optional = true }
2423
metrics-util = { version = "0.20", optional = true }
@@ -27,7 +26,7 @@ metrics-util = { version = "0.20", optional = true }
2726
tokio = { version = "1.43", features = ["test-util"] }
2827

2928
[features]
30-
expose-metrics = ["metrics", "metrics-exporter-prometheus", "metrics-util"]
29+
metrics = ["dep:metrics", "dep:metrics-exporter-prometheus", "dep:metrics-util"]
3130

3231
[profile.release]
3332
codegen-units = 1

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,10 @@ setting `DISABLE_HTTP2` to any value when running the proxy.
115115

116116
## Prometheus metrics
117117

118-
The HTTP proxy can expose prometheus metrics when compiled with the
119-
`expose-metrics` feature. These metrics are then available on the `/metrics`
120-
endpoint.
121-
You can set the metrics key used for the histogram data by setting the
122-
`METRIC_KEY` environment variable.
118+
The HTTP proxy can expose prometheus metrics when compiled with the `metrics`
119+
feature. These metrics are then available on the `/metrics` endpoint. You can
120+
set the metrics key used for the histogram data by setting the `METRIC_KEY`
121+
environment variable.
123122

124123
The exported histogram includes timing percentiles, response status codes,
125124
request path and request method. Calls to the metrics endpoint itself are not

src/main.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ use twilight_http_ratelimiting::{
3939
#[cfg(unix)]
4040
use tokio::signal::unix::{SignalKind, signal};
4141

42-
#[cfg(feature = "expose-metrics")]
42+
#[cfg(feature = "metrics")]
4343
use http::header::CONTENT_TYPE;
44-
#[cfg(feature = "expose-metrics")]
44+
#[cfg(feature = "metrics")]
4545
use http_body_util::{BodyExt, Full};
46-
#[cfg(feature = "expose-metrics")]
46+
#[cfg(feature = "metrics")]
4747
use metrics::histogram;
48-
#[cfg(feature = "expose-metrics")]
48+
#[cfg(feature = "metrics")]
4949
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
50-
#[cfg(feature = "expose-metrics")]
50+
#[cfg(feature = "metrics")]
5151
use metrics_util::MetricKindMask;
52-
#[cfg(feature = "expose-metrics")]
52+
#[cfg(feature = "metrics")]
5353
use std::{
5454
borrow::Cow,
5555
sync::LazyLock,
5656
time::{Duration, Instant},
5757
};
5858

59-
#[cfg(feature = "expose-metrics")]
59+
#[cfg(feature = "metrics")]
6060
static METRIC_KEY: LazyLock<Cow<str>> = LazyLock::new(|| {
6161
env::var("METRIC_KEY").map_or(Cow::Borrowed("twilight_http_proxy"), Cow::Owned)
6262
});
@@ -90,10 +90,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
9090

9191
let address = SocketAddr::from((host, port));
9292

93-
#[cfg(feature = "expose-metrics")]
93+
#[cfg(feature = "metrics")]
9494
let handle: Arc<PrometheusHandle>;
9595

96-
#[cfg(feature = "expose-metrics")]
96+
#[cfg(feature = "metrics")]
9797
{
9898
let timeout = parse_env("METRIC_TIMEOUT").unwrap_or(300);
9999
let recorder = PrometheusBuilder::new()
@@ -127,7 +127,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
127127
// Cloning a hyper client is fairly cheap by design
128128
let client = client.clone();
129129

130-
#[cfg(feature = "expose-metrics")]
130+
#[cfg(feature = "metrics")]
131131
let handle = handle.clone();
132132

133133
tasks.spawn(async move {
@@ -141,7 +141,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
141141
let (ratelimiter, token) = ratelimiter_map.get_or_insert(token);
142142
let client = client.clone();
143143

144-
#[cfg(feature = "expose-metrics")]
144+
#[cfg(feature = "metrics")]
145145
{
146146
let handle = handle.clone();
147147

@@ -158,7 +158,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
158158
}
159159
}
160160

161-
#[cfg(not(feature = "expose-metrics"))]
161+
#[cfg(not(feature = "metrics"))]
162162
{
163163
async move {
164164
Ok::<_, Infallible>(
@@ -390,7 +390,7 @@ async fn handle_request(
390390
};
391391
*request.uri_mut() = uri;
392392

393-
#[cfg(feature = "expose-metrics")]
393+
#[cfg(feature = "metrics")]
394394
let start = Instant::now();
395395

396396
let resp = match client.request(request).await {
@@ -412,13 +412,13 @@ async fn handle_request(
412412
error!("Error when sending ratelimit headers to ratelimiter");
413413
};
414414

415-
#[cfg(feature = "expose-metrics")]
415+
#[cfg(feature = "metrics")]
416416
let end = Instant::now();
417417

418418
trace!("Response: {:?}", resp);
419419

420420
let status = resp.status();
421-
#[cfg(feature = "expose-metrics")]
421+
#[cfg(feature = "metrics")]
422422
{
423423
let scope = resp
424424
.headers()
@@ -439,7 +439,7 @@ async fn handle_request(
439439
Ok(resp)
440440
}
441441

442-
#[cfg(feature = "expose-metrics")]
442+
#[cfg(feature = "metrics")]
443443
fn handle_metrics(handle: Arc<PrometheusHandle>) -> Response<BoxBody<Bytes, hyper::Error>> {
444444
Response::builder()
445445
.header(

0 commit comments

Comments
 (0)