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

Updated Backend Client #49

Merged
merged 1 commit into from
Dec 17, 2024
Merged

Updated Backend Client #49

merged 1 commit into from
Dec 17, 2024

Conversation

Shivam-yadav2de
Copy link
Contributor

@Shivam-yadav2de Shivam-yadav2de commented Dec 17, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new classes for enhanced tenant management and metrics control.
    • Added methods for retrieving tags and searching tenant policies.
    • Implemented embedding update functionality through a new service handler.
  • Bug Fixes

    • Updated response types for existing methods to ensure accurate data handling.
  • Chores

    • Removed outdated classes to streamline the data model.

Copy link

coderabbitai bot commented Dec 17, 2024

Walkthrough

This pull request introduces significant enhancements to the OneLens backend client, focusing on expanding tenant management, metrics control, and embedding services. The changes primarily involve adding new classes, methods, and fields across multiple files in the onelens_backend_client_v2 package. Key additions include new RPC handlers for embedding services, tags retrieval, tenant policy search, and methods for refreshing change manager status. The modifications aim to provide more granular control and improved functionality for tenant-related operations and metrics management.

Changes

File Changes
models.py - Added classes: EmbeddingType, GetMetricsControlWebhookResponse, FetchTenantDetailResponse, FetchTenantUsersResponse
- Updated classes with new tenant_id fields: GetCloudAccountMetadataRequest, APIGetFeaturesByFiltersRequest, APIUpdateMetricsControlRequest
- Removed GetPolicyTicketsForNotificationRequest class
rpc/__init__.py - Added import and export for NaviraEmbeddingServiceRpcHandler
rpc/cloud_metadata_service_rpc_handler.py - Added get_tags method
- Added _get_tags_serialize private method
rpc/metrics_control_service_rpc_handler.py - Added refresh_change_manager_status method
- Updated process_metrics_control_webhook return type
rpc/navira_embedding_service_rpc_handler.py - New file with NaviraEmbeddingServiceRpcHandler class
- Added update_embeddings method
- Added _update_embeddings_serialize private method
rpc/tenant_policy_service_rpc_handler.py - Added search_tenant_policies method
- Added _search_tenant_policies_serialize private method

Sequence Diagram

sequenceDiagram
    participant Client
    participant NaviraEmbeddingService
    participant MetricsControlService
    participant TenantPolicyService

    Client->>NaviraEmbeddingService: update_embeddings()
    NaviraEmbeddingService-->>Client: Embedding Update Response

    Client->>MetricsControlService: refresh_change_manager_status()
    MetricsControlService-->>Client: Status Refresh Response

    Client->>TenantPolicyService: search_tenant_policies()
    TenantPolicyService-->>Client: Tenant Policies
Loading

Possibly related PRs

Suggested reviewers

  • kaushikkishore
  • pranjal-astuto
  • sidpan1

Poem

🐰 Hop, hop, through the code we go,
Tenant management starts to grow!
Embeddings dance, metrics take flight,
Our backend client shines so bright!
New handlers leap with joyful might! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

Copy link

@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: 2

🧹 Nitpick comments (2)
onelens_backend_client_v2/rpc/tenant_policy_service_rpc_handler.py (2)

110-113: Remove extra blank lines between imports.

The imports are correctly added but contain unnecessary blank lines between them. Consider removing the extra blank lines to maintain consistency with other imports in the file.

 from onelens_backend_client_v2.models import SearchTenantPoliciesRequest
-
-
 from onelens_backend_client_v2.models import SearchTenantPoliciesResponse

2190-2254: Remove extra blank lines in docstring.

The method implementation looks good and follows the established patterns, but there are unnecessary blank lines in the docstring between the description and parameters.

     """Search Tenant Policies
-
-
-
     :param request: (required)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efff93f and 14d8c8c.

📒 Files selected for processing (6)
  • onelens_backend_client_v2/models.py (28 hunks)
  • onelens_backend_client_v2/rpc/__init__.py (2 hunks)
  • onelens_backend_client_v2/rpc/cloud_metadata_service_rpc_handler.py (2 hunks)
  • onelens_backend_client_v2/rpc/metrics_control_service_rpc_handler.py (4 hunks)
  • onelens_backend_client_v2/rpc/navira_embedding_service_rpc_handler.py (1 hunks)
  • onelens_backend_client_v2/rpc/tenant_policy_service_rpc_handler.py (2 hunks)
🔇 Additional comments (24)
onelens_backend_client_v2/models.py (16)

1078-1080: LGTM: New enum class for embedding types

The EmbeddingType enum class is well-defined with a clear purpose for handling different types of embeddings, currently supporting "TAGS".


1246-1246: LGTM: Optional tenant_id field addition

The optional tenant_id field of type UUID4 is appropriately added to the GetCloudAccountMetadataRequest class.


1307-1313: LGTM: New response model for metrics control webhook

The GetMetricsControlWebhookResponse class is well-structured with a required status field that describes the change manager request webhook status.


1512-1516: LGTM: New response model for tags

The GetTagsResponse class is well-defined with a required tags field that holds a dictionary of tag information.


1900-1909: LGTM: New model for Navira logs

The NaviraLog class is well-structured with all required fields for tracking query execution details:

  • query_id, user_id for identification
  • username, query for user context
  • status, sql_query_translation for execution details
  • created_at, updated_at for timestamps

2133-2145: LGTM: New pagination request models

The PostNaviraLogsRequest and PostTenantUsersRequest classes are well-defined with optional pagination parameters defaulting to page 1 with 10 items per page.


2500-2515: LGTM: New request/response models for change manager status

The RefreshChangeManagerStatusRequest and RefreshChangeManagerStatusResponse classes are well-structured for handling change manager status updates:

  • Request includes optional list of event IDs
  • Response includes required status field

3055-3081: LGTM: New response model for tenant details

The TenantDetailResponse class is well-structured with comprehensive fields for tenant information:

  • Basic details: ID, name, status
  • Subscription and account info
  • Financial metrics: potential savings
  • Ticket stats: open/closed counts
  • Feature flags: hierarchy_exists

3223-3227: LGTM: New model for policy search results

The TenantPolicySearchResult class is well-defined with essential fields for policy search results:

  • id: UUID4 for unique identification
  • title: String for display
  • alias: String for reference

3350-3376: LGTM: New model for tenant user details

The TenantUserDetails class is well-structured with comprehensive user information:

  • Personal info: name, email, contact details
  • Professional info: role, job title, manager
  • Preferences: language, currency, timezone
  • System info: status, sources, timestamps
  • Access control: node_ids

3564-3571: LGTM: New request model for embeddings update

The UpdateEmbeddingsRequest class is well-defined with required fields:

  • tenant_id: UUID4 for tenant identification
  • embedding_type: EmbeddingType enum for type specification

4315-4319: LGTM: Optional field addition for change manager events

The optional change_manager_event_ids field is appropriately added to the APIMetricsControlFilter class.


6036-6040: LGTM: Consistent field addition across models

The optional change_manager_event_ids field is consistently added to both GetMetricsControlStatusCountRequest and GetMetricsControlStatusRequest classes.

Also applies to: 6076-6080


Line range hint 6960-6988: LGTM: New response model for metrics control

The MetricsControlResponse class is well-structured with comprehensive fields for metrics control:

  • Identification: id, resource_id
  • Metrics info: metric_name, status
  • Timestamps: requested_on, expires_on
  • Additional data: entity_id, attributes
  • Optional change manager event ID

9581-9606: LGTM: New request model for policy tickets notification

The GetPolicyTicketsForNotificationRequest class is well-defined with:

  • Required tenant_id
  • Optional filter criteria
  • Boolean flags for controlling response data

10353-10356: LGTM: New response model for tenant policy search

The ResponseSearchTenantPoliciesResponse class follows the standard response pattern with data and optional message fields.

onelens_backend_client_v2/rpc/__init__.py (1)

105-107: LGTM! Import and export of NaviraEmbeddingServiceRpcHandler are properly implemented.

The changes follow the established pattern in the module for importing and exporting RPC handlers.

Also applies to: 181-181

onelens_backend_client_v2/rpc/cloud_metadata_service_rpc_handler.py (2)

14-18: LGTM! Import statements are properly organized.

The imports for the new tags-related models are correctly placed and follow the module's import style.


152-271: LGTM! The get_tags implementation follows the established pattern.

The method implementation is consistent with other RPC handlers in the class, including:

  • Proper type annotations
  • Complete error handling
  • Comprehensive documentation
  • Consistent parameter serialization
onelens_backend_client_v2/rpc/metrics_control_service_rpc_handler.py (3)

44-47: LGTM! Import statements for RefreshChangeManagerStatus models are properly placed.

The imports follow the module's organization pattern.


687-687: LGTM! Return type specification is more precise.

The change from Any to GetMetricsControlWebhookResponse improves type safety and makes the API contract clearer.

Also applies to: 725-725


793-912: LGTM! The refresh_change_manager_status implementation is well-structured.

The new method follows the established pattern with:

  • Proper type annotations
  • Complete error handling
  • Comprehensive documentation
  • Consistent parameter serialization
onelens_backend_client_v2/rpc/tenant_policy_service_rpc_handler.py (2)

2255-2309: LGTM!

The serialization method is well-implemented and follows the established patterns in the codebase. It properly handles:

  • Request body serialization
  • HTTP headers configuration
  • Authentication settings
  • Resource path construction

2190-2309: Verify the usage of the new search functionality.

Let's verify if there are any existing components that should be updated to use this new search functionality.

Comment on lines +125 to +127
# authentication setting
_auth_settings: List[str] = []

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure authentication settings are correctly configured

The _auth_settings variable is set to an empty list, which means no authentication methods are being applied. If the API endpoint requires authentication, you should specify the appropriate authentication methods here to ensure secure access.

Comment on lines +74 to +77
_response_types_map: Dict[str, Optional[str]] = {
"200": "Any",
"422": "HTTPValidationError",
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Handle unexpected HTTP status codes

The _response_types_map currently handles only status codes 200 and 422. It's important to handle other possible HTTP responses such as 400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), and 500 (Internal Server Error) to ensure robust error handling.

Consider updating the _response_types_map to include these status codes:

 _response_types_map: Dict[str, Optional[str]] = {
     "200": "Any",
     "422": "HTTPValidationError",
+    "400": "HTTPBadRequestError",
+    "401": "HTTPUnauthorizedError",
+    "403": "HTTPForbiddenError",
+    "404": "HTTPNotFoundError",
+    "500": "HTTPServerError",
 }

Committable suggestion skipped: line range outside the PR's diff.

@bhatt-priyadutt bhatt-priyadutt merged commit 738d70c into main Dec 17, 2024
2 of 12 checks passed
This was referenced Dec 18, 2024
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.

2 participants