Skip to content

Commit fbe846b

Browse files
committed
chore: realtime registery json key renamed
1 parent 4a98fa3 commit fbe846b

File tree

7 files changed

+52
-31
lines changed

7 files changed

+52
-31
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ harness = false
1717
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1818

1919
[features]
20-
# default = ["use_std", "event"]
21-
default = ["use_tokio", "event_tokio", "realtime"]
20+
default = ["use_std", "event"]
2221
internal = []
2322
use_std = ["ureq"]
2423
event = ["feature-probe-event-std"]
@@ -57,7 +56,7 @@ reqwest = { optional = true, version = "0.11", default-features = false, feature
5756
tokio = { optional = true, version = "1", features = ["full"] }
5857
ureq = { optional = true, version = "2.4" }
5958

60-
socketio-rs = { optional = true, version = "0.1.5", default-features = false, features = ["client"] }
59+
socketio-rs = { optional = true, version = "0.1.7", default-features = false, features = ["client"] }
6160
futures-util = { optional = true, version = "0.3", default-features = false, features = [
6261
"sink",
6362
] }

examples/demo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use url::Url;
88
#[tokio::main]
99
async fn main() -> Result<(), FPError> {
1010
tracing_subscriber::fmt::init();
11-
// let remote_url = "http://localhost:4009/server"; // for local docker
11+
// let remote_url = Url::parse("http://localhost:4009/server").unwrap(); // for local docker
1212
let remote_url = Url::parse("https://featureprobe.io/server").expect("invalid url");
13-
// Server SDK key in Project List Page.
13+
// Replace Server SDK key in your Project List Page.
1414
let server_sdk_key = "server-7fa2f771259cb7235b96433d70b91e99abcf6ff8".to_owned();
1515
let refresh_interval = Duration::from_secs(20);
1616

src/config.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,50 @@ pub struct FPConfig {
1010
pub remote_url: Url,
1111
pub toggles_url: Option<Url>,
1212
pub events_url: Option<Url>,
13-
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
14-
pub realtime_url: Option<Url>,
1513
pub server_sdk_key: String,
1614
pub refresh_interval: Duration,
1715
#[cfg(feature = "use_tokio")]
1816
pub http_client: Option<Client>,
1917
pub start_wait: Option<Duration>,
18+
19+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
20+
pub realtime_url: Option<Url>,
21+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
22+
pub realtime_path: Option<String>,
2023
}
2124

2225
#[derive(Debug, Clone)]
2326
pub(crate) struct Config {
24-
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
25-
pub realtime_url: Url,
2627
pub toggles_url: Url,
2728
pub events_url: Url,
2829
pub server_sdk_key: String,
2930
pub refresh_interval: Duration,
3031
#[cfg(feature = "use_tokio")]
3132
pub http_client: Option<Client>,
3233
pub start_wait: Option<Duration>,
34+
35+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
36+
pub realtime_url: Url,
37+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
38+
pub realtime_path: String,
3339
}
3440

3541
impl Default for FPConfig {
3642
fn default() -> Self {
3743
Self {
3844
server_sdk_key: "".to_owned(),
39-
remote_url: Url::parse("http://127.0.0.1:8080").unwrap(),
45+
remote_url: Url::parse("https://featureprobe.io/server").unwrap(),
4046
toggles_url: None,
4147
events_url: None,
4248
refresh_interval: Duration::from_secs(5),
4349
start_wait: None,
4450
#[cfg(feature = "use_tokio")]
4551
http_client: None,
52+
4653
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
4754
realtime_url: None,
55+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
56+
realtime_path: None,
4857
}
4958
}
5059
}
@@ -53,14 +62,18 @@ impl Default for Config {
5362
fn default() -> Self {
5463
Self {
5564
server_sdk_key: "".to_owned(),
56-
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
57-
realtime_url: Url::parse("http://127.0.0.1:9090").unwrap(), // TODO: set by config
58-
toggles_url: Url::parse("http://127.0.0.1:8080").unwrap(),
59-
events_url: Url::parse("http://127.0.0.1:8080").unwrap(),
60-
refresh_interval: Duration::from_secs(5),
65+
toggles_url: Url::parse("https://featureprobe.io/server/api/server-sdk/toggles")
66+
.unwrap(),
67+
events_url: Url::parse("https://featureprobe.io/server/api/events").unwrap(),
68+
refresh_interval: Duration::from_secs(60),
6169
start_wait: None,
6270
#[cfg(feature = "use_tokio")]
6371
http_client: None,
72+
73+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
74+
realtime_url: Url::parse("https://featureprobe.io/server/realtime").unwrap(),
75+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
76+
realtime_path: "/server/realtime".to_owned(),
6477
}
6578
}
6679
}
@@ -80,6 +93,12 @@ impl FPConfig {
8093
Some(url) => url.to_owned(),
8194
};
8295

96+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
97+
let realtime_path = match &self.realtime_path {
98+
Some(p) => p.to_owned(),
99+
None => realtime_url.path().to_owned(),
100+
};
101+
83102
let toggles_url = match &self.toggles_url {
84103
None => Url::parse(&(remote_url.clone() + "api/server-sdk/toggles"))
85104
.expect("invalid toggles url"),
@@ -101,6 +120,8 @@ impl FPConfig {
101120
http_client: self.http_client.clone(),
102121
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
103122
realtime_url,
123+
#[cfg(all(feature = "use_tokio", feature = "realtime"))]
124+
realtime_path,
104125
}
105126
}
106127
}

src/evaluate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ mod condition_tests {
789789
}
790790
"#;
791791

792-
let condition = serde_json::from_str::<Condition>(&json_str);
792+
let condition = serde_json::from_str::<Condition>(json_str);
793793
assert!(condition.is_ok());
794794
let condition = condition.unwrap();
795795
assert_eq!(condition.r#type, ConditionType::Unknown);

src/feature_probe.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,13 @@ impl FeatureProbe {
252252
fn connect_socket(&mut self) {
253253
let mut slf = self.clone();
254254
let slf2 = self.clone();
255+
let nsp = self.config.realtime_path.clone();
255256
tokio::spawn(async move {
256257
let url = slf.config.realtime_url;
257258
let server_sdk_key = slf.config.server_sdk_key.clone();
258259
tracing::trace!("connect_socket {}", url);
259260
let client = socketio_rs::ClientBuilder::new(url.clone())
260-
.namespace("/")
261+
.namespace(&nsp)
261262
.on(socketio_rs::Event::Connect, move |_, socket, _| {
262263
Self::socket_on_connect(socket, server_sdk_key.clone())
263264
})
@@ -285,7 +286,7 @@ impl FeatureProbe {
285286
trace!("socket_on_connect: {:?}", sdk_key);
286287
async move {
287288
if let Err(e) = socket
288-
.emit("register", serde_json::json!({ "sdk_key": sdk_key }))
289+
.emit("register", serde_json::json!({ "key": sdk_key }))
289290
.await
290291
{
291292
tracing::error!("register error: {:?}", e);
@@ -403,15 +404,15 @@ mod tests {
403404

404405
assert!(fp.bool_value("none_exist_toggle", &u, true));
405406
let d = fp.bool_detail("none_exist_toggle", &u, true);
406-
assert_eq!(d.value, true);
407+
assert!(d.value);
407408
assert_eq!(d.rule_index, None);
408409
}
409410

410411
#[test]
411412
fn test_for_ut() {
412413
let fp = FeatureProbe::new_for_test("toggle_1", Value::Bool(false));
413414
let u = FPUser::new();
414-
assert_eq!(fp.bool_value("toggle_1", &u, true), false);
415+
assert!(!fp.bool_value("toggle_1", &u, true));
415416

416417
let mut toggles: HashMap<String, Value> = HashMap::new();
417418
toggles.insert("toggle_2".to_owned(), json!(12.5));
@@ -460,7 +461,7 @@ mod server_sdk_contract_tests {
460461
pub(crate) fixture: Repository,
461462
}
462463

463-
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
464+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Eq)]
464465
#[serde(rename_all = "camelCase")]
465466
pub struct Case {
466467
pub(crate) name: String,
@@ -469,27 +470,27 @@ mod server_sdk_contract_tests {
469470
pub(crate) expect_result: ExpectResult,
470471
}
471472

472-
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
473+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Eq)]
473474
#[serde(rename_all = "camelCase")]
474475
pub struct User {
475476
pub(crate) key: String,
476477
pub(crate) custom_values: Vec<KeyValue>,
477478
}
478479

479-
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
480+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Eq)]
480481
pub struct KeyValue {
481482
pub(crate) key: String,
482483
pub(crate) value: String,
483484
}
484485

485-
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
486+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Eq)]
486487
pub struct Function {
487488
pub(crate) name: String,
488489
pub(crate) toggle: String,
489490
pub(crate) default: Value,
490491
}
491492

492-
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
493+
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Eq)]
493494
#[serde(rename_all = "camelCase")]
494495
pub struct ExpectResult {
495496
pub(crate) value: Value,
@@ -589,7 +590,7 @@ mod server_sdk_contract_tests {
589590
case.expect_result.value
590591
);
591592
}
592-
_ => assert!(false, "function name {} not found.", case.function.name),
593+
_ => panic!("function name {} not found.", case.function.name),
593594
}
594595
}
595596
}

src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ mod tests {
429429
TypedHeader(user_agent): TypedHeader<UserAgent>,
430430
) -> Json<Repository> {
431431
assert_eq!(sdk_key, "sdk-key");
432-
assert!(user_agent.to_string().len() > 0);
432+
assert!(!user_agent.to_string().is_empty());
433433
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
434434
path.push("resources/fixtures/repo.json");
435435
let json_str = fs::read_to_string(path).unwrap();

0 commit comments

Comments
 (0)