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: integrate flagsmith client into API layer #2447

Merged
merged 18 commits into from
Sep 4, 2023

Conversation

matthewelwell
Copy link
Contributor

@matthewelwell matthewelwell commented Jul 14, 2023

Changes

Add Flagsmith to the API.

The main point of friction I found when implementing this is that we really need to be able to set the client into offline mode. If we could do that, then the logic to disable flagsmith requests for all self hosted deployments would be a lot simpler.

How did you test this code?

Added unit tests.

@vercel
Copy link

vercel bot commented Jul 14, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 31, 2023 11:18am
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 31, 2023 11:18am
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 31, 2023 11:18am

@github-actions github-actions bot added api Issue related to the REST API github labels Jul 14, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2023

Uffizzi Preview deployment-30959 was deleted.

@dabeeeenster
Copy link
Contributor

/awards worst PR title ever

@matthewelwell matthewelwell changed the title Add flagsmith chore: integration flagsmith client into API layer Jul 15, 2023
@matthewelwell
Copy link
Contributor Author

/awards worst PR title ever

😬 Yep, you got me...

@matthewelwell matthewelwell changed the title chore: integration flagsmith client into API layer chore: integrate flagsmith client into API layer Jul 17, 2023
Comment on lines 11 to 14
def reset_globals(mocker):
mocker.patch("integrations.flagsmith.client._defaults", None)
mocker.patch("integrations.flagsmith.client._flagsmith_client", None)
yield
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't love this, but managing the global variables is a bit painful (but necessary I think) and I don't think it's too bad since the fixture is used by every test in this module.

The tests in the previous iteration here were arguably cleaner, but I feel like the code itself to consume the flagsmith client was more messy.

Part of the issue that we have is the need to be able to switch Flagsmith off entirely and rely purely on the defaults. I guess there's an argument here that we should define an option in our SDKs to run in 'offline only' mode, for which we already have an issue here.

@matthewelwell matthewelwell marked this pull request as ready for review July 18, 2023 14:31
@matthewelwell matthewelwell requested review from a team and khvn26 July 18, 2023 14:31
@matthewelwell
Copy link
Contributor Author

I'm sceptical about committing the environment JSON to VCS, to be honest. I'd rather we use our own Change Requests feature for this, and fetch the file during Docker build. Maybe we'd like to think on a GitHub CR integration if we're keen to keep all reviews in one place.

@khvn26, I do agree with you here, however, not including some default data became very painful. The reason for this is that I don't want to enforce the logic in the Docker build since we have a docker-compose.yml in the root of the repo that builds the docker image from scratch. In that case though, we could fall back to requiring a FLAGSMITH_ON_FLAGSMITH_SERVER setup. Either of these options, however, would require us either shipping with the environment key (no no!) or requiring users to provide one (also, not great).

As such, what I have done here is updated the logic such that it masks any data that could be considered sensitive in the environment document (and isn't used by the engine).

Another option I considered is removing this constraint to allow the default handler to be a final fall back if the OfflineHandler fails.

What are your thoughts?

@dabeeeenster
Copy link
Contributor

I feel like we have to store the feature state in the repo/app. We also cant rely on people using docker - what if you want to use buildpacks or heroku or similar?

@matthewelwell
Copy link
Contributor Author

I feel like we have to store the feature state in the repo/app. We also cant rely on people using docker - what if you want to use buildpacks or heroku or similar?

Yep, that's a good point. I think, in that case, the solution I have here is the best we can do. Keen to know what @khvn26 thinks, however.

@dabeeeenster
Copy link
Contributor

I feel like we have to store the feature state in the repo/app. We also cant rely on people using docker - what if you want to use buildpacks or heroku or similar?

Yep, that's a good point. I think, in that case, the solution I have here is the best we can do. Keen to know what @khvn26 thinks, however.

Yep I think having a hard dependency on docker is not the right path. This feature behaviour configuration just so happens to be encoded in a json file. I don't think there's that much wrong with that. Projects like https://cerbos.dev/ encode permissions in JSON!

@matthewelwell matthewelwell requested a review from khvn26 August 2, 2023 09:55
api/integrations/flagsmith/flagsmith_service.py Outdated Show resolved Hide resolved
api/requirements.in Outdated Show resolved Hide resolved
# Conflicts:
#	api/app/settings/common.py
@mvrhov
Copy link

mvrhov commented Sep 6, 2023

I'm trying to find a documentation on how I can use this instead of polluting the only project that can be used in self hosted open source version with flagsmith flags.

@matthewelwell
Copy link
Contributor Author

Hi @mvrhov, that's not currently possible. I would recommend creating a separate organisation to contain the project for flagsmith flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants