Skip to content

Commit

Permalink
feat: add analysis url
Browse files Browse the repository at this point in the history
  • Loading branch information
SSebo committed Feb 20, 2023
1 parent da89e60 commit a0a4a27
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 54 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "feature-probe-server"
version = "1.3.13"
version = "2.0.1"
license = "Apache-2.0"
authors = ["[email protected]"]
description = "FeatureProbe Server for evaluating feature toggles"
Expand Down Expand Up @@ -51,11 +51,11 @@ tracing-subscriber = { version = "0.3", features = [
] }
url = "2.3"
socketio-rs = { optional = true, version = "0.1.7", default-features = false, features = ["server"] }
feature-probe-server-sdk = { version = "1.2.9", features = [
feature-probe-server-sdk = { version="1.2.12", features = [
"internal",
"use_tokio",
], default-features = false }
feature-probe-event = { version = "1.0.5", features = [
feature-probe-event = { version="1.1.3", features = [
"use_tokio",
"collector",
], default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ RUN update-ca-certificates

WORKDIR /app
COPY . /app
WORKDIR /app/server

RUN rustc -V
RUN cargo build --release --verbose

FROM debian:buster-slim
COPY --from=build /app/target/release/feature_probe_server .
COPY --from=build /app/server/target/release/feature_probe_server .

CMD [ "./feature_probe_server" ]

4 changes: 4 additions & 0 deletions examples/local_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ async fn main() {
))
.unwrap();
let events_url = Url::parse(&format!("http://0.0.0.0:{}/api/events", api_port)).unwrap();
let analysis_url =
Some(Url::parse(&format!("http://0.0.0.0:{}/analysis/events", api_port)).unwrap());
let refresh_seconds = Duration::from_secs(1);
let config = ServerConfig {
toggles_url,
events_url: events_url.clone(),
keys_url: None,
analysis_url: None,
refresh_interval: refresh_seconds,
client_sdk_key: Some(client_sdk_key.clone()),
server_sdk_key: Some(server_sdk_key.clone()),
Expand All @@ -57,6 +60,7 @@ async fn main() {
let feature_probe_server = FpHttpHandler {
repo: repo.clone(),
events_url,
analysis_url,
events_timeout: refresh_seconds,
http_client: Default::default(),
};
Expand Down
15 changes: 15 additions & 0 deletions resources/fixtures/repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,20 @@
}
]
}
},
"events": {
"c52d1e0fd380f432a21f4743d59b26a0": {
"name": "c52d1e0fd380f432a21f4743d59b26a0",
"type": "PAGE_VIEW",
"matcher": "SIMPLE",
"url": "https://127.0.0.1/test"
},
"b62d1e0fd380f432a21f47sss29b26a0": {
"name": "b62d1e0fd380f432a21f47sss29b26a0",
"type": "CLICK",
"matcher": "SIMPLE",
"url": "https://127.0.0.1/test",
"selector": "#DEMO"
}
}
}
26 changes: 25 additions & 1 deletion src/base.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use feature_probe_server_sdk::Url;
use log::warn;
use serde::Deserialize;
use std::{fmt::Display, time::Duration};
use thiserror::Error;
Expand Down Expand Up @@ -30,6 +31,7 @@ pub struct ServerConfig {
pub toggles_url: Url,
pub events_url: Url,
pub keys_url: Option<Url>,
pub analysis_url: Option<Url>,
pub refresh_interval: Duration,
pub server_sdk_key: Option<String>,
pub client_sdk_key: Option<String>,
Expand Down Expand Up @@ -103,6 +105,22 @@ impl ServerConfig {
}
};

let analysis_url = match config.get_string("analysis_url") {
Ok(url) => match Url::parse(&url) {
Err(e) => {
return Err(FPServerError::ConfigError(format!(
"INVALID FP_ANALYSIS_URL: {}",
e,
)))
}
Ok(u) => Some(u),
},
Err(_) => {
warn!("NOT SET FP_ANALYSIS_URL");
None
}
};

let refresh_interval = match config.get_int("refresh_seconds") {
Err(_) => {
return Err(FPServerError::ConfigError(
Expand Down Expand Up @@ -131,6 +149,7 @@ impl ServerConfig {
Ok(ServerConfig {
toggles_url,
events_url,
analysis_url,
keys_url,
refresh_interval,
client_sdk_key,
Expand All @@ -150,10 +169,15 @@ impl Display for ServerConfig {
None => "None".to_owned(),
Some(s) => s.to_string(),
};
write!(f, "server_port {}, toggles_url {}, events_url {}, keys_url {}, refresh_interval {:?}, client_sdk_key {:?}, server_sdk_key {:?}",
let analysis_url = match &self.analysis_url {
None => "None".to_owned(),
Some(s) => s.to_string(),
};
write!(f, "server_port {}, toggles_url {}, events_url {}, analysis_url {}, keys_url {}, refresh_interval {:?}, client_sdk_key {:?}, server_sdk_key {:?}",
self.server_port,
self.toggles_url,
self.events_url,
analysis_url,
keys_url,
self.refresh_interval,
self.client_sdk_key,
Expand Down
Loading

0 comments on commit a0a4a27

Please sign in to comment.