-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
/api/events endpoint can be used to receive events not only from client #8799
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
014658f
endpoint for sending events not from client
Eldies a474668
updating schema
Eldies 1a0b0fc
fix payload and request id
Eldies aef1798
fix ing schema
Eldies 1a939b6
reusing existing events endpoint
Eldies db1ae66
removing unnecesary changes
Eldies f3667c4
rewriting user and org data in event only when it is from client
Eldies fb2f84d
Merge branch 'refs/heads/develop' into dl/events-endpoint
Eldies 5230967
changelog entry
Eldies f20c6af
Merge branch 'refs/heads/develop' into dl/events-endpoint
Eldies 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 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 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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
# Copyright (C) 2023-2024 CVAT.ai Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
import json | ||
|
||
from django.conf import settings | ||
from drf_spectacular.types import OpenApiTypes | ||
from drf_spectacular.utils import (OpenApiParameter, OpenApiResponse, | ||
extend_schema) | ||
from rest_framework import status, viewsets | ||
from rest_framework.decorators import action | ||
from rest_framework.renderers import JSONRenderer | ||
from rest_framework.response import Response | ||
|
||
|
@@ -15,8 +17,10 @@ | |
from cvat.apps.events.serializers import ClientEventsSerializer | ||
from cvat.apps.iam.filters import ORGANIZATION_OPEN_API_PARAMETERS | ||
|
||
from .event import record_server_event | ||
from .export import export | ||
from .handlers import handle_client_events_push | ||
from .handlers import handle_client_events_push, request_id | ||
from .serializers import EventSerializer | ||
|
||
|
||
class EventsViewSet(viewsets.ViewSet): | ||
|
@@ -44,6 +48,26 @@ def create(self, request): | |
|
||
return Response(serializer.validated_data, status=status.HTTP_201_CREATED) | ||
|
||
@extend_schema(summary='Log external events', | ||
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. Do we really need several end-points to send events (add a row into Clickhouse)? 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. reused existing endpoint |
||
description='Sends logs to the Clickhouse if it is connected', | ||
responses={'201': EventSerializer()}) | ||
@action( | ||
detail=False, | ||
url_path='external', | ||
methods=['POST'], | ||
serializer_class=EventSerializer, | ||
) | ||
def external(self, request): | ||
serializer = EventSerializer(data=request.data) | ||
serializer.is_valid(raise_exception=True) | ||
data = dict( | ||
serializer.validated_data, | ||
payload=json.loads(serializer.validated_data['payload']), | ||
) | ||
record_server_event(request_id=request_id(), **data) | ||
|
||
return Response(serializer.validated_data, status=status.HTTP_201_CREATED) | ||
|
||
@extend_schema(summary='Get an event log', | ||
methods=['GET'], | ||
description='The log is returned in the CSV format.', | ||
|
This file contains 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the rego rules to reflect this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I planned it to be only accessible by admins, and rego rules do not need to be changed for it.
But due to comments above I will try to use the existing endpoint somehow, and just drop this scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed it