-
Notifications
You must be signed in to change notification settings - Fork 551
feat(Environments): Track first evaluation with a new Onboarding interface #8063
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
Merged
+644
−24
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
99c6e79
red stuff
emyller 24b67eb
let there be data
emyller 4cf4b70
green stuff
emyller 3eb3773
go international 🌐
emyller 7922b5f
🪵
emyller 772ad1b
nah
emyller 17a7f4d
yay anyway
emyller 797590a
404
emyller edad9ab
clone but offboard it
emyller 01064ba
fix api spec
emyller 9f6b6be
wait it
emyller 1fedc19
smithers-only
emyller b0ef881
tweak api visibility
emyller 2197c0b
chore: Update documentation artefacts
flagsmith-engineering[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
api/environments/migrations/0038_add_first_evaluated_fields.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Generated by Django 5.2.16 on 2026-07-20 22:50 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("environments", "0037_add_uuid_field"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="environment", | ||
| name="first_evaluated_at", | ||
| field=models.DateTimeField( | ||
| blank=True, | ||
| help_text="When the environment's flags were first evaluated by an SDK.", | ||
| null=True, | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="environment", | ||
| name="first_evaluated_sdk_label", | ||
| field=models.CharField( | ||
| blank=True, | ||
| help_text="SDK that first evaluated the environment's flags.", | ||
| max_length=100, | ||
| null=True, | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="historicalenvironment", | ||
| name="first_evaluated_at", | ||
| field=models.DateTimeField( | ||
| blank=True, | ||
| help_text="When the environment's flags were first evaluated by an SDK.", | ||
| null=True, | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="historicalenvironment", | ||
| name="first_evaluated_sdk_label", | ||
| field=models.CharField( | ||
| blank=True, | ||
| help_text="SDK that first evaluated the environment's flags.", | ||
| max_length=100, | ||
| null=True, | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from typing import get_args | ||
|
|
||
| from rest_framework import serializers | ||
|
|
||
| from app_analytics.types import KnownSDK | ||
| from environments.models import Environment | ||
|
|
||
|
|
||
| class EnvironmentOnboardingStatusSerializer(serializers.ModelSerializer[Environment]): | ||
| class Meta: | ||
| model = Environment | ||
| fields = ("first_evaluated_at", "first_evaluated_sdk_label") | ||
|
|
||
|
|
||
| class EnvironmentOnboardingStatusUpdateSerializer(serializers.Serializer[None]): | ||
| first_evaluated_sdk_label = serializers.ChoiceField(choices=get_args(KnownSDK)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import structlog | ||
| from django.utils import timezone | ||
|
|
||
| from app_analytics.types import KnownSDK | ||
| from environments.models import Environment | ||
|
|
||
| logger = structlog.get_logger("onboarding") | ||
|
|
||
|
|
||
| def record_environment_first_evaluation( | ||
| environment: Environment, | ||
| sdk_label: KnownSDK, | ||
| ) -> None: | ||
| """Mark this environment as having been evaluated by a client SDK.""" | ||
| log = logger.bind( | ||
| environment__id=environment.id, | ||
| project__id=environment.project_id, | ||
| organisation__id=environment.project.organisation_id, | ||
| sdk__label=sdk_label, | ||
| ) | ||
|
|
||
| if environment.first_evaluated_at is not None: | ||
| log.info("environment.already_evaluated") | ||
| return | ||
|
|
||
| environment.first_evaluated_at = timezone.now() | ||
|
emyller marked this conversation as resolved.
|
||
| environment.first_evaluated_sdk_label = sdk_label | ||
| environment.save(update_fields=["first_evaluated_at", "first_evaluated_sdk_label"]) | ||
|
|
||
| Environment.write_environment_documents(environment_id=environment.id) | ||
|
|
||
| log.info("environment.first_evaluated") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from django.urls import path | ||
|
|
||
| from environments.onboarding.views import EnvironmentOnboardingStatusAPIView | ||
|
|
||
| app_name = "onboarding" | ||
|
|
||
| urlpatterns = [ | ||
| path( | ||
| "", | ||
| EnvironmentOnboardingStatusAPIView.as_view(), | ||
| name="onboarding-status", | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| from drf_spectacular.utils import extend_schema | ||
| from rest_framework import status | ||
| from rest_framework.generics import RetrieveAPIView | ||
| from rest_framework.request import Request | ||
| from rest_framework.response import Response | ||
|
|
||
| from environments.models import Environment | ||
| from environments.onboarding.serializers import ( | ||
| EnvironmentOnboardingStatusSerializer, | ||
| EnvironmentOnboardingStatusUpdateSerializer, | ||
| ) | ||
| from environments.onboarding.services import record_environment_first_evaluation | ||
|
|
||
|
|
||
| class EnvironmentOnboardingStatusAPIView(RetrieveAPIView[Environment]): | ||
| """Obtain information on whether features for this environment have been evaluated yet.""" | ||
|
|
||
| authentication_classes = () | ||
| permission_classes = () | ||
| throttle_classes = [] | ||
|
|
||
| queryset = Environment.objects.select_related("project") | ||
| lookup_field = "api_key" | ||
| lookup_url_kwarg = "environment_api_key" | ||
| serializer_class = EnvironmentOnboardingStatusSerializer | ||
|
|
||
| @extend_schema(exclude=True) | ||
| def put(self, request: Request, environment_api_key: str) -> Response: | ||
|
khvn26 marked this conversation as resolved.
|
||
| """Mark this environment as having been evaluated by a client SDK.""" | ||
| serializer = EnvironmentOnboardingStatusUpdateSerializer(data=request.data) | ||
| serializer.is_valid(raise_exception=True) | ||
| record_environment_first_evaluation( | ||
| environment=self.get_object(), | ||
| sdk_label=serializer.validated_data["first_evaluated_sdk_label"], | ||
| ) | ||
| return Response(status=status.HTTP_204_NO_CONTENT) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.