-
Notifications
You must be signed in to change notification settings - Fork 527
feat: verify warehouse connection api and events received #7677
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
2c90b7b
518c78a
0300658
b9cfa77
3262f68
4fea97c
69c60e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class WarehouseEventStats: | ||
| total_events_received: int | ||
| unique_events_count: int |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| Experiment, | ||
| ExperimentStatus, | ||
| WarehouseConnection, | ||
| WarehouseType, | ||
| ) | ||
| from experimentation.permissions import ( | ||
| ExperimentPermission, | ||
|
|
@@ -27,8 +28,10 @@ | |
| WarehouseConnectionSerializer, | ||
| ) | ||
| from experimentation.services import ( | ||
| annotate_warehouse_event_stats, | ||
| create_experiment_audit_log, | ||
| create_warehouse_audit_log, | ||
| mark_warehouse_pending_connection, | ||
| transition_experiment_status, | ||
| ) | ||
| from users.models import FFAdminUser | ||
|
|
@@ -71,6 +74,32 @@ def perform_destroy(self, instance: WarehouseConnection) -> None: | |
| ) | ||
| instance.delete() | ||
|
|
||
| def list(self, request: Request, *args: object, **kwargs: object) -> Response: | ||
| environment_api_key: str = self.kwargs["environment_api_key"] | ||
| connections = list(self.filter_queryset(self.get_queryset())) | ||
| for connection in connections: | ||
| annotate_warehouse_event_stats(connection, environment_api_key) | ||
|
Zaimwa9 marked this conversation as resolved.
|
||
| serializer = self.get_serializer(connections, many=True) | ||
| return Response(serializer.data) | ||
|
|
||
| def retrieve(self, request: Request, *args: object, **kwargs: object) -> Response: | ||
| connection = self.get_object() | ||
| annotate_warehouse_event_stats(connection, self.kwargs["environment_api_key"]) | ||
| serializer = self.get_serializer(connection) | ||
| return Response(serializer.data) | ||
|
|
||
| @action(detail=True, methods=["post"], url_path="test-warehouse-connection") | ||
| def test_warehouse_connection(self, request: Request, **kwargs: object) -> Response: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes so this endpoint does 2 things:
I'm not entirely satisfied but using a task would have been overkilled to me (especially while we are still likely to change the flush buffer). I think for external warehouse this can be replaced with a sort of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think polling is probably a bad idea since clickhouse calls are expensive |
||
| connection: WarehouseConnection = self.get_object() | ||
| if connection.warehouse_type != WarehouseType.FLAGSMITH: | ||
| return Response( | ||
| {"detail": "Test events are only supported for Flagsmith warehouses."}, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
| ) | ||
| mark_warehouse_pending_connection(connection) | ||
| serializer = self.get_serializer(connection) | ||
| return Response(serializer.data) | ||
|
|
||
| def create(self, request: Request, *args: object, **kwargs: object) -> Response: | ||
| environment = self._get_environment() | ||
| serializer = self.get_serializer(data=request.data) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.