Skip to content

Commit

Permalink
task: remove request tracing
Browse files Browse the repository at this point in the history
Originally we wanted to support OpenTelemetry for tracing, but we no
longer support setting up an OTEL_COLLECTOR, so removing the request
tracer seems sensible
  • Loading branch information
chriswk committed Oct 16, 2024
1 parent 3e1f60d commit f94436c
Show file tree
Hide file tree
Showing 8 changed files with 525 additions and 838 deletions.
1,059 changes: 518 additions & 541 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions server/src/auth/token_validator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use dashmap::DashMap;
use tracing::{instrument, trace};
use tracing::trace;
use unleash_types::Upsert;

use crate::http::feature_refresher::FeatureRefresher;
Expand Down Expand Up @@ -100,7 +100,6 @@ impl TokenValidator {
}
}

#[instrument(skip(self))]
pub async fn schedule_validation_of_known_tokens(&self, validation_interval_seconds: u64) {
let sleep_duration = tokio::time::Duration::from_secs(validation_interval_seconds);
loop {
Expand All @@ -112,7 +111,6 @@ impl TokenValidator {
}
}

#[instrument(skip(self, tokens, refresher))]
pub async fn schedule_revalidation_of_startup_tokens(
&self,
tokens: Vec<String>,
Expand Down
4 changes: 1 addition & 3 deletions server/src/frontend_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use actix_web::{
};
use dashmap::DashMap;
use serde_qs::actix::QsQuery;
use tracing::{debug, instrument};
use tracing::debug;
use unleash_types::client_features::Context;
use unleash_types::client_metrics::{ClientApplication, ConnectVia};
use unleash_types::{
Expand Down Expand Up @@ -242,7 +242,6 @@ security(
)
)]
#[get("")]
#[instrument(skip(edge_token, req, engine_cache, token_cache, context))]
async fn get_enabled_proxy(
edge_token: EdgeToken,
engine_cache: Data<DashMap<String, EngineState>>,
Expand Down Expand Up @@ -272,7 +271,6 @@ security(
)
)]
#[get("")]
#[instrument(skip(edge_token, req, engine_cache, token_cache, context))]
async fn get_enabled_frontend(
edge_token: EdgeToken,
engine_cache: Data<DashMap<String, EngineState>>,
Expand Down
2 changes: 0 additions & 2 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use utoipa_swagger_ui::SwaggerUi;
use unleash_edge::builder::build_caches_and_refreshers;
use unleash_edge::cli::{CliArgs, EdgeMode};
use unleash_edge::metrics::client_metrics::MetricsCache;
use unleash_edge::middleware::request_tracing::RequestTracing;
use unleash_edge::offline::offline_hotload;
use unleash_edge::persistence::{persist_data, EdgePersistence};
use unleash_edge::types::{EdgeToken, TokenValidationStatus};
Expand Down Expand Up @@ -106,7 +105,6 @@ async fn main() -> Result<(), anyhow::Error> {
.wrap(actix_web::middleware::Compress::default())
.wrap(actix_web::middleware::NormalizePath::default())
.wrap(cors_middleware)
.wrap(RequestTracing::new())
.wrap(request_metrics.clone())
.wrap(Logger::default())
.service(web::scope("/internal-backstage").configure(|service_cfg| {
Expand Down
79 changes: 4 additions & 75 deletions server/src/metrics/actix_web_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use actix_http::header::CONTENT_LENGTH;
use actix_web::dev;
use actix_web::dev::ServiceRequest;
use actix_web::http::{header, Method, StatusCode, Version};
use actix_web::http::{Method, StatusCode, Version};
use futures::{future, FutureExt};
use futures_core::future::LocalBoxFuture;
use opentelemetry::metrics::{Histogram, Meter, MeterProvider, MetricsError, UpDownCounter};
use opentelemetry::{global, Key, KeyValue, Value};
use opentelemetry::{global, KeyValue, Value};
use opentelemetry_semantic_conventions::trace::{
CLIENT_ADDRESS, HTTP_REQUEST_METHOD, HTTP_RESPONSE_STATUS_CODE, HTTP_ROUTE,
NETWORK_PROTOCOL_NAME, NETWORK_PROTOCOL_VERSION, SERVER_ADDRESS, SERVER_PORT, URL_PATH,
URL_SCHEME, USER_AGENT_ORIGINAL,
CLIENT_ADDRESS, HTTP_REQUEST_METHOD, HTTP_RESPONSE_STATUS_CODE, NETWORK_PROTOCOL_NAME,
NETWORK_PROTOCOL_VERSION, SERVER_ADDRESS, SERVER_PORT, URL_PATH, URL_SCHEME,
};
use prometheus::{Encoder, TextEncoder};
use std::sync::Arc;
Expand Down Expand Up @@ -58,76 +57,6 @@ pub(super) fn http_scheme(scheme: &str) -> Value {
}
}

pub(crate) fn trace_attributes_from_request(
req: &ServiceRequest,
http_route: &str,
) -> Vec<KeyValue> {
let conn_info = req.connection_info();

let mut attributes = Vec::with_capacity(11);
attributes.push(KeyValue::new(
HTTP_REQUEST_METHOD,
http_method_str(req.method()),
));
attributes.push(KeyValue::new::<Key, String>(
NETWORK_PROTOCOL_NAME.into(),
"http".into(),
));
attributes.push(KeyValue::new(
NETWORK_PROTOCOL_VERSION,
http_version(req.version()),
));
attributes.push(KeyValue::new::<Key, String>(
CLIENT_ADDRESS.into(),
conn_info.host().to_string(),
));
attributes.push(KeyValue::new::<Key, String>(
HTTP_ROUTE.into(),
http_route.to_owned(),
));
attributes.push(KeyValue::new(URL_SCHEME, http_scheme(conn_info.scheme())));

let server_name = req.app_config().host();
if server_name != conn_info.host() {
attributes.push(KeyValue::new::<Key, String>(
SERVER_ADDRESS.into(),
server_name.to_string(),
));
}
if let Some(port) = conn_info
.host()
.split_terminator(':')
.nth(1)
.and_then(|port| port.parse::<i64>().ok())
{
if port != 80 && port != 443 {
attributes.push(KeyValue::new(SERVER_PORT, port));
}
}
if let Some(path) = req.uri().path_and_query() {
attributes.push(KeyValue::new(URL_PATH, path.as_str().to_string()));
}
if let Some(user_agent) = req
.headers()
.get(header::USER_AGENT)
.and_then(|s| s.to_str().ok())
{
attributes.push(KeyValue::new(USER_AGENT_ORIGINAL, user_agent.to_string()));
}
let remote_addr = conn_info.realip_remote_addr();
if let Some(remote) = remote_addr {
attributes.push(KeyValue::new(CLIENT_ADDRESS, remote.to_string()));
}
if let Some(peer_addr) = req.peer_addr().map(|socket| socket.ip().to_string()) {
if Some(peer_addr.as_str()) != remote_addr {
// Client is going through a proxy
attributes.push(KeyValue::new(CLIENT_ADDRESS, peer_addr));
}
}

attributes
}

pub(super) fn metrics_attributes_from_request(
req: &ServiceRequest,
http_target: &str,
Expand Down
3 changes: 1 addition & 2 deletions server/src/middleware/client_token_from_frontend_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use actix_web::{
web::Data,
};
use dashmap::DashMap;
use tracing::{debug, instrument};
use tracing::debug;

use crate::{
http::feature_refresher::FeatureRefresher,
Expand All @@ -25,7 +25,6 @@ pub(crate) async fn create_client_token_for_fe_token(
Ok(())
}

#[instrument(skip(req, srv, token))]
pub async fn client_token_from_frontend_token(
token: EdgeToken,
req: ServiceRequest,
Expand Down
3 changes: 0 additions & 3 deletions server/src/middleware/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
pub mod as_async_middleware;

#[cfg(not(tarpaulin_include))]
pub mod request_tracing;

pub mod validate_token;

pub mod client_token_from_frontend_token;
Expand Down
209 changes: 0 additions & 209 deletions server/src/middleware/request_tracing.rs

This file was deleted.

0 comments on commit f94436c

Please sign in to comment.