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 flagsmith on flagsmith feature export task #3149

Merged
merged 13 commits into from
Dec 14, 2023

Conversation

zachaysan
Copy link
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have run pre-commit to check linting
  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

This enables the easy export of Flagsmith feature flag features through the existing feature import export module. By setting two new settings constants, one for the target environment id and one for the tag id that will be selected for the feature flags that are to be exported, a daily background task will create new export ids which are saved through a new model. The most recent of which will be served through the download endpoint which is fixed and open to all without authentication.

How did you test this code?

Three new tests. The actual data itself is assert in both the task generation test and the view test.

Copy link

vercel bot commented Dec 12, 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 Dec 14, 2023 6:50pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 14, 2023 6:50pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 14, 2023 6:50pm

@github-actions github-actions bot added the api Issue related to the REST API label Dec 12, 2023
@zachaysan zachaysan changed the title Feat/create flagsmith on flagsmith feature export task feat: Create flagsmith on flagsmith feature export task Dec 12, 2023
Copy link
Contributor

github-actions bot commented Dec 12, 2023

Uffizzi Preview deployment-42669 was deleted.

@codecov-commenter
Copy link

codecov-commenter commented Dec 12, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (9c475e4) 96.11% compared to head (6709b33) 96.10%.

Files Patch % Lines
api/features/import_export/tasks.py 80.00% 3 Missing ⚠️
api/features/import_export/views.py 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3149      +/-   ##
==========================================
- Coverage   96.11%   96.10%   -0.01%     
==========================================
  Files        1058     1059       +1     
  Lines       31918    31995      +77     
==========================================
+ Hits        30677    30750      +73     
- Misses       1241     1245       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 209 to 217
@register_recurring_task(
run_every=timedelta(hours=24),
)
def create_flagsmith_on_flagsmith_feature_export():
if (
not settings.FLAGSMITH_ON_FLAGSMITH_FEATURE_EXPORT_ENVIRONMENT_ID
or not settings.FLAGSMITH_ON_FLAGSMITH_FEATURE_EXPORT_TAG_ID
):
# No explicit settings on both feature settings, hence exit.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest that probably the settings filter should be before we register the recurring task, otherwise it might be a little odd for self hosted people that see the task registered.

e.g.

if (settings.FLAGSMITH_ON_FLAGSMITH_FEATURE_EXPORT_ENVIRONMENT_ID and settings.FLAGSMITH_ON_FLAGSMITH_FEATURE_EXPORT_TAG_ID):
    @register_recurring_task(
        run_every=timedelta(hours=24),
    )
    def create_flagsmith_on_flagsmith_feature_export():
        ...

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 we chatted briefly on Slack, there is the issue of importing this so in the mean time I've wrapped a private function and used it in conjunction with your suggestion to keep the task from queuing for the other clients.

Comment on lines 81 to 88
class FlagsmithOnFlagsmithFeatureExport(models.Model):
feature_export = models.ForeignKey(
FeatureExport,
related_name="flagsmith_on_flagsmith",
on_delete=models.CASCADE,
)

created_at = models.DateTimeField(auto_now_add=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I can certainly see why you went with this approach but I think I'd prefer to just have an attribute on the FeatureExport class. Just thinking it's slightly better aesthetics for the self hosted community where this functionality will be totally redundant. It'll be a redundant column vs a redundant table.

That being said, I don't have a massive preference here so if you think this is the cleanest approach, I'll take your word for it.

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 think it's better to keep the whole functionality limited to it's own class. I can see FeatureExport getting expanded and used more and more as the functionality evolves and every dev investigating it will see a field that is used almost none of the time and it will clutter up the definition of the FeatureExport class. I think it's better to just have a single class here which self-describes itself. Plus, if there are any other features we decide to implement in the future, like say hold onto different versions of flagsmith for download, we can add it to the FlagsmithOnFlagsmithFeatureExport class.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, fair enough. Happy with this approach in that case. Maybe we should add a docstring to the model however, to help explain it's purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea I'll add it before merging the PR.

@zachaysan zachaysan added this pull request to the merge queue Dec 14, 2023
Merged via the queue into main with commit e74ba0f Dec 14, 2023
@zachaysan zachaysan deleted the feat/create_flagsmith_on_flagsmith_feature_export_task branch December 14, 2023 18:56
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.

3 participants