Skip to content

Commit

Permalink
feat: upgrade types library, unfortunately this does two things - add…
Browse files Browse the repository at this point in the history
…s new optional metrics data and adds backwards compatability for impression_data (#489)
  • Loading branch information
sighphyre authored Jul 19, 2024
1 parent 4b43ff0 commit 9795c7c
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ tokio = { version = "1.38.0", features = [
tracing = { version = "0.1.40", features = ["log"] }
tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] }
ulid = "1.1.2"
unleash-types = { version = "0.12", features = ["openapi", "hashes"] }
unleash-yggdrasil = { version = "0.12.0" }
unleash-types = { version = "0.13", features = ["openapi", "hashes"] }
unleash-yggdrasil = { version = "0.13.0" }
utoipa = { version = "4.2.3", features = ["actix_extras", "chrono"] }
utoipa-swagger-ui = { version = "7.1.0", features = ["actix-web"] }
[dev-dependencies]
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 @@ -283,7 +283,7 @@ mod tests {
ClientFeature, Constraint, Operator, Strategy, StrategyVariant,
};
use unleash_types::client_metrics::{
ClientMetricsEnv, ConnectViaBuilder, MetricBucket, ToggleStats,
ClientMetricsEnv, ConnectViaBuilder, MetricBucket, MetricsMetadata, ToggleStats,
};
use unleash_yggdrasil::EngineState;

Expand All @@ -310,6 +310,12 @@ mod tests {
},
},
environment: Some("development".into()),
metadata: MetricsMetadata {
platform_name: Some("test".into()),
platform_version: Some("1.0".into()),
sdk_version: Some("1.0".into()),
yggdrasil_version: None,
},
}))
.to_request()
}
Expand All @@ -329,9 +335,14 @@ mod tests {
environment: None,
instance_id: None,
interval: 10,
sdk_version: None,
started: Default::default(),
strategies: vec![],
metadata: MetricsMetadata {
platform_name: None,
platform_version: None,
sdk_version: None,
yggdrasil_version: None,
},
}],
metrics: vec![ClientMetricsEnv {
feature_name: "".to_string(),
Expand All @@ -341,6 +352,12 @@ mod tests {
yes: 0,
no: 0,
variants: Default::default(),
metadata: MetricsMetadata {
platform_name: None,
platform_version: None,
sdk_version: None,
yggdrasil_version: None,
},
}],
}))
.to_request()
Expand Down Expand Up @@ -407,6 +424,12 @@ mod tests {
yes: 1,
no: 0,
variants: HashMap::new(),
metadata: MetricsMetadata {
platform_name: None,
platform_version: None,
sdk_version: None,
yggdrasil_version: None
}
};

assert_eq!(found_metric.yes, expected.yes);
Expand Down
13 changes: 12 additions & 1 deletion server/src/frontend_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ pub fn evaluate_feature(
payload: r.variant.payload,
},
impression_data: r.impression_data,
impressionData: r.impression_data
})
.ok_or_else(|| EdgeError::FeatureNotFound(feature_name.clone()))
}
Expand Down Expand Up @@ -735,6 +736,7 @@ pub fn frontend_from_yggdrasil(
payload: resolved.variant.payload.clone(),
},
impression_data: resolved.impression_data,
impressionData: resolved.impression_data
})
.collect::<Vec<EvaluatedToggle>>();
FrontendResult { toggles }
Expand Down Expand Up @@ -792,7 +794,7 @@ mod tests {
use std::str::FromStr;
use std::sync::Arc;
use tracing_test::traced_test;
use unleash_types::client_metrics::ClientMetricsEnv;
use unleash_types::client_metrics::{ClientMetricsEnv, MetricsMetadata};
use unleash_types::{
client_features::{ClientFeature, ClientFeatures, Constraint, Operator, Strategy},
frontend::{EvaluatedToggle, EvaluatedVariant, FrontendResult},
Expand Down Expand Up @@ -1005,6 +1007,7 @@ mod tests {
payload: None,
},
impression_data: false,
impressionData: false
}],
};

Expand Down Expand Up @@ -1062,6 +1065,7 @@ mod tests {
payload: None,
},
impression_data: false,
impressionData: false
}],
};

Expand Down Expand Up @@ -1117,6 +1121,7 @@ mod tests {
payload: None,
},
impression_data: false,
impressionData: false
}],
};

Expand Down Expand Up @@ -1192,6 +1197,12 @@ mod tests {
yes: 1,
no: 0,
variants: HashMap::new(),
metadata: MetricsMetadata {
platform_name: None,
platform_version: None,
sdk_version: None,
yggdrasil_version: None,
},
};

assert_eq!(found_metric.yes, expected.yes);
Expand Down
9 changes: 7 additions & 2 deletions server/src/http/feature_refresher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dashmap::DashMap;
use reqwest::StatusCode;
use tracing::{debug, info, warn};
use unleash_types::client_features::Segment;
use unleash_types::client_metrics::ClientApplication;
use unleash_types::client_metrics::{ClientApplication, MetricsMetadata};
use unleash_types::{
client_features::{ClientFeature, ClientFeatures},
Deduplicate,
Expand Down Expand Up @@ -124,9 +124,14 @@ 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)),
started: Utc::now(),
strategies: vec![],
metadata: MetricsMetadata {
platform_name: None,
platform_version: None,
sdk_version: Some(format!("unleash-edge:{}", build::PKG_VERSION)),
yggdrasil_version: None
}
}
}

Expand Down
Loading

0 comments on commit 9795c7c

Please sign in to comment.