Skip to content

Commit

Permalink
chore(api): ignore health checks in request metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Mar 29, 2024
1 parent a9b7eff commit d56e142
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions crates/synd_api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ pub mod serve {
pub const DEFAULT_REQUEST_TIMEOUT: &str = "30s";
pub const DEFAULT_REQUEST_BODY_LIMIT_BYTES: usize = 1024 * 2;
pub const DEFAULT_REQUEST_CONCURRENCY_LIMIT: usize = 100;

pub const HEALTH_CHECK_PATH: &str = "/health";
}
}
21 changes: 13 additions & 8 deletions crates/synd_api/src/serve/layer/request_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,19 @@ where
let response = this.inner.call(req).await.unwrap();
let status = response.status().as_u16();

// https://opentelemetry.io/docs/specs/semconv/http/http-metrics/
// Considiering the case of not found(404), recording the path as
// an attribute leads to an inability to control cardinality.
// Therefore, the path is not recorded.
metric!(
monotonic_counter.http.server.request = 1,
http.response.status.code = status
);
// Ignore health check
// Metrics related to health checks is ignored as the are collected
// by the service performing the health check
if path != config::serve::HEALTH_CHECK_PATH {
// https://opentelemetry.io/docs/specs/semconv/http/http-metrics/
// Considiering the case of not found(404), recording the path as
// an attribute leads to an inability to control cardinality.
// Therefore, the path is not recorded.
metric!(
monotonic_counter.http.server.request = 1,
http.response.status.code = status
);
}

// instrument graphql latency
if path == "/graphql" && method == Method::POST {
Expand Down
2 changes: 1 addition & 1 deletion crates/synd_api/src/serve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub async fn serve(
.layer(RequestBodyLimitLayer::new(request_body_limit_bytes))
.layer(CorsLayer::new()),
)
.route("/health", get(probe::healthcheck))
.route(config::serve::HEALTH_CHECK_PATH, get(probe::healthcheck))
.layer(RequestMetricsLayer::new())
.fallback(not_found);

Expand Down

0 comments on commit d56e142

Please sign in to comment.