Skip to content

Commit

Permalink
feat: parse created_at and environment field in UFC response
Browse files Browse the repository at this point in the history
  • Loading branch information
rasendubi committed Jul 18, 2024
1 parent ec59b05 commit 890378a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion eppo_core/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pub struct Configuration {
pub flags: Option<UniversalFlagConfig>,
/// Bandits configuration.
pub bandits: Option<BanditResponse>,
/// Mapping from flag key to flag variation value to bandit variation.
/// Mapping from flag key to flag variation value to bandit variation. Cached from
/// `self.flags.bandits`.
pub flag_to_bandit_associations:
HashMap</* flag_key: */ String, HashMap</* variation_key: */ String, BanditVariation>>,
}
Expand Down
11 changes: 10 additions & 1 deletion eppo_core/src/configuration_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ impl ConfigurationStore {
mod tests {
use std::{collections::HashMap, sync::Arc};

use chrono::Utc;

use super::ConfigurationStore;
use crate::{ufc::UniversalFlagConfig, Configuration};
use crate::{
ufc::{Environment, UniversalFlagConfig},
Configuration,
};

#[test]
fn can_set_configuration_from_another_thread() {
Expand All @@ -58,6 +63,10 @@ mod tests {
let _ = std::thread::spawn(move || {
store.set_configuration(Configuration::new(
Some(UniversalFlagConfig {
created_at: Utc::now(),
environment: Environment {
name: "test".to_owned(),
},
flags: HashMap::new(),
bandits: HashMap::new(),
}),
Expand Down
13 changes: 13 additions & 0 deletions eppo_core/src/ufc/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ pub type Timestamp = chrono::DateTime<chrono::Utc>;
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct UniversalFlagConfig {
/// When configuration was last updated.
pub created_at: Timestamp,
/// Environment this configuration belongs to.
pub environment: Environment,
/// Flags configuration.
///
/// Value is wrapped in `TryParse` so that if we fail to parse one flag (e.g., new server
Expand All @@ -23,6 +27,13 @@ pub struct UniversalFlagConfig {
pub bandits: HashMap<String, Vec<BanditVariation>>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Environment {
/// Name of the environment.
pub name: String,
}

/// `TryParse` allows the subfield to fail parsing without failing the parsing of the whole
/// structure.
///
Expand Down Expand Up @@ -314,6 +325,8 @@ mod tests {
let ufc: UniversalFlagConfig = serde_json::from_str(
&r#"
{
"createdAt": "2024-07-18T00:00:00Z",
"environment": {"name": "test"},
"flags": {
"success": {
"key": "success",
Expand Down
1 change: 1 addition & 0 deletions rust-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ serde_json = "1.0.116"
name = "simple"

[dev-dependencies]
chrono = "0.4.38"
env_logger = { version = "0.11.3", features = ["unstable-kv"] }
9 changes: 8 additions & 1 deletion rust-sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ mod tests {
use crate::{client::AssignmentValue, Client, ClientConfig};
use eppo_core::{
configuration_store::ConfigurationStore,
ufc::{Allocation, Flag, Split, TryParse, UniversalFlagConfig, Variation, VariationType},
ufc::{
Allocation, Environment, Flag, Split, TryParse, UniversalFlagConfig, Variation,
VariationType,
},
Configuration,
};

Expand Down Expand Up @@ -393,6 +396,10 @@ mod tests {
// updating configuration after client is created
configuration_store.set_configuration(Configuration::new(
Some(UniversalFlagConfig {
created_at: chrono::Utc::now(),
environment: Environment {
name: "test".to_owned(),
},
flags: [(
"flag".to_owned(),
TryParse::Parsed(Flag {
Expand Down

0 comments on commit 890378a

Please sign in to comment.