Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add edge observability #713

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions server/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ pub struct InternalBackstageArgs {
/// Used to show tokens used to refresh feature caches, but also tokens already validated/invalidated against upstream
#[clap(long, env, global = true)]
pub disable_tokens_endpoint: bool,

/// Disables /internal-backstage/instancedata endpoint
///
/// Used to show instance data for the edge instance.
#[clap(long, env, global = true)]
pub disable_instance_data_endpoint: bool,
}

#[derive(Args, Debug, Clone)]
Expand Down
27 changes: 25 additions & 2 deletions server/src/client_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::filters::{
use crate::http::broadcaster::Broadcaster;
use crate::http::refresher::feature_refresher::FeatureRefresher;
use crate::metrics::client_metrics::MetricsCache;
use crate::metrics::edge_metrics::EdgeInstanceData;
use crate::tokens::cache_key;
use crate::types::{
self, BatchMetricsRequestBody, EdgeJsonResult, EdgeResult, EdgeToken, FeatureFilters,
Expand All @@ -15,6 +16,8 @@ use actix_web::web::{self, Data, Json, Query};
use actix_web::Responder;
use actix_web::{get, post, HttpRequest, HttpResponse};
use dashmap::DashMap;
use tokio::sync::RwLock;
use tracing::{info, instrument};
use unleash_types::client_features::{ClientFeature, ClientFeatures};
use unleash_types::client_metrics::{ClientApplication, ClientMetrics, ConnectVia};

Expand Down Expand Up @@ -272,6 +275,26 @@ pub async fn post_bulk_metrics(
);
Ok(HttpResponse::Accepted().finish())
}

#[utoipa::path(context_path = "/api/client", responses((status = 202, description = "Accepted Instance data"), (status = 403, description = "Was not allowed to post instance data")), request_body = EdgeInstanceData, security(
("Authorization" = [])
)
)]
#[post("/metrics/edge")]
#[instrument(skip(_edge_token, instance_data, connected_instances))]
pub async fn post_edge_instance_data(
_edge_token: EdgeToken,
instance_data: Json<EdgeInstanceData>,
connected_instances: Data<RwLock<Vec<EdgeInstanceData>>>,
) -> EdgeResult<HttpResponse> {
info!("Accepted {instance_data:?}");
connected_instances
.write()
.await
.push(instance_data.into_inner());
Ok(HttpResponse::Accepted().finish())
}

pub fn configure_client_api(cfg: &mut web::ServiceConfig) {
let client_scope = web::scope("/client")
.wrap(crate::middleware::as_async_middleware::as_async_middleware(
Expand All @@ -282,7 +305,8 @@ pub fn configure_client_api(cfg: &mut web::ServiceConfig) {
.service(register)
.service(metrics)
.service(post_bulk_metrics)
.service(stream_features);
.service(stream_features)
.service(post_edge_instance_data);

cfg.service(client_scope);
}
Expand Down Expand Up @@ -1358,7 +1382,6 @@ mod tests {
let features_cache = Arc::new(FeatureCache::default());
let token_cache: Arc<DashMap<String, EdgeToken>> = Arc::new(DashMap::default());
let token_header = TokenHeader::from_str("NeedsToBeTested").unwrap();
println!("token_header: {:?}", token_header);
let app = test::init_service(
App::new()
.app_data(Data::from(features_cache.clone()))
Expand Down
Loading
Loading