Skip to content

feat(api): add /api/v2/events route specification #2419

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tothandras
Copy link
Contributor

@tothandras tothandras commented Mar 12, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a new API endpoint for listing ingested events with advanced filtering on attributes such as id, source, subject, type, time, and ingestedAt.
    • Enabled cursor-based pagination with enhanced query constraints to ensure efficient and robust data retrieval.

@tothandras tothandras added the release-note/feature Release note: Exciting New Features label Mar 12, 2025
Copy link

coderabbitai bot commented Mar 12, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new /api/v2/events endpoint across multiple components. The endpoint, accessible via a new method listEventsV2 and associated interface definitions, supports advanced filtering by several fields and cursor-based pagination. In addition, new schema types for filtering and pagination have been defined. Several files across the API specifications and the server router now include these endpoint additions. Separately, the pull request removes the dependency on the @typespec/versioning package by eliminating its import statements, using directives, and dependency entries from various files.

Changes

File(s) Summary
api/client/.../schemas.ts, api/openapi.cloud.yaml, api/openapi.yaml, api/spec/src/cloud/main.tsp, api/spec/src/events.tsp, openmeter/server/router/event.go Added a new /api/v2/events endpoint with the listEventsV2 method, including advanced filtering, cursor pagination, and related schema/interface definitions.
api/spec/package.json, api/spec/src/billing/..., api/spec/src/entitlements/..., api/spec/src/main.tsp, api/spec/src/notification/main.tsp, api/spec/src/productcatalog/subscription.tsp Removed the @typespec/versioning dependency along with its corresponding import and using directives.
api/spec/src/pagination.tsp Updated the PaginatedQuery model with validation constraints and introduced the CursorPaginatedQuery and CursorPagedList<T> models for cursor-based pagination.

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

🪧 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.
  • @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.

@tothandras tothandras marked this pull request as ready for review March 13, 2025 15:21
@tothandras tothandras requested a review from a team as a code owner March 13, 2025 15:21
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: 4

🧹 Nitpick comments (6)
api/openapi.yaml (2)

11689-11708: IngestedEventCursorList Schema
The addition of the IngestedEventCursorList schema effectively supports cursor-based pagination by mandating both items and nextCursor. One consideration is whether nextCursor should be optional to accommodate scenarios where there are no subsequent pages. Providing an example usage in the schema documentation might also benefit API consumers.


13381-13393: Installed Apps Query Parameters Update
The updated properties for listing installed apps—specifically, the page and pageSize parameters—are appropriately defined with numerical constraints and defaults. If the new /api/v2/events endpoint is intended to move toward cursor-based pagination exclusively, it might be worthwhile to review whether the page-based parameters should be consolidated or marked for deprecation in the future for consistency.

api/client/javascript/src/client/schemas.ts (2)

7956-7959: Appropriate cursor pagination parameters

The pagination query parameters (cursor and limit) are well-defined with clear documentation. Consider adding validation constraints for the limit parameter (e.g., minimum and maximum values) in the implementation to prevent abuse.


18332-18419: Comprehensive operation definition with thorough error handling

The listEventsV2 operation is well-defined with:

  1. Appropriate query parameters for filtering and pagination
  2. Clear documentation for each parameter
  3. Thorough response definitions for successful cases (200) and various error scenarios (400, 401, 403, 500, 503, default)

The error handling follows RESTful API best practices by using appropriate HTTP status codes and structured problem+json responses.

One enhancement to consider: Add a parameter for sorting the results, as users often expect to control the order of returned items (e.g., by time ascending/descending).

api/spec/src/events.tsp (2)

280-280: Consider explaining the purpose of x-internal extension

The @extension("x-internal", true) annotation suggests this API might be for internal use. It would be helpful to add a comment explaining the purpose of this extension and any usage restrictions.


281-311: Consider adding documentation for filter parameters

The filter parameters (id, source, subject, type, time, ingestedAt) have minimal documentation. Consider adding more detailed descriptions explaining the available filter operations and expected format.

Example for one parameter:

    @query(#{ explode: true, style: "deepObject" })
+   /**
+    * Filter events by ID.
+    * Supports operations: eq, contains
+    * Example: ?id[eq]=abc123 or ?id[contains]=abc
+    */
    id?: OpenMeter.FilterString,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 363729d and 8bc3188.

⛔ Files ignored due to path filters (1)
  • api/spec/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (15)
  • api/client/javascript/src/client/schemas.ts (8 hunks)
  • api/openapi.cloud.yaml (6 hunks)
  • api/openapi.yaml (6 hunks)
  • api/spec/package.json (0 hunks)
  • api/spec/src/billing/invoices/main.tsp (0 hunks)
  • api/spec/src/billing/main.tsp (0 hunks)
  • api/spec/src/cloud/main.tsp (1 hunks)
  • api/spec/src/entitlements/grant.tsp (0 hunks)
  • api/spec/src/entitlements/main.tsp (0 hunks)
  • api/spec/src/events.tsp (2 hunks)
  • api/spec/src/main.tsp (0 hunks)
  • api/spec/src/notification/main.tsp (0 hunks)
  • api/spec/src/pagination.tsp (2 hunks)
  • api/spec/src/productcatalog/subscription.tsp (0 hunks)
  • openmeter/server/router/event.go (1 hunks)
💤 Files with no reviewable changes (8)
  • api/spec/src/notification/main.tsp
  • api/spec/package.json
  • api/spec/src/billing/main.tsp
  • api/spec/src/productcatalog/subscription.tsp
  • api/spec/src/entitlements/main.tsp
  • api/spec/src/billing/invoices/main.tsp
  • api/spec/src/entitlements/grant.tsp
  • api/spec/src/main.tsp
🔇 Additional comments (18)
api/openapi.cloud.yaml (4)

7642-7742: New /api/v2/events Endpoint Definition

The new endpoint is clearly defined with its operationId listEventsV2, concise summary, and detailed description. The query parameters for filtering (such as clientId, id, source, subject, type, time, and ingestedAt) are well specified with appropriate schemas (using FilterString and FilterTime where needed). The response definitions for various HTTP statuses are thorough, and the inclusion of the x-internal flag and proper security configuration is appropriate for internal API endpoints.


7849-7873: Cursor-Based Pagination Parameter Definitions

The new reusable parameters for cursor-based pagination (CursorPaginatedQuery.cursor and CursorPaginatedQuery.limit) are well defined with clear descriptions, types, and validation (including minimum, maximum, and default values). This addition will support advanced pagination effectively.


11294-11404: New Schema Definitions for Query Filtering

The additions of the FilterString and FilterTime schemas provide a comprehensive, operator-rich filtering mechanism. The use of various operators ($eq, $ne, $in, $nin, $like, and so on) with clear descriptions and appropriate handling of nullable values is well executed. This will allow precise and flexible query filtering across the API.


11622-11641: IngestedEventCursorList Schema for Cursor Pagination

The new IngestedEventCursorList schema is well structured for supporting cursor-based pagination. It correctly enforces required fields (items and nextCursor), limits the number of items, and documents the purpose of each field. This schema aligns effectively with the new /api/v2/events endpoint requirements.

api/openapi.yaml (4)

7411-7511: New /api/v2/events Endpoint Specification
The new /api/v2/events endpoint is well-defined. The operationId (listEventsV2), summary, and detailed description clearly outline its purpose. The filtering parameters (including clientId, id, source, subject, type, time, and ingestedAt) are properly referenced via schemas, and the use of the deepObject style is appropriate for complex query structures. Ensure that all API clients support the deepObject style and that this behavior is clearly documented.


7615-7637: Cursor-Based Pagination Parameters
The definitions for CursorPaginatedQuery.cursor and CursorPaginatedQuery.limit are clear and include useful constraints such as data type, minimum/maximum limits, and default values. This setup should help enforce consistency on pagination behavior. Just verify that the backend enforces these constraints as defined.


8022-8027: Page Number Parameter Definition
The PaginatedQuery.page parameter is clearly documented with a description, a minimum value of 1, and a default of 1. This provides a sensible and user-friendly mechanism for page-based pagination.


8032-8039: Page Size Parameter Definition
The Pagination.pageSize parameter is well-configured with constraints ensuring a minimum value of 1, a maximum of 1000, and a default value of 100. This helps maintain consistency and control over the volume of data per page.

api/client/javascript/src/client/schemas.ts (5)

1762-1781: Well-structured API path definition

The new /api/v2/events endpoint is clearly defined with appropriate JSDoc comments explaining its purpose. The explicit marking of supported (GET) and unsupported HTTP methods follows the pattern used throughout the codebase.


3927-3957: Comprehensive string filtering capabilities

The FilterString type provides a rich set of filtering operators including equality, negation, inclusion, pattern matching (with case sensitivity options), and comparison operators. The inclusion of logical operators ($and, $or) enables the construction of complex filtering expressions. Each field has clear documentation explaining its purpose.


3958-3984: Well-designed time filtering capabilities

The FilterTime type appropriately provides comparison operators for date-time values with clear JSDoc documentation. The inclusion of logical operators ($and, $or) enables complex time-based filtering expressions. The consistent structure between FilterString and FilterTime makes the API intuitive to use.


4152-4158: Good implementation of cursor-based pagination

The IngestedEventCursorList type follows best practices for cursor-based pagination, including an array of items and a nextCursor field for retrieving the next page of results. This approach is more reliable than offset-based pagination for large datasets.


8272-8273: Proper type exports

The newly created types and parameters are correctly exported, making them available to consumers of this module and ensuring type safety throughout the application.

Also applies to: 8290-8291, 8591-8594

api/spec/src/cloud/main.tsp (1)

109-111: Interface extension looks good

The EventsV2 interface properly extends OpenMeter.EventsV2 and is correctly tagged with the /api/v2/events route, following the same pattern as other interfaces in the file.

api/spec/src/events.tsp (1)

272-312: EventsV2 interface implementation looks good

The EventsV2 interface and its list method are well-designed with appropriate query parameters for filtering and pagination. The method is correctly annotated and the return type properly uses the cursor-based pagination model.

api/spec/src/pagination.tsp (3)

14-15: Good addition of validation constraints

Adding min/max value constraints to pagination parameters is a good practice to prevent performance issues from excessive page sizes or invalid page numbers.

Also applies to: 21-23


55-73: Well-designed cursor pagination query model

The CursorPaginatedQuery model is well-structured with appropriate documentation and constraints. The implementation follows best practices for cursor-based pagination.


75-91: Well-designed cursor pagination response model

The CursorPagedList<T> model properly implements the cursor-based pagination response pattern with the @pageItems annotation and appropriate constraints.

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: 0

🧹 Nitpick comments (1)
api/spec/src/events.tsp (1)

270-312: Provide usage examples for advanced filtering

The new endpoint is well structured for deep-object filtering. However, consider adding example requests that demonstrate how to filter by time, source, and other properties. This helps API consumers understand the expected query shapes for OpenMeter.FilterString and OpenMeter.FilterTime.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8bc3188 and 4947ea1.

📒 Files selected for processing (1)
  • api/spec/src/events.tsp (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: Artifacts / Benthos Collector Container image
  • GitHub Check: Artifacts / Container image
  • GitHub Check: Quickstart
  • GitHub Check: Test
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: E2E
  • GitHub Check: Developer environment
  • GitHub Check: CI
  • GitHub Check: Build
  • GitHub Check: Commit hooks
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
api/spec/src/events.tsp (1)

4-4: Import looks good

Thanks for adding the import for pagination; it clearly aligns with the spread usage of CursorPaginatedQuery introduced below.

@tothandras tothandras enabled auto-merge (squash) March 13, 2025 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/feature Release note: Exciting New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant