diff --git a/server/src/builder.rs b/server/src/builder.rs index 8defe485..5d86ad2e 100644 --- a/server/src/builder.rs +++ b/server/src/builder.rs @@ -162,7 +162,7 @@ async fn get_data_source(args: &EdgeArgs) -> Option> { None } -async fn build_edge(args: &EdgeArgs) -> EdgeResult { +async fn build_edge(args: &EdgeArgs, app_name: &str) -> EdgeResult { if !args.strict { if !args.dynamic { error!("You should explicitly opt into either strict or dynamic behavior. Edge has defaulted to dynamic to preserve legacy behavior, however we recommend using strict from now on. Not explicitly opting into a behavior will return an error on startup in a future release"); @@ -190,6 +190,7 @@ async fn build_edge(args: &EdgeArgs) -> EdgeResult { Duration::seconds(args.upstream_request_timeout), Duration::seconds(args.upstream_socket_timeout), args.token_header.token_header.clone(), + app_name.into(), ) }) .map(|c| c.with_custom_client_headers(args.custom_client_headers.clone())) @@ -209,6 +210,7 @@ async fn build_edge(args: &EdgeArgs) -> EdgeResult { Duration::seconds(args.features_refresh_interval_seconds.try_into().unwrap()), persistence.clone(), args.strict, + app_name, )); let _ = token_validator.register_tokens(args.tokens.clone()).await; @@ -245,7 +247,7 @@ pub async fn build_caches_and_refreshers(args: CliArgs) -> EdgeResult EdgeMode::Offline(offline_args) => { build_offline(offline_args).map(|cache| (cache, None, None, None)) } - EdgeMode::Edge(edge_args) => build_edge(&edge_args).await, + EdgeMode::Edge(edge_args) => build_edge(&edge_args, &args.app_name).await, _ => unreachable!(), } } @@ -296,7 +298,7 @@ mod tests { token_revalidation_interval_seconds: Default::default(), }; - let result = build_edge(&args).await; + let result = build_edge(&args, &"test-app").await; assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), diff --git a/server/src/cli.rs b/server/src/cli.rs index b0becd2c..5dbcbe75 100644 --- a/server/src/cli.rs +++ b/server/src/cli.rs @@ -284,7 +284,7 @@ pub struct CliArgs { pub instance_id: String, /// App name. Used for metrics reporting. - #[clap(short, long, env, default_value = "unleash-edge")] + #[clap(short, long, env, global = true, default_value = "unleash-edge")] pub app_name: String, #[arg(long, hide = true, global = true)] diff --git a/server/src/client_api.rs b/server/src/client_api.rs index 1f88dd6a..39871222 100644 --- a/server/src/client_api.rs +++ b/server/src/client_api.rs @@ -975,6 +975,7 @@ mod tests { refresh_interval: Duration::seconds(6000), persistence: None, strict: false, + app_name: "test-app".into(), }); let token_validator = Arc::new(TokenValidator { unleash_client: unleash_client.clone(), diff --git a/server/src/http/feature_refresher.rs b/server/src/http/feature_refresher.rs index 7dc45378..d51024ad 100644 --- a/server/src/http/feature_refresher.rs +++ b/server/src/http/feature_refresher.rs @@ -101,6 +101,7 @@ pub struct FeatureRefresher { pub refresh_interval: chrono::Duration, pub persistence: Option>, pub strict: bool, + pub app_name: String, } impl Default for FeatureRefresher { @@ -113,13 +114,18 @@ impl Default for FeatureRefresher { engine_cache: Default::default(), persistence: None, strict: true, + app_name: "unleash_edge".into(), } } } -fn client_application_from_token(token: EdgeToken, refresh_interval: i64) -> ClientApplication { +fn client_application_from_token_and_name( + token: EdgeToken, + refresh_interval: i64, + app_name: &str, +) -> ClientApplication { ClientApplication { - app_name: "unleash_edge".into(), + app_name: app_name.into(), connect_via: None, environment: token.environment, instance_id: None, @@ -143,6 +149,7 @@ impl FeatureRefresher { features_refresh_interval: chrono::Duration, persistence: Option>, strict: bool, + app_name: &str, ) -> Self { FeatureRefresher { unleash_client, @@ -152,6 +159,7 @@ impl FeatureRefresher { refresh_interval: features_refresh_interval, persistence, strict, + app_name: app_name.into(), } } @@ -269,9 +277,10 @@ impl FeatureRefresher { self.unleash_client .register_as_client( token.token.clone(), - client_application_from_token( + client_application_from_token_and_name( token.clone(), self.refresh_interval.num_seconds(), + &self.app_name, ), ) .await @@ -484,6 +493,7 @@ mod tests { Duration::seconds(5), Duration::seconds(5), "Authorization".to_string(), + "test-client".into(), ); let features_cache = Arc::new(DashMap::default()); let engine_cache = Arc::new(DashMap::default()); @@ -516,6 +526,7 @@ mod tests { Duration::seconds(5), Duration::seconds(5), "Authorization".to_string(), + "test-client".into(), ); let features_cache = Arc::new(DashMap::default()); let engine_cache = Arc::new(DashMap::default()); @@ -552,6 +563,7 @@ mod tests { Duration::seconds(5), Duration::seconds(5), "Authorization".to_string(), + "test-client".into(), ); let features_cache = Arc::new(DashMap::default()); let engine_cache = Arc::new(DashMap::default()); @@ -595,6 +607,7 @@ mod tests { Duration::seconds(5), Duration::seconds(5), "Authorization".to_string(), + "test-client".into(), ); let features_cache = Arc::new(DashMap::default()); let engine_cache = Arc::new(DashMap::default()); @@ -647,6 +660,7 @@ mod tests { Duration::seconds(5), Duration::seconds(5), "Authorization".to_string(), + "test-client".into(), ); let features_cache = Arc::new(DashMap::default()); let engine_cache = Arc::new(DashMap::default()); @@ -703,6 +717,7 @@ mod tests { Duration::seconds(5), Duration::seconds(5), "Authorization".to_string(), + "test-client".into(), ); let features_cache = Arc::new(DashMap::default()); let engine_cache = Arc::new(DashMap::default()); @@ -744,6 +759,7 @@ mod tests { Duration::seconds(5), Duration::seconds(5), "Authorization".to_string(), + "test-client".into(), ); let features_cache = Arc::new(DashMap::default()); let engine_cache = Arc::new(DashMap::default()); @@ -780,6 +796,7 @@ mod tests { Duration::seconds(5), Duration::seconds(5), "Authorization".to_string(), + "test-client".into(), ); let features_cache = Arc::new(DashMap::default()); let engine_cache = Arc::new(DashMap::default()); diff --git a/server/src/http/unleash_client.rs b/server/src/http/unleash_client.rs index 128da52f..52f355b3 100644 --- a/server/src/http/unleash_client.rs +++ b/server/src/http/unleash_client.rs @@ -136,6 +136,7 @@ fn new_reqwest_client( upstream_certificate_file: Option, connect_timeout: Duration, socket_timeout: Duration, + app_name: String, ) -> EdgeResult { build_identity(client_identity) .and_then(|builder| { @@ -148,7 +149,8 @@ fn new_reqwest_client( let mut header_map = HeaderMap::new(); header_map.insert( UNLEASH_APPNAME_HEADER, - header::HeaderValue::from_static("unleash-edge"), + header::HeaderValue::from_str(app_name.as_str()) + .expect("Could not add app name as a header"), ); header_map.insert( UNLEASH_INSTANCE_ID_HEADER, @@ -184,6 +186,7 @@ impl UnleashClient { connect_timeout: Duration, socket_timeout: Duration, token_header: String, + app_name: String, ) -> Self { Self { urls: UnleashUrls::from_base_url(server_url), @@ -194,6 +197,7 @@ impl UnleashClient { upstream_certificate_file, connect_timeout, socket_timeout, + app_name, ) .unwrap(), custom_headers: Default::default(), @@ -215,6 +219,7 @@ impl UnleashClient { None, Duration::seconds(5), Duration::seconds(5), + "test-client".into(), ) .unwrap(), custom_headers: Default::default(), @@ -235,6 +240,7 @@ impl UnleashClient { None, Duration::seconds(5), Duration::seconds(5), + "test-client".into(), ) .unwrap(), custom_headers: Default::default(), @@ -806,6 +812,7 @@ mod tests { None, Duration::seconds(5), Duration::seconds(5), + "test-client".into(), ); assert!(client.is_ok()); } @@ -827,6 +834,7 @@ mod tests { None, Duration::seconds(5), Duration::seconds(5), + "test-client".into(), ); assert!(client.is_err()); } @@ -848,6 +856,7 @@ mod tests { None, Duration::seconds(5), Duration::seconds(5), + "test-client".into(), ); assert!(client.is_ok()); } diff --git a/server/src/middleware/client_token_from_frontend_token.rs b/server/src/middleware/client_token_from_frontend_token.rs index 8688496a..2caf7d51 100644 --- a/server/src/middleware/client_token_from_frontend_token.rs +++ b/server/src/middleware/client_token_from_frontend_token.rs @@ -140,6 +140,7 @@ mod tests { Duration::seconds(5), Duration::seconds(5), "Authorization".to_string(), + "test-client".into(), ); let local_features_cache: Arc> = Arc::new(DashMap::default());