Skip to content

fix: take limit as input so the no of operations returned is always limited#2095

Merged
JivusAyrus merged 8 commits intomainfrom
suvij/fix-export-of-unlimited-operations
Jul 31, 2025
Merged

fix: take limit as input so the no of operations returned is always limited#2095
JivusAyrus merged 8 commits intomainfrom
suvij/fix-export-of-unlimited-operations

Conversation

@JivusAyrus
Copy link
Copy Markdown
Member

@JivusAyrus JivusAyrus commented Jul 31, 2025

Summary by CodeRabbit

  • New Features

    • Added support for specifying a limit on the number of operations returned in analytics queries.
    • If no limit is provided, a default value of 100 will be used.
  • Improvements

    • Simplified date range handling in analytics operations, now using a fixed 7-day range.

Checklist

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 31, 2025

Warning

Rate limit exceeded

@JivusAyrus has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d99d729 and 96061dc.

📒 Files selected for processing (2)
  • controlplane/src/core/bufservices/analytics/getOperations.ts (3 hunks)
  • controlplane/src/core/constants.ts (1 hunks)

Walkthrough

A new optional integer field limit was added to the GetOperationsRequest message in both the protobuf definition and its TypeScript implementation. The backend logic was updated to accept and use this limit, defaulting to 100 if unspecified, and simplified date range handling by removing feature flag checks and dynamic retention logic.

Changes

Cohort / File(s) Change Summary
Protobuf Schema & Generated Types
proto/wg/cosmo/platform/v1/platform.proto, connect/src/wg/cosmo/platform/v1/platform_pb.ts
Added an optional int32 field limit to the GetOperationsRequest message in the protobuf schema and updated the generated TypeScript class to include this field.
Backend Analytics Logic
controlplane/src/core/bufservices/analytics/getOperations.ts
Removed organization feature flag checks and dynamic retention logic; now uses a fixed 7-day date range and passes a limit (default 100) from the request to metricsRepo.getOperations, with simplified validation ensuring the limit is between 1 and 1000.
Metrics Repository
controlplane/src/core/repositories/analytics/MetricsRepository.ts
Updated getOperations method to require a limit parameter; SQL query now includes a LIMIT clause using this value to restrict the number of returned operations ordered by latency descending.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch suvij/fix-export-of-unlimited-operations

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jul 31, 2025

Router image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-8fb7ed3ed0caf1b42bfd993f09c124ea0b88ff95

Copy link
Copy Markdown
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: 2

🧹 Nitpick comments (1)
proto/wg/cosmo/platform/v1/platform.proto (1)

2781-2785: Parameter limit looks fine, but align with existing pagination conventions

Most request messages (e.g., GetFederatedGraphsRequest, GetSubgraphsRequest) expose both limit and offset as plain int32 (not optional). Introducing limit here as optional diverges from that pattern and still leaves callers unable to page through large result sets.

Consider the more consistent schema below:

   optional string clientName = 3;
-  optional int32 limit = 4;
+  int32 limit = 4;   // keep semantic parity with other requests
+  int32 offset = 5;  // enable paging through large operation lists

This keeps field‐number compatibility (4 is already new) while giving consumers the same UX they already have elsewhere.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 461dbdd and 78046dc.

⛔ Files ignored due to path filters (1)
  • connect-go/gen/proto/wg/cosmo/platform/v1/platform.pb.go is excluded by !**/*.pb.go, !**/gen/**
📒 Files selected for processing (4)
  • connect/src/wg/cosmo/platform/v1/platform_pb.ts (2 hunks)
  • controlplane/src/core/bufservices/analytics/getOperations.ts (2 hunks)
  • controlplane/src/core/repositories/analytics/MetricsRepository.ts (2 hunks)
  • proto/wg/cosmo/platform/v1/platform.proto (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in the cosmo codebase, database transactions are typically managed at the service layer (e.g., in bu...
Learnt from: wilsonrivera
PR: wundergraph/cosmo#1919
File: controlplane/src/core/repositories/OrganizationGroupRepository.ts:193-224
Timestamp: 2025-07-01T13:53:54.146Z
Learning: In the Cosmo codebase, database transactions are typically managed at the service layer (e.g., in buf services like deleteOrganizationGroup.ts), where repositories are instantiated with the transaction handle and all operations within those repositories are automatically part of the same transaction.

Applied to files:

  • controlplane/src/core/bufservices/analytics/getOperations.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
  • GitHub Check: build-router
  • GitHub Check: build_push_image
  • GitHub Check: build_test
  • GitHub Check: integration_test (./. ./fuzzquery ./lifecycle ./modules)
  • GitHub Check: build_push_image (nonroot)
  • GitHub Check: image_scan (nonroot)
  • GitHub Check: build_push_image
  • GitHub Check: image_scan
  • GitHub Check: integration_test (./telemetry)
  • GitHub Check: integration_test (./events)
  • GitHub Check: build_test
  • GitHub Check: build_push_image
  • GitHub Check: build_test
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
connect/src/wg/cosmo/platform/v1/platform_pb.ts (2)

21892-21895: LGTM! Properly generated protobuf field declaration.

The limit field declaration follows correct protobuf TypeScript generation patterns with appropriate JSDoc documentation and optional typing.


21908-21908: LGTM! Correct field descriptor configuration.

The field descriptor properly configures the limit field with field number 4, INT32 scalar type, and optional flag, maintaining consistency with the protobuf schema.

controlplane/src/core/repositories/analytics/MetricsRepository.ts (1)

722-722: LGTM! Method signature properly extended with limit parameter.

The addition of the limit parameter to the getOperations method signature is clean and follows TypeScript conventions.

controlplane/src/core/bufservices/analytics/getOperations.ts (2)

55-55: LGTM! Fixed range simplifies the logic.

Using a fixed 7-day range (168 hours) instead of dynamic retention limits simplifies the implementation and removes dependency on feature flags.


70-70: LGTM! Limit parameter properly passed to repository.

The limit parameter is correctly passed to the metricsRepo.getOperations method, completing the integration from service to repository layer.

Comment thread controlplane/src/core/bufservices/analytics/getOperations.ts
Comment thread controlplane/src/core/repositories/analytics/MetricsRepository.ts Outdated
Copy link
Copy Markdown
Member

@Aenimus Aenimus left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

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

LGTM

@JivusAyrus JivusAyrus merged commit 80691fe into main Jul 31, 2025
41 checks passed
@JivusAyrus JivusAyrus deleted the suvij/fix-export-of-unlimited-operations branch July 31, 2025 15:58
@Noroth Noroth mentioned this pull request Sep 30, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants