Skip to content

Commit

Permalink
feat: implement semver strategy constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Meemaw committed Jul 16, 2023
1 parent 18410e6 commit fef9e78
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 35 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ log = "0.4.14"
murmur3 = "0.5.1"
rand = "0.8.4"
rustversion = "1.0.7"
semver = "1.0.18"
serde_json = "1.0.68"
serde_plain = "1.0.0"
surf = { version = "2.3.1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ UNLEASH_API_URL=http://127.0.0.1:4242/api \

or similar. The functional test suite looks for a manually setup set of
features. E.g. log into the Unleash UI on port 4242 and create a feature called
`default`.
`default` & `semver` with a `SEMVER_EQ` strategy constraint.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.3"
services:
web:
image: unleashorg/unleash-server:4.12.6
image: unleashorg/unleash-server:4.16.0
ports:
- "4242:4242"
environment:
Expand Down
22 changes: 19 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,29 @@ pub struct Constraint {
}

#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(tag = "operator", content = "values")]
#[serde(tag = "operator")]
#[cfg_attr(feature = "strict", serde(deny_unknown_fields))]
pub enum ConstraintExpression {
#[serde(rename = "IN")]
In(Vec<String>),
In(MultiValueExpression),
#[serde(rename = "NOT_IN")]
NotIn(Vec<String>),
NotIn(MultiValueExpression),
#[serde(rename = "SEMVER_EQ")]
SemverEq(SingleValueExpression),
#[serde(rename = "SEMVER_GT")]
SemverGt(SingleValueExpression),
#[serde(rename = "SEMVER_LT")]
SemverLt(SingleValueExpression),
}

#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct MultiValueExpression {
pub values: Vec<String>,
}

#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct SingleValueExpression {
pub value: String,
}

#[derive(Clone, Serialize, Deserialize, Debug)]
Expand Down
12 changes: 6 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,9 @@ where
self.polling.store(true, Ordering::Relaxed);
loop {
debug!("poll: retrieving features");
let res = self.http.get_json(&endpoint).await;
if let Ok(res) = res {
let features: Features = res;
match self.memoize(features.features) {
let res: Result<Features, C::Error> = self.http.get_json(&endpoint).await;
match res {
Ok(features) => match self.memoize(features.features) {
Ok(None) => {}
Ok(Some(metrics)) => {
if !self.disable_metric_submission {
Expand All @@ -800,9 +799,10 @@ where
Err(_) => {
warn!("poll: failed to memoize features");
}
},
Err(err) => {
warn!("poll: failed to retrieve features {}", err);
}
} else {
warn!("poll: failed to retrieve features");
}

let duration = Duration::from_millis(self.interval);
Expand Down
Loading

0 comments on commit fef9e78

Please sign in to comment.