diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a6a0d4d9..9ad531b2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -18,6 +18,7 @@ jobs: name: Checkout code with: token: ${{ secrets.GH_PUSH_TOKEN }} + fetch-depth: 0 - name: setup git config run: | git config user.name "Github Release Bot" @@ -27,7 +28,10 @@ jobs: rustup set auto-self-update disable rustup toolchain install stable --profile minimal rustup show - - uses: Swatinem/rust-cache@v2 + - name: Use rust cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true - name: Install cargo smart-release run: | cargo install cargo-smart-release diff --git a/Cargo.lock b/Cargo.lock index 132e2910..1a0fae99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2076,7 +2076,7 @@ dependencies = [ "tracing", "tracing-opentelemetry", "tracing-subscriber", - "unleash-types 0.4.0", + "unleash-types 0.4.1", "unleash-yggdrasil", ] @@ -2093,9 +2093,9 @@ dependencies = [ [[package]] name = "unleash-types" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f0c6b0dea14d7fe9296f2217b8f0b1dc21b1616d158d5f3623caaa09ef86bf3" +checksum = "cd02ee0e5dca295018290a6e4d7bdd53a961f58a08695ef3e9fc34180a581e0d" dependencies = [ "chrono", "derive_builder", diff --git a/server/Cargo.toml b/server/Cargo.toml index 3560923c..3c459e33 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -24,5 +24,5 @@ tokio = { version = "1.24.2", features = ["macros", "rt-multi-thread", "tracing" tracing = { version = "0.1.37", features = ["log"] } tracing-opentelemetry = "0.18.0" tracing-subscriber = { version = "0.3.16", features = ["json", "env-filter"] } -unleash-types = "0.4.0" +unleash-types = "0.4.1" unleash-yggdrasil = "0.2.0" diff --git a/server/src/client_api.rs b/server/src/client_api.rs index 12bdf8bd..7413a95a 100644 --- a/server/src/client_api.rs +++ b/server/src/client_api.rs @@ -1,11 +1,12 @@ -use crate::offline_provider::OfflineProvider; use crate::types::{EdgeJsonResult, FeaturesProvider}; use actix_web::get; use actix_web::web::{self, Json}; use unleash_types::client_features::ClientFeatures; #[get("/client/features")] -async fn features(features_source: web::Data) -> EdgeJsonResult { +async fn features( + features_source: web::Data, +) -> EdgeJsonResult { let client_features = features_source.get_client_features(); Ok(Json(client_features)) } diff --git a/server/src/edge_api.rs b/server/src/edge_api.rs new file mode 100644 index 00000000..4e9369a9 --- /dev/null +++ b/server/src/edge_api.rs @@ -0,0 +1,3 @@ +use actix_web::web; + +pub fn configure_edge_api(_cfg: &mut web::ServiceConfig) {} diff --git a/server/src/error.rs b/server/src/error.rs index 4cdce6df..5b2456e2 100644 --- a/server/src/error.rs +++ b/server/src/error.rs @@ -5,7 +5,7 @@ use actix_web::{http::StatusCode, HttpResponseBuilder, ResponseError}; #[derive(Debug)] pub enum EdgeError { - InvalidBackupFile(String), + InvalidBackupFile(String, String), NoFeaturesFile, TlsError, } @@ -15,7 +15,11 @@ impl Error for EdgeError {} impl Display for EdgeError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - EdgeError::InvalidBackupFile(msg) => write!(f, "{}", msg), + EdgeError::InvalidBackupFile(path, why_invalid) => write!( + f, + "file at path: {} was invalid due to {}", + path, why_invalid + ), EdgeError::TlsError => write!(f, "Could not configure TLS"), EdgeError::NoFeaturesFile => write!(f, "No features file located"), } @@ -25,7 +29,7 @@ impl Display for EdgeError { impl ResponseError for EdgeError { fn status_code(&self) -> actix_web::http::StatusCode { match self { - EdgeError::InvalidBackupFile(_) => StatusCode::INTERNAL_SERVER_ERROR, + EdgeError::InvalidBackupFile(_, _) => StatusCode::INTERNAL_SERVER_ERROR, EdgeError::TlsError => StatusCode::INTERNAL_SERVER_ERROR, EdgeError::NoFeaturesFile => StatusCode::INTERNAL_SERVER_ERROR, } diff --git a/server/src/frontend_api.rs b/server/src/frontend_api.rs new file mode 100644 index 00000000..b9cdc698 --- /dev/null +++ b/server/src/frontend_api.rs @@ -0,0 +1,3 @@ +use actix_web::web; + +pub fn configure_frontend_api(_cfg: &mut web::ServiceConfig) {} diff --git a/server/src/internal_backstage.rs b/server/src/internal_backstage.rs index ee58527a..50378dac 100644 --- a/server/src/internal_backstage.rs +++ b/server/src/internal_backstage.rs @@ -1,8 +1,8 @@ use actix_web::{ get, web::{self, Json}, - HttpRequest, }; +use actix_web_opentelemetry::PrometheusMetricsHandler; use serde::Serialize; use crate::types::EdgeJsonResult; @@ -20,12 +20,16 @@ impl EdgeStatus { } } #[get("/health")] -pub async fn health(_req: HttpRequest) -> EdgeJsonResult { +pub async fn health() -> EdgeJsonResult { Ok(Json(EdgeStatus::ok())) } -pub fn configure_internal_backstage(cfg: &mut web::ServiceConfig) { - cfg.service(health); +pub fn configure_internal_backstage( + cfg: &mut web::ServiceConfig, + metrics_handler: PrometheusMetricsHandler, +) { + cfg.service(health) + .service(web::resource("/metrics").route(web::get().to(metrics_handler))); } #[cfg(test)] @@ -34,9 +38,9 @@ mod tests { #[actix_web::test] async fn test_health_ok() { - let app = test::init_service(App::new().service( - web::scope("/internal-backstage").configure(super::configure_internal_backstage), - )) + let app = test::init_service( + App::new().service(web::scope("/internal-backstage").service(super::health)), + ) .await; let req = test::TestRequest::get() .uri("/internal-backstage/health") diff --git a/server/src/main.rs b/server/src/main.rs index 7a4e7e50..b9b7ca3a 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,13 +1,18 @@ +use std::sync::Arc; + use crate::cli::EdgeMode; use crate::offline_provider::OfflineProvider; use actix_web::{middleware, web, App, HttpServer}; use actix_web_opentelemetry::RequestTracing; use clap::Parser; use cli::CliArgs; +use types::FeaturesProvider; mod cli; mod client_api; +mod edge_api; mod error; +mod frontend_api; mod internal_backstage; mod metrics; mod offline_provider; @@ -24,19 +29,25 @@ async fn main() -> Result<(), anyhow::Error> { } .map_err(anyhow::Error::new)?; let server = HttpServer::new(move || { + let client_provider_arc: Arc = Arc::new(client_provider.clone()); + let client_provider_data = web::Data::from(client_provider_arc); App::new() - .app_data(web::Data::new(client_provider.clone())) + .app_data(client_provider_data) .wrap(RequestTracing::new()) .wrap(request_metrics.clone()) .wrap(middleware::Logger::default()) + .service(web::scope("/internal-backstage").configure(|service_cfg| { + internal_backstage::configure_internal_backstage( + service_cfg, + metrics_handler.clone(), + ) + })) .service( - web::scope("/internal-backstage") - .configure(internal_backstage::configure_internal_backstage) - .service( - web::resource("/metrics").route(web::get().to(metrics_handler.clone())), - ), + web::scope("/api") + .configure(client_api::configure_client_api) + .configure(frontend_api::configure_frontend_api), ) - .service(web::scope("/api").configure(client_api::configure_client_api)) + .service(web::scope("/edge").configure(edge_api::configure_edge_api)) }); let server = if args.http.tls.tls_enable { let config = tls::config(args.clone().http.tls) diff --git a/server/src/offline_provider.rs b/server/src/offline_provider.rs index 2ab78c79..db481da7 100644 --- a/server/src/offline_provider.rs +++ b/server/src/offline_provider.rs @@ -3,7 +3,6 @@ use crate::types::FeaturesProvider; use std::fs::File; use std::io::BufReader; use std::path::PathBuf; -use tracing::info; use unleash_types::client_features::ClientFeatures; #[derive(Debug, Clone)] @@ -21,18 +20,13 @@ impl OfflineProvider { pub fn instantiate_provider( bootstrap_file: Option, ) -> Result { - info!("Instantiate offline provider"); if let Some(bootstrap) = bootstrap_file { - info!("Opening bootstrap file"); let file = File::open(bootstrap.clone()).map_err(|_| EdgeError::NoFeaturesFile)?; - info!("Opened"); let reader = BufReader::new(file); - info!("Buffered reader"); - let client_features: ClientFeatures = - serde_json::from_reader(reader).map_err(|_| { - let path = format!("{}", bootstrap.clone().display()); - EdgeError::InvalidBackupFile(path) - })?; + let client_features: ClientFeatures = serde_json::from_reader(reader).map_err(|e| { + let path = format!("{}", bootstrap.clone().display()); + EdgeError::InvalidBackupFile(path, e.to_string()) + })?; Ok(OfflineProvider::new(client_features)) } else { Err(EdgeError::NoFeaturesFile)