Skip to content
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

Merged
merged 1 commit into from
Sep 4, 2024
Merged

Conversation

SpecLad
Copy link
Contributor

@SpecLad SpecLad commented Sep 3, 2024

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

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • [ ] 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

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features

    • Introduced enhanced analytics tracking for function calls, improving user behavior insights.
    • Added a new event type, call:function, to the analytics documentation.
  • Bug Fixes

    • Improved event handling for function calls, ensuring better logging and tracking capabilities.
  • Documentation

    • Updated analytics documentation to include the new event type for server interactions.

Copy link
Contributor

coderabbitai bot commented Sep 3, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This 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

File Change Summary
changelog.d/20240903_155336_roman_function_events.md Introduced analytics event tracking for function calls.
cvat/apps/events/event.py Added a new entry to EventScopes for function call tracking.
cvat/apps/events/handlers.py Introduced handle_function_call to log server events related to function calls.
cvat/apps/lambda_manager/views.py Modified call and create methods to invoke handle_function_call for enhanced tracking.
site/content/en/docs/administration/advanced/analytics.md Added new event type call:function to server events documentation.

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
Loading

Poem

In the meadow where functions play,
A new way to track has come our way.
With hops and jumps, we log with glee,
Function calls dance, oh so free!
Let's celebrate with a joyful cheer,
For every call brings us near! 🐰✨


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@SpecLad SpecLad force-pushed the function-events branch 2 times, most recently from 1839854 to 4dcd14b Compare September 3, 2024 13:24
@SpecLad SpecLad marked this pull request as ready for review September 3, 2024 13:24
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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:

  1. Make the function more generic by accepting any model instance as the target instead of just Task or Job. This will allow the function to be used for tracking function calls on any model instance.

  2. Validate the payload_fields to ensure that only valid fields are passed. This will prevent invalid data from being logged.

  3. 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

Commits

Files that changed from the base of the PR and between 4aa2a4e and 4dcd14b.

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 the scopes dictionary in the EventScopes 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.

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.
Copy link

sonarcloud bot commented Sep 4, 2024

@SpecLad SpecLad merged commit d80a574 into cvat-ai:develop Sep 4, 2024
33 checks passed
@SpecLad SpecLad deleted the function-events branch September 4, 2024 12:37
This was referenced Sep 9, 2024
bschultz96 pushed a commit to bschultz96/cvat that referenced this pull request Sep 12, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant