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

chore: Removed shadow-rs to reduce our dependencies tree #321

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 0 additions & 119 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ rustls-pemfile = "1.0.3"
serde = {version = "1.0.189", features = ["derive"]}
serde_json = "1.0.107"
serde_qs = { version = "0.12.0", features = ["actix4", "tracing"] }
shadow-rs = "0.24.1"
tokio = {version = "1.33.0", features = ["macros", "rt-multi-thread", "tracing", "fs"]}
tracing = {version = "0.1.40", features = ["log"]}
tracing-subscriber = {version = "0.3.17", features = ["json", "env-filter"]}
Expand All @@ -68,6 +67,3 @@ test-case = "3.2.1"
testcontainers = "0.15.0"
testcontainers-modules = { version = "0.1.3", features = ["redis"]}
tracing-test = "0.2.4"

[build-dependencies]
shadow-rs = "0.24.1"
3 changes: 0 additions & 3 deletions server/build.rs

This file was deleted.

4 changes: 2 additions & 2 deletions server/src/http/feature_refresher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::unleash_client::UnleashClient;
use crate::error::{EdgeError, FeatureError};
use crate::filters::{filter_client_features, FeatureFilterSet};
use crate::types::{
build, ClientTokenRequest, ClientTokenResponse, EdgeResult, TokenType, TokenValidationStatus,
self, ClientTokenRequest, ClientTokenResponse, EdgeResult, TokenType, TokenValidationStatus,
};
use crate::{
persistence::EdgePersistence,
Expand Down Expand Up @@ -120,7 +120,7 @@ fn client_application_from_token(token: EdgeToken, refresh_interval: i64) -> Cli
environment: token.environment,
instance_id: None,
interval: refresh_interval as u32,
sdk_version: Some(format!("unleash-edge:{}", build::PKG_VERSION)),
sdk_version: Some(format!("unleash-edge:{}", types::CARGO_PKG_VERSION)),
started: Utc::now(),
strategies: vec![],
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/http/unleash_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn new_reqwest_client(
);

client
.user_agent(format!("unleash-edge-{}", crate::types::build::PKG_VERSION))
.user_agent(format!("unleash-edge-{}", crate::types::CARGO_PKG_VERSION))
.default_headers(header_map)
.danger_accept_invalid_certs(skip_ssl_verification)
.timeout(socket_timeout.to_std().unwrap())
Expand Down
29 changes: 2 additions & 27 deletions server/src/internal_backstage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::auth::token_validator::TokenValidator;
use crate::http::feature_refresher::FeatureRefresher;
use crate::metrics::actix_web_metrics::PrometheusMetricsHandler;
use crate::types::Status;
use crate::types::{BuildInfo, EdgeJsonResult, EdgeToken, TokenInfo, TokenRefresh};
use crate::types::{EdgeJsonResult, EdgeToken, TokenInfo, TokenRefresh};
use actix_web::{
get,
web::{self, Json},
Expand Down Expand Up @@ -37,12 +37,6 @@ pub async fn health() -> EdgeJsonResult<EdgeStatus> {
Ok(Json(EdgeStatus::ok()))
}

#[get("/info")]
pub async fn info() -> EdgeJsonResult<BuildInfo> {
let data = BuildInfo::default();
Ok(Json(data))
}

#[get("/ready")]
pub async fn ready(
features_cache: web::Data<DashMap<String, ClientFeatures>>,
Expand Down Expand Up @@ -84,7 +78,6 @@ pub fn configure_internal_backstage(
metrics_handler: PrometheusMetricsHandler,
) {
cfg.service(health)
.service(info)
.service(tokens)
.service(ready)
.service(web::resource("/metrics").route(web::get().to(metrics_handler)));
Expand All @@ -102,8 +95,7 @@ mod tests {
use crate::middleware;
use crate::tests::upstream_server;
use crate::tokens::cache_key;
use crate::types::{BuildInfo, EdgeToken, Status, TokenInfo, TokenType, TokenValidationStatus};
use actix_web::body::MessageBody;
use crate::types::{EdgeToken, Status, TokenInfo, TokenType, TokenValidationStatus};
use actix_web::http::header::ContentType;
use actix_web::test;
use actix_web::{web, App};
Expand All @@ -125,23 +117,6 @@ mod tests {
assert!(resp.status().is_success())
}

#[actix_web::test]
async fn test_build_info_ok() {
let app = test::init_service(
App::new().service(web::scope("/internal-backstage").service(super::info)),
)
.await;
let req = test::TestRequest::get()
.uri("/internal-backstage/info")
.insert_header(ContentType::json())
.to_request();
let resp = test::call_service(&app, req).await;
assert!(resp.status().is_success());
let body = resp.into_body().try_into_bytes().unwrap();
let info: BuildInfo = serde_json::from_slice(&body).unwrap();
assert_eq!(info.app_name, "unleash-edge");
}

#[actix_web::test]
async fn test_ready_endpoint_without_toggles() {
let client_features: DashMap<String, ClientFeatures> = DashMap::default();
Expand Down
9 changes: 4 additions & 5 deletions server/src/prom_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ pub fn instantiate(
fn instantiate_prometheus_metrics_handler(
registry: prometheus::Registry,
) -> (PrometheusMetricsHandler, RequestMetrics) {
let resource = opentelemetry::sdk::Resource::new(vec![
opentelemetry::KeyValue::new("service.name", "unleash-edge"),
opentelemetry::KeyValue::new("edge.version", crate::types::build::PKG_VERSION),
opentelemetry::KeyValue::new("edge.githash", crate::types::build::SHORT_COMMIT),
]);
let resource = opentelemetry::sdk::Resource::new(vec![opentelemetry::KeyValue::new(
"service.name",
"unleash-edge",
)]);
let provider = MeterProvider::builder().with_resource(resource).build();
(
PrometheusMetricsHandler::new(registry),
Expand Down
50 changes: 1 addition & 49 deletions server/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use async_trait::async_trait;
use chrono::{DateTime, Duration, Utc};
use dashmap::DashMap;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use shadow_rs::shadow;
use unleash_types::client_features::ClientFeatures;
use unleash_types::client_metrics::{ClientApplication, ClientMetricsEnv};
use unleash_yggdrasil::EngineState;
Expand Down Expand Up @@ -273,6 +272,7 @@ pub struct ClientTokenRequest {
pub environment: String,
pub expires_at: DateTime<Utc>,
}
pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");

#[async_trait]
pub trait TokenValidator {
Expand All @@ -281,54 +281,6 @@ pub trait TokenValidator {
async fn register_tokens(&mut self, tokens: Vec<String>) -> EdgeResult<Vec<EdgeToken>>;
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BuildInfo {
pub package_version: String,
pub app_name: String,
pub git_commit_date: DateTime<Utc>,
pub package_major: String,
pub package_minor: String,
pub package_patch: String,
pub package_version_pre: Option<String>,
pub branch: String,
pub tag: String,
pub rust_version: String,
pub rust_channel: String,
pub short_commit_hash: String,
pub full_commit_hash: String,
pub build_os: String,
pub build_target: String,
}

shadow!(build); // Get build information set to build placeholder
impl Default for BuildInfo {
fn default() -> Self {
BuildInfo {
package_version: build::PKG_VERSION.into(),
app_name: build::PROJECT_NAME.into(),
package_major: build::PKG_VERSION_MAJOR.into(),
package_minor: build::PKG_VERSION_MINOR.into(),
package_patch: build::PKG_VERSION_PATCH.into(),
package_version_pre: if build::PKG_VERSION_PRE.is_empty() {
None
} else {
Some(build::PKG_VERSION_PRE.into())
},
branch: build::BRANCH.into(),
tag: build::TAG.into(),
rust_version: build::RUST_VERSION.into(),
rust_channel: build::RUST_CHANNEL.into(),
short_commit_hash: build::SHORT_COMMIT.into(),
full_commit_hash: build::COMMIT_HASH.into(),
git_commit_date: DateTime::parse_from_rfc3339(build::COMMIT_DATE_3339)
.expect("shadow-rs did not give proper date")
.into(),
build_os: build::BUILD_OS.into(),
build_target: build::BUILD_TARGET.into(),
}
}
}

#[derive(Clone, Debug, Serialize, Deserialize, IntoParams)]
#[serde(rename_all = "camelCase")]
pub struct FeatureFilters {
Expand Down
Loading