Skip to content

Commit

Permalink
Log events for function calls
Browse files Browse the repository at this point in the history
Note that I would've preferred the function ID to go into the `obj_id`
field, but function IDs are strings, and the field is numeric.
  • Loading branch information
SpecLad committed Sep 3, 2024
1 parent 4aa2a4e commit 6966b7a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog.d/20240903_155336_roman_function_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Added

- Added analytics events for function calls
(<https://github.com/cvat-ai/cvat/pull/8395>)
1 change: 1 addition & 0 deletions cvat/apps/events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class EventScopes:
"annotations": ["create", "update", "delete"],
"label": ["create", "update", "delete"],
"dataset": ["export", "import"],
"function": ["call"],
}

@classmethod
Expand Down
20 changes: 20 additions & 0 deletions cvat/apps/events/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,26 @@ def handle_dataset_import(
) -> None:
handle_dataset_io(instance, "import", format_name=format_name, cloud_storage_id=cloud_storage_id)

def handle_function_call(
function_id: str,
target: Union[Task, Job],
**payload_fields,
) -> None:
record_server_event(
scope=event_scope("call", "function"),
request_id=request_id(),
project_id=project_id(target),
task_id=task_id(target),
job_id=job_id(target),
user_id=user_id(),
user_name=user_name(),
user_email=user_email(),
payload={
"function": {"id": function_id},
**payload_fields,
},
)

def handle_rq_exception(rq_job, exc_type, exc_value, tb):
oid = rq_job.meta.get(RQJobMetaField.ORG_ID, None)
oslug = rq_job.meta.get(RQJobMetaField.ORG_SLUG, None)
Expand Down
12 changes: 11 additions & 1 deletion cvat/apps/lambda_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import numpy as np
import requests
import rq
from cvat.apps.events.handlers import handle_function_call
from cvat.apps.lambda_manager.signals import interactive_function_call_signal
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, ValidationError
Expand Down Expand Up @@ -1083,14 +1084,21 @@ def call(self, request, func_id):
gateway = LambdaGateway()
lambda_func = gateway.get(func_id)

return lambda_func.invoke(
response = lambda_func.invoke(
db_task,
request.data, # TODO: better to add validation via serializer for these data
db_job=job,
is_interactive=True,
request=request
)

handle_function_call(func_id, db_task,
category="interactive",
parameters={"frame": request.data["frame"]},
)

return response

@extend_schema(tags=['lambda'])
@extend_schema_view(
retrieve=extend_schema(
Expand Down Expand Up @@ -1182,6 +1190,8 @@ def create(self, request):
rq_job = queue.enqueue(lambda_func, threshold, task, quality,
mapping, cleanup, conv_mask_to_poly, max_distance, request, job=job)

handle_function_call(function, job or task, category="batch")

response_serializer = FunctionCallSerializer(rq_job.to_dict())
return response_serializer.data

Expand Down
2 changes: 2 additions & 0 deletions site/content/en/docs/administration/advanced/analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Server events:

- `export:dataset`, `import:dataset`

- `call:function`

Client events:

- `load:cvat`
Expand Down

0 comments on commit 6966b7a

Please sign in to comment.