Skip to content

Commit b6425f4

Browse files
authored
perf: chore: flagd: Update dependencies, reuse reqwest client for better performance, add cargo audit to CI (#47)
Signed-off-by: Eren Atas <[email protected]>
1 parent 7959cf3 commit b6425f4

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

.github/workflows/flagd-check.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ jobs:
3939
run: |
4040
cargo readme --no-title --no-license > README.md.generated
4141
diff README.md README.md.generated
42+
43+
- name: Install and run cargo-audit
44+
run: |
45+
cargo install cargo-audit --locked
46+
# Run from root directory where Cargo.lock is located
47+
cargo audit
4248

crates/flagd/Cargo.toml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,35 @@ include = [
2121
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2222

2323
[build-dependencies]
24-
tonic-build = "0.12"
25-
prost = "0.13"
26-
prost-build = "0.13"
24+
tonic-build = "0.13"
2725

2826
[dev-dependencies]
2927
cucumber = "0.21"
3028
tokio-stream = "0.1"
3129
futures-core = "0.3"
3230
testcontainers = { version = "0.24.0", features = ["http_wait", "blocking"] }
3331
wiremock = "0.6.3"
34-
tempfile = "3.19.0"
32+
tempfile = "3.20.0"
3533
serial_test = "3.2"
36-
tracing-test = "0.2"
3734
test-log = { version = "0.2", features = ["trace"] }
3835

3936
[dependencies]
4037
open-feature = "0.2"
4138
async-trait = "0.1"
42-
tonic = { version = "0.12", features = ["tls"] }
39+
tonic = { version = "0.13" }
4340
prost = "0.13"
4441
prost-types = "0.13"
45-
tokio = { version = "1.44", features = ["full"] }
42+
tokio = { version = "1.45", features = ["full"] }
4643
serde_json = "1.0"
4744
serde = { version = "1.0", features = ["derive"] }
4845
lru = "0.14"
4946
futures = "0.3"
5047
reqwest = { version = "0.12", default-features = false, features = ["json", "stream", "rustls-tls"] }
5148
tracing = "0.1"
52-
tracing-subscriber = "0.3"
53-
anyhow = "1.0.97"
54-
regex = "1.11.1"
49+
anyhow = "1.0.98"
5550
semver = "1.0.26"
5651
murmurhash3 = "0.0.5"
5752
tower = "0.5"
5853
hyper-util = { version = "0.1", features = ["tokio"] }
5954
thiserror = "2.0"
60-
datalogic-rs = "3.0.22"
55+
datalogic-rs = "3.0.24"

crates/flagd/src/resolver/rest.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use open_feature::{
4848
EvaluationContext, EvaluationContextFieldValue, EvaluationError, EvaluationErrorCode,
4949
EvaluationResult, StructValue, Value,
5050
};
51+
use reqwest::Client;
5152
use serde_json;
5253
use tracing::{debug, error, instrument};
5354

@@ -60,6 +61,8 @@ pub struct RestResolver {
6061
endpoint: String,
6162
/// Provider metadata
6263
metadata: ProviderMetadata,
64+
/// HTTP client for making requests
65+
client: Client,
6366
}
6467

6568
impl RestResolver {
@@ -81,6 +84,7 @@ impl RestResolver {
8184
Self {
8285
endpoint,
8386
metadata: ProviderMetadata::new("flagd-rest-provider"),
87+
client: Client::new(),
8488
}
8589
}
8690
}
@@ -108,12 +112,13 @@ impl FeatureProvider for RestResolver {
108112
evaluation_context: &EvaluationContext,
109113
) -> EvaluationResult<ResolutionDetails<bool>> {
110114
debug!("Resolving boolean flag");
111-
let client = reqwest::Client::new();
115+
112116
let payload = serde_json::json!({
113117
"context": context_to_json(evaluation_context)
114118
});
115119

116-
let response = client
120+
let response = self
121+
.client
117122
.post(format!(
118123
"{}/ofrep/v1/evaluate/flags/{}",
119124
self.endpoint, flag_key
@@ -176,12 +181,13 @@ impl FeatureProvider for RestResolver {
176181
evaluation_context: &EvaluationContext,
177182
) -> EvaluationResult<ResolutionDetails<String>> {
178183
debug!("Resolving string flag");
179-
let client = reqwest::Client::new();
184+
180185
let payload = serde_json::json!({
181186
"context": context_to_json(evaluation_context)
182187
});
183188

184-
let response = client
189+
let response = self
190+
.client
185191
.post(format!(
186192
"{}/ofrep/v1/evaluate/flags/{}",
187193
self.endpoint, flag_key
@@ -247,12 +253,13 @@ impl FeatureProvider for RestResolver {
247253
evaluation_context: &EvaluationContext,
248254
) -> EvaluationResult<ResolutionDetails<f64>> {
249255
debug!("Resolving float flag");
250-
let client = reqwest::Client::new();
256+
251257
let payload = serde_json::json!({
252258
"context": context_to_json(evaluation_context)
253259
});
254260

255-
let response = client
261+
let response = self
262+
.client
256263
.post(format!(
257264
"{}/ofrep/v1/evaluate/flags/{}",
258265
self.endpoint, flag_key
@@ -313,12 +320,13 @@ impl FeatureProvider for RestResolver {
313320
evaluation_context: &EvaluationContext,
314321
) -> EvaluationResult<ResolutionDetails<i64>> {
315322
debug!("Resolving integer flag");
316-
let client = reqwest::Client::new();
323+
317324
let payload = serde_json::json!({
318325
"context": context_to_json(evaluation_context)
319326
});
320327

321-
let response = client
328+
let response = self
329+
.client
322330
.post(format!(
323331
"{}/ofrep/v1/evaluate/flags/{}",
324332
self.endpoint, flag_key
@@ -382,12 +390,13 @@ impl FeatureProvider for RestResolver {
382390
evaluation_context: &EvaluationContext,
383391
) -> EvaluationResult<ResolutionDetails<StructValue>> {
384392
debug!("Resolving struct flag");
385-
let client = reqwest::Client::new();
393+
386394
let payload = serde_json::json!({
387395
"context": context_to_json(evaluation_context)
388396
});
389397

390-
let response = client
398+
let response = self
399+
.client
391400
.post(format!(
392401
"{}/ofrep/v1/evaluate/flags/{}",
393402
self.endpoint, flag_key

0 commit comments

Comments
 (0)