Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
feat(flags): Add basic property matching (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkakkar authored Jun 10, 2024
1 parent f28466a commit f6569a7
Show file tree
Hide file tree
Showing 7 changed files with 1,694 additions and 6 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions feature-flags/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serde_json = { workspace = true }
thiserror = { workspace = true }
serde-pickle = { version = "1.1.1"}
sha1 = "0.10.6"
regex = "1.10.4"

[lints]
workspace = true
Expand Down
36 changes: 36 additions & 0 deletions feature-flags/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# Testing

```
cargo test --package feature-flags
```

### To watch changes

```
brew install cargo-watch
```

and then run:

```
cargo watch -x test --package feature-flags
```

To run a specific test:

```
cargo watch -x "test --package feature-flags --lib -- property_matching::tests::test_match_properties_math_operators --exact --show-output"
```

# Running

```
RUST_LOG=debug cargo run --bin feature-flags
```

# Format code

```
cargo fmt --package feature-flags
```
5 changes: 4 additions & 1 deletion feature-flags/src/flag_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const TEAM_FLAGS_CACHE_PREFIX: &str = "posthog:1:team_feature_flags_";
#[derive(Debug, Deserialize)]
pub enum GroupTypeIndex {}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum OperatorType {
Exact,
Expand All @@ -39,6 +39,9 @@ pub enum OperatorType {
#[derive(Debug, Clone, Deserialize)]
pub struct PropertyFilter {
pub key: String,
// TODO: Probably need a default for value?
// incase operators like is_set, is_not_set are used
// not guaranteed to have a value, if say created via api
pub value: serde_json::Value,
pub operator: Option<OperatorType>,
#[serde(rename = "type")]
Expand Down
1 change: 0 additions & 1 deletion feature-flags/src/flag_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ impl FeatureFlagMatcher {
hasher.update(hash_key.as_bytes());
let result = hasher.finalize();
// :TRICKY: Convert the first 15 characters of the digest to a hexadecimal string
// not sure if this is correct, padding each byte as 2 characters
let hex_str: String = result.iter().fold(String::new(), |mut acc, byte| {
let _ = write!(acc, "{:02x}", byte);
acc
Expand Down
1 change: 1 addition & 0 deletions feature-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod api;
pub mod config;
pub mod flag_definitions;
pub mod flag_matching;
pub mod property_matching;
pub mod redis;
pub mod router;
pub mod server;
Expand Down
Loading

0 comments on commit f6569a7

Please sign in to comment.