-
Notifications
You must be signed in to change notification settings - Fork 466
feat: renamed-feature-health-sample-to-webhook ⚠️ #6332
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cf2a3f4
feat: renamed-feature-health-sample-to-generic
Zaimwa9 7e986e1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cf43520
feat: typing
Zaimwa9 db09aef
Merge branch 'feat/migrate-sample-to-generic' of github.com:Flagsmith…
Zaimwa9 c85c738
feat: migrate-to-webhook-feature-health-provider
Zaimwa9 d96fb3d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3aba086
feat: lint
Zaimwa9 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
52 changes: 52 additions & 0 deletions
52
api/features/feature_health/migrations/0003_migrate_sample_to_webhook.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,52 @@ | ||
| # Generated by Django 4.2.26 on 2025-11-27 10:39 | ||
| from django.apps.registry import Apps | ||
| from django.db.backends.base.schema import BaseDatabaseSchemaEditor | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def migrate_sample_to_webhook_forward(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None: | ||
| FeatureHealthProvider = apps.get_model("feature_health", "FeatureHealthProvider") | ||
| FeatureHealthEvent = apps.get_model("feature_health", "FeatureHealthEvent") | ||
|
|
||
| FeatureHealthProvider.objects.filter(name="Sample").update(name="Webhook") | ||
| FeatureHealthEvent.objects.filter(provider_name="Sample").update(provider_name="Webhook") | ||
|
|
||
|
|
||
| def migrate_sample_to_webhook_reverse(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None: | ||
| FeatureHealthProvider = apps.get_model("feature_health", "FeatureHealthProvider") | ||
| FeatureHealthEvent = apps.get_model("feature_health", "FeatureHealthEvent") | ||
|
|
||
| FeatureHealthProvider.objects.filter(name="Webhook").update(name="Sample") | ||
| FeatureHealthEvent.objects.filter(provider_name="Webhook").update(provider_name="Sample") | ||
|
|
||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("feature_health", "0002_featurehealthevent_add_external_id_alter_created_at"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='featurehealthprovider', | ||
| name='name', | ||
| field=models.CharField( | ||
| choices=[('Webhook', 'Webhook'), ('Grafana', 'Grafana')], | ||
| max_length=50 | ||
| ), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='historicalfeaturehealthprovider', | ||
| name='name', | ||
| field=models.CharField( | ||
| choices=[('Webhook', 'Webhook'), ('Grafana', 'Grafana')], | ||
| max_length=50 | ||
| ), | ||
| ), | ||
| migrations.RunPython( | ||
| migrate_sample_to_webhook_forward, | ||
| migrate_sample_to_webhook_reverse, | ||
| ), | ||
| ] | ||
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
2 changes: 1 addition & 1 deletion
2
...ature_health/providers/sample/__init__.py → ...ture_health/providers/webhook/__init__.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
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,46 @@ | ||
| from pydantic.type_adapter import TypeAdapter | ||
|
|
||
| from features.feature_health.models import ( | ||
| FeatureHealthEventType, | ||
| FeatureHealthProviderName, | ||
| ) | ||
| from features.feature_health.providers.webhook.types import ( | ||
| WebhookEvent, | ||
| WebhookEventStatus, | ||
| ) | ||
| from features.feature_health.types import ( | ||
| FeatureHealthEventData, | ||
| FeatureHealthProviderResponse, | ||
| ) | ||
|
|
||
| _sample_event_type_adapter = TypeAdapter(WebhookEvent) | ||
|
|
||
|
|
||
| def map_sample_event_status_to_feature_health_event_type( | ||
| status: WebhookEventStatus, | ||
| ) -> FeatureHealthEventType: | ||
| return ( | ||
| FeatureHealthEventType.UNHEALTHY | ||
| if status == "unhealthy" | ||
| else FeatureHealthEventType.HEALTHY | ||
| ) | ||
|
|
||
|
|
||
| def map_payload_to_provider_response( | ||
| payload: str, | ||
| ) -> FeatureHealthProviderResponse: | ||
| event_data: WebhookEvent = _sample_event_type_adapter.validate_json(payload) | ||
|
|
||
| return FeatureHealthProviderResponse( | ||
| events=[ | ||
| FeatureHealthEventData( | ||
| feature_name=event_data["feature"], | ||
| environment_name=event_data.get("environment"), | ||
| type=map_sample_event_status_to_feature_health_event_type( | ||
| event_data["status"] | ||
| ), | ||
| reason=event_data.get("reason"), | ||
| provider_name=FeatureHealthProviderName.WEBHOOK.value, | ||
| ), | ||
| ], | ||
| ) |
2 changes: 1 addition & 1 deletion
2
...ature_health/providers/sample/services.py → ...ture_health/providers/webhook/services.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
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
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
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
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.