Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flags): return real feature flag evaluation for basic matching with new endpoint #24358

Merged
merged 15 commits into from
Aug 22, 2024

Conversation

dmarticus
Copy link
Contributor

@dmarticus dmarticus commented Aug 13, 2024

The new Rust /flags endpoint now works end-to-end locally! With this change, you can now do the following:

  • start the Rust service with RUST_LOG=debug cargo run --bin feature-flags
  • call the endpoint with /decide-looking requests, e.g.
$ curl 'http://localhost:3001/flags?v=3&ip=1&_=1723503992996&ver=1.154.3' \
  -H 'Accept: */*' \
  -H 'Accept-Language: en-US,en;q=0.9,es;q=0.8,fi;q=0.7,sv;q=0.6' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Origin: https://localhost:3000' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: cross-site' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  --data '{ "token": "phc_URYUdLWjF3NSKKw0futdm41Owob0wAhJLxPku9LaQ0Q", "distinct_id": "019148eb-b78e-7339-bfaf-d6eebfcdeec1", "groups": {} }'
{"errorWhileComputingFlags":false,"featureFlags":{"first-experiment":"control","survey-targeting-a4ea8007c0":true,"survey-targeting-89ad32a148":true,"survey-targeting-20596c69b7-custom":true,"half-of-people":false,"zenhog":true,"surveys-events":true,"survey-targeting-c14f2cb42f":true,"survey-targeting-b35c7ea672-custom":true}}

Doesn't support gzip or any compression yet. Supports both Redis and Postgres for returning flag and team definitions. Only supports a subset of matching logic.

@dmarticus dmarticus marked this pull request as draft August 13, 2024 23:22
@@ -98,7 +127,7 @@ impl IntoResponse for FlagError {
(StatusCode::BAD_REQUEST, "The distinct_id field is missing from the request. Please include a valid identifier.".to_string())
}
FlagError::NoTokenError => {
(StatusCode::UNAUTHORIZED, "No API key provided. Please include a valid API key in your request.".to_string())
(StatusCode::UNAUTHORIZED, "No API token provided. Please include a valid API token in your request.".to_string())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we should call it a key or a token, lol. We'll pick one on which to standardize.

@@ -8,10 +8,10 @@ pub struct Config {
#[envconfig(default = "127.0.0.1:3001")]
pub address: SocketAddr,

#[envconfig(default = "postgres://posthog:posthog@localhost:5432/test_posthog")]
#[envconfig(default = "postgres://posthog:posthog@localhost:5432/posthog")]
Copy link
Contributor Author

@dmarticus dmarticus Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

real app uses real DB!

@dmarticus dmarticus requested a review from a team August 13, 2024 23:34
@dmarticus dmarticus marked this pull request as ready for review August 16, 2024 23:32
@jurajmajerik
Copy link
Contributor

Looking great as far as my Rust knowledge goes :D

Didn't run it, don't have Rust installed yet. Do we have a standard way to do this? Worth updating the docs too: https://posthog.com/handbook/engineering/developing-locally

@dmarticus
Copy link
Contributor Author

Didn't run it, don't have Rust installed yet. Do we have a standard way to do this? Worth updating the docs too: posthog.com/handbook/engineering/developing-locally

Yeah, the feature flag module readme has some instructions: https://github.com/PostHog/posthog/blob/feat/make-rust-decide-curlable/rust/feature-flags/README.md#L2-L53. But I was going to update the developing locally section once this service is more mature. I'll make a note in the checklist!

@dmarticus dmarticus merged commit d6ad9fa into master Aug 22, 2024
77 checks passed
@dmarticus dmarticus deleted the feat/make-rust-decide-curlable branch August 22, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants