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: Create a Growthbook server side provider #938

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

msamper
Copy link
Contributor

@msamper msamper commented Jun 7, 2024

This PR

  • adds a new OpenFeature GrowthBook server provider

How to test

Integrate OpenFeature into a test node server and set it up with this new GrowthBook provider. Ensure that GrowthBook flag evaluation works as expected using the OpenFeature API

How to set up OpenFeature with node

OpenFeature.setProvider(new GrowthbookProvider(gbContext, initOptions))

@msamper msamper requested a review from a team as a code owner June 7, 2024 19:24
@msamper msamper changed the title [feat] Create a Growthbook server side provider feat: Create a Growthbook server side provider Jun 7, 2024
@lukas-reining
Copy link
Member

Hey @msamper, great addition, I will have a look tomorrow!

@beeme1mr
Copy link
Member

Hi @msamper, could you please rebase this PR? It should resolve the E2E issue.

Signed-off-by: Michael Samper <msamper@growthbook.io>
Signed-off-by: Michael Samper <msamper@growthbook.io>
Signed-off-by: Michael Samper <msamper@growthbook.io>
Signed-off-by: Michael Samper <msamper@growthbook.io>
@msamper msamper force-pushed the msamper/growthbook-node-provider branch from b0201e3 to 52b9510 Compare June 12, 2024 02:36
@msamper
Copy link
Contributor Author

msamper commented Jun 12, 2024

Hi @msamper, could you please rebase this PR? It should resolve the E2E issue.

@beeme1mr I rebased on the main branch of my fork and it seems like there's still CI issues with the e2e and the lint-test-build. Should I be rebasing on open-feature:main instead?

Copy link
Member

@lukas-reining lukas-reining left a comment

Choose a reason for hiding this comment

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

Thanks @msamper this looks good!
I just have two comments regarding the EvaluationContext -> Attributes.
When these are resolved this looks great!

Comment on lines 67 to 70
if (!isEmpty(context)) {
// Add flag evaluation context and merge with existing context
await this.client.setAttributes({ ...this.client.getAttributes(), ...context });
}
Copy link
Member

Choose a reason for hiding this comment

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

The context is is not reset after the evaluations.
If am am not overseeing anything this would mean that if a first request with a context is done, and a second one is done with both, both would have the context set from the first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right. The context would remain the same across both requests unless it was overwritten. I wasn't sure if a merge was needed to support the Dynamic Context Paradigm that is expected for server providers, but realizing that maybe the OpenFeature server SDK handles the different evaluation context levels before calling these functions.

Copy link
Member

Choose a reason for hiding this comment

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

That's true, you do not need to merge here, the SDK does it.

But this still has an issue.
If you do an evaluation with a context, the attributes of the GrowthBook object are set.
If another evaluation with absolutely no context is done after that, the attributes from the last evaluation will be used as they are not overwritten again.

This also relates to the concurrency problem I wrote in the other comment.

Comment on lines 67 to 70
if (!isEmpty(context)) {
// Add flag evaluation context and merge with existing context
await this.client.setAttributes({ ...this.client.getAttributes(), ...context });
}
Copy link
Member

Choose a reason for hiding this comment

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

This could be problematic if setAttributes does network calls or so. Which I assume from here: https://github.com/growthbook/growthbook/blob/main/packages/sdk-js/src/GrowthBook.ts#L467

It could happen that we have a race condition here, if two evaluations with different context are done close to each other. In that case it might happen that the internal await this.refreshStickyBuckets();of client.setAttributes would take time, but the next evaluation is already started, where the attributes would be overwritten before the evaluation with that context has been done.

Copy link
Member

@toddbaert toddbaert Jun 17, 2024

Choose a reason for hiding this comment

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

I agree. That pattern looks more like our static context paradigm we use for client.

Is there a way to set attributes without mutating the client in any way? @msamper ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As of right now our SDK doesn't have a way of doing that. We could consider making some changes to our SDK to support passing in some attributes that take precedence over ones within the GrowthBook context. I'm looking into it to see what the level of effort is and if there's some better alternatives

@lukas-reining
Copy link
Member

lukas-reining commented Jun 14, 2024

Hi @msamper, could you please rebase this PR? It should resolve the E2E issue.

@beeme1mr I rebased on the main branch of my fork and it seems like there's still CI issues with the e2e and the lint-test-build. Should I be rebasing on open-feature:main instead?

Yes, open-feature:main should be your branch to rebase on @msamper.

Signed-off-by: Michael Samper <msamper@growthbook.io>
Signed-off-by: Michael Samper <msamper@growthbook.io>
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.

4 participants