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

Feature/support feature flags #12

Closed
wants to merge 15 commits into from
Closed

Feature/support feature flags #12

wants to merge 15 commits into from

Conversation

imhmdb
Copy link
Contributor

@imhmdb imhmdb commented Jun 4, 2021

Follows spec for implementing feature flags support:
https://github.com/PostHog/posthog.com/pull/1455/files

@yakkomajuri yakkomajuri self-requested a review June 7, 2021 10:57
Copy link
Contributor

@yakkomajuri yakkomajuri left a comment

Choose a reason for hiding this comment

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

Hey, thanks a lot for this! Appreciate you submitting it upstream.

Left one inline comment, but overall looking good. Some thoughts:

  1. I'm happy to merge this with only LibCurl support
  2. Some tests that mock the endpoint response and verify that the code handles the response appropriately should be enough.
  3. This implementation appears correct and is an improvement over what we currently have (no feature flags), so it should be valid to merge. However, I'd appreciate if you could consider adding support for is_simple_flag (see Python lib). I'm adding feature flags to posthog-node this week and will write a spec for implementing flags in other libraries. Essentially, for is_simple_flag, we use a Personal API Key to poll for flags and if they're "simple" (only rollout percentage, no filters), we calculate them locally for speed. This can definitely be a separate PR and I'm happy to help.

lib/Consumer/LibCurl.php Outdated Show resolved Hide resolved
@yakkomajuri yakkomajuri added this to To Do Next Sprint (1.27 1/2) in Extensibility Jun 7, 2021
@yakkomajuri yakkomajuri self-assigned this Jun 7, 2021
@Twixes Twixes moved this from To Do This Sprint (1.27 1/2) to In Progress in Extensibility Jun 8, 2021
@yakkomajuri
Copy link
Contributor

Node is done and the "spec" is written

@imhmdb are you planning on making the changes here? totally understand if not, just checking

@imhmdb imhmdb closed this Jun 9, 2021
@imhmdb imhmdb reopened this Jun 9, 2021
@imhmdb
Copy link
Contributor Author

imhmdb commented Jun 9, 2021

Node is done and the "spec" is written

@imhmdb are you planning on making the changes here? totally understand if not, just checking

of course, I'll give it a shot today and see how it goes.

@imhmdb imhmdb requested a review from yakkomajuri June 10, 2021 17:49
@imhmdb
Copy link
Contributor Author

imhmdb commented Jun 10, 2021

I think this only needs to have tests fixed with mocks

@imhmdb imhmdb changed the title (WIP) Feature/support feature flags decide API Feature/support feature flags decide API Jun 12, 2021
@imhmdb
Copy link
Contributor Author

imhmdb commented Jun 12, 2021

Done fixing tests with the mocked response of simple flags.

@imhmdb imhmdb changed the title Feature/support feature flags decide API Feature/support feature flags Jun 12, 2021
@yakkomajuri
Copy link
Contributor

Awesome, thanks a lot! I'll give this a review latest by tomorrow

Copy link
Contributor

@yakkomajuri yakkomajuri left a comment

Choose a reason for hiding this comment

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

This is awesome! Follows the spec perfectly for the most part (see below). I'm about to test it locally and will report back.

Thanks again for doing this.

One final comment that just came to mind: should we also error out if people chose not to use libcurl and they try to use feature flags?

private function loadFeatureFlags(): void
{
$response = $this->httpClient->sendRequest(
'/api/feature_flag',
Copy link
Contributor

Choose a reason for hiding this comment

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

We've made a change since you last edited this, so this should now be /api/feature_flag?token=project_api_key_here.

No way you could have known though!

$this->featureFlags = [];
}

$this->featureFlags = $responseBody['results'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Another change we made is that this should filter by active flags.

The active property is in $responseBody['results'][i]['active']

{
$this->assertIsArray(PostHog::fetchEnabledFeatureFlags('user-id'));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

could we add a test for isSimpleFlagEnabled?

Flag of key a with distinct id b should be on for rollout percentage 42 but off for rollout percentage 40

Extensibility automation moved this from In Progress to In Review/Pending Deployment Jun 16, 2021
Copy link
Contributor

@yakkomajuri yakkomajuri left a comment

Choose a reason for hiding this comment

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

Having tried this and re-read the code - there are a few issues. First is a POST request to api/feature_flag. Second is that we're missing a poller. We shouldn't load feature flags once, we should load them regularly at an interval in the background.


private function loadFeatureFlags(): void
{
$response = $this->httpClient->sendRequest(
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok so I tried this locally and it didn't work. I suspect this is a potential problem. We're sending a POST request here, when it should actually be a GET request.

@imhmdb
Copy link
Contributor Author

imhmdb commented Jun 16, 2021

This is awesome! Follows the spec perfectly for the most part (see below). I'm about to test it locally and will report back.

Thanks again for doing this.

One final comment that just came to mind: should we also error out if people chose not to use libcurl and they try to use feature flags?

Hi, @yakkomajuri

Regarding the libcurl error, when I reimplemented according to spec I moved the feature flags from libcurl consumer into the client, not sure if you mean ext-curl and not the libcurl-posthog-consumer here, cuz that would be a valid case to error on.

Regarding the poller, I wasn't sure how can I keep polling at an interval when php doesn't supports threads or pools, have this poller been implemented in a php-like client that I can take insights from?

Regarding the errors on the POST request, this sure is weird As I made sure the tests were working on my production environment keys instead of debug ones, but maybe the tests were also broken 😂

I'll sure take a second look and try to debug and fix the addressed issues.

Side note: I just got out of surgery so it might take me a week or two of recovery until I can get my hands on this thing again, just letting you guys know.

@yakkomajuri
Copy link
Contributor

I could also be at fault here - not a PHP dev, so if anything I say sounds crazy, it probably is.

Also, get better! No rush!

I might also pick this up if I get the time.

Thanks again for all your work @imhmdb

@yakkomajuri
Copy link
Contributor

Closing in favor of #18

@posthog-bot please add @imhmdb for code

@posthog-contributions-bot
Copy link

@yakkomajuri

I've put up a pull request to add @imhmdb! 🎉

@Twixes
Copy link
Contributor

Twixes commented Jul 16, 2021

@posthog-bot please add @imhmdb for code

@posthog-contributions-bot
Copy link

@Twixes

@imhmdb we tried to send you an email with a merch code but that failed :(
We didn't give up on getting you some merch though, so email yakko [at] posthog [.] com and he'll send you a code!

@Twixes
Copy link
Contributor

Twixes commented Jul 16, 2021

@posthog-bot please add @imhmdb for code

@posthog-contributions-bot
Copy link

@Twixes

I've put up a pull request to add @imhmdb! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Extensibility
In Review/Pending Deployment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants