-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Log events for function calls #8395
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis update introduces a feature that tracks analytics events for function calls within the application. It enhances monitoring capabilities by logging interactions with functions, allowing for better analysis of usage patterns. Key changes include the addition of a new event type, modifications to event handling, and updates to documentation to reflect these enhancements. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant LambdaManagerView
participant EventHandler
User->>LambdaManagerView: Call function
LambdaManagerView->>EventHandler: handle_function_call(func_id, target)
EventHandler-->>LambdaManagerView: Log event details
LambdaManagerView-->>User: Response
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
1839854
to
4dcd14b
Compare
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.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (1)
cvat/apps/events/handlers.py (1)
513-531
: Improve the genericity, validation, and documentation of the function.The
handle_function_call
function can be improved in the following ways:
Make the function more generic by accepting any model instance as the
target
instead of justTask
orJob
. This will allow the function to be used for tracking function calls on any model instance.Validate the
payload_fields
to ensure that only valid fields are passed. This will prevent invalid data from being logged.Add a docstring and type hints to better document the function. This will make it easier for other developers to understand and use the function.
Here's an example of how the function can be improved:
def handle_function_call( function_id: str, target: models.Model, **payload_fields, ) -> None: """ Record a server event for a function call on a model instance. Args: function_id: The ID of the function that was called. target: The model instance on which the function was called. **payload_fields: Additional fields to include in the payload. Returns: None """ # Validate payload fields valid_fields = ["foo", "bar"] # Replace with actual valid fields for field in payload_fields: if field not in valid_fields: raise ValueError(f"Invalid payload field: {field}") 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, }, )
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- changelog.d/20240903_155336_roman_function_events.md (1 hunks)
- cvat/apps/events/event.py (1 hunks)
- cvat/apps/events/handlers.py (1 hunks)
- cvat/apps/lambda_manager/views.py (3 hunks)
- site/content/en/docs/administration/advanced/analytics.md (1 hunks)
Additional comments not posted (7)
changelog.d/20240903_155336_roman_function_events.md (1)
1-4
: LGTM!The changelog fragment is correctly formatted and documents the changes made in the pull request.
cvat/apps/events/event.py (1)
30-30
: LGTM!The addition of the
"function": ["call"]
entry to thescopes
dictionary in theEventScopes
class is a valid and consistent change that expands the functionality of the event management system to track function call events.site/content/en/docs/administration/advanced/analytics.md (1)
132-133
: LGTM!The addition of the new
call:function
event type to track function calls looks good.cvat/apps/lambda_manager/views.py (4)
23-23
: LGTM!The code changes are approved.
1087-1098
: LGTM!The code changes are approved.
1099-1100
: LGTM!The code changes are approved.
1192-1193
: LGTM!The code changes are approved.
4dcd14b
to
6966b7a
Compare
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.
6966b7a
to
305cb3e
Compare
Quality Gate passedIssues Measures |
This will let us collect statistics about function usage. 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.
Motivation and context
This will let us collect statistics about function usage.
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.How has this been tested?
Manual testing.
Checklist
develop
branch[ ] I have added tests to cover my changes[ ] I have linked related issues (see GitHub docs)[ ] I have increased versions of npm packages if it is necessary(cvat-canvas,
cvat-core,
cvat-data and
cvat-ui)
License
Feel free to contact the maintainers if that's a concern.
Summary by CodeRabbit
New Features
call:function
, to the analytics documentation.Bug Fixes
Documentation