Repository navigation
feat(api): add event subject list endpoint - #4497
tothandras wants to merge 2 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds an internal event-subject listing API with cursor pagination, key and attributed filters, ClickHouse-backed subject discovery, Go and JavaScript client methods, generated API contracts, and end-to-end coverage. ChangesAPI contracts and domain
Streaming and server implementation
Client and validation surfaces
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant API
participant MetereventService
participant ClickHouse
Client->>API: GET /openmeter/events/subjects
API->>MetereventService: ListSubjects(params)
MetereventService->>ClickHouse: ListSubjectsV2(namespace, cursor, filters)
ClickHouse-->>MetereventService: Ordered subject keys
MetereventService-->>API: Subjects and cursor metadata
API-->>Client: JSON paginated response
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
9937a40 to
1f3c37e
Compare
1f3c37e to
449cad9
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openmeter/meterevent/adapter/subject.go (1)
104-137: ⚡ Quick winTwo separate customer queries for attribution resolution.
The implementation makes two
ListCustomerscalls (lines 114-123) to resolve attributed subjects: one searching byUsageAttributionSubjectKeyand another by customerKey. This is necessary because these are different search fields, and the customer service likely doesn't support OR queries across these fields.While this works correctly, if the customer service API is ever extended to support OR queries or multi-field searches, combining these into a single call could reduce overhead, especially when many subjects need attribution checks.
For now, this is fine—just something to keep in mind for future optimization if attribution checks become a hot path.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@openmeter/meterevent/adapter/subject.go` around lines 104 - 137, The function attributedSubjectKeys currently issues two ListCustomers calls (via a.customerService.ListCustomers) to match keys against UsageAttributionSubjectKey and Key; add a concise TODO comment in attributedSubjectKeys noting that these separate queries are intentional but should be combined into a single OR/multi-field query if/when the customer service gains support for OR searches (or add a feature-flagged path to call a combined search method such as ListCustomersWithOr if implemented), referencing the existing fields UsageAttributionSubjectKey and Key and the ListCustomers call so future maintainers can find and replace the two-query approach with a single call.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@openmeter/meterevent/adapter/subject.go`:
- Around line 104-137: The function attributedSubjectKeys currently issues two
ListCustomers calls (via a.customerService.ListCustomers) to match keys against
UsageAttributionSubjectKey and Key; add a concise TODO comment in
attributedSubjectKeys noting that these separate queries are intentional but
should be combined into a single OR/multi-field query if/when the customer
service gains support for OR searches (or add a feature-flagged path to call a
combined search method such as ListCustomersWithOr if implemented), referencing
the existing fields UsageAttributionSubjectKey and Key and the ListCustomers
call so future maintainers can find and replace the two-query approach with a
single call.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7777cf3c-0234-47c6-9ead-9cb9ea1a5d74
⛔ Files ignored due to path filters (1)
api/v3/openapi.yamlis excluded by!**/openapi.yaml
📒 Files selected for processing (32)
api/spec/packages/aip-client-javascript/README.mdapi/spec/packages/aip-client-javascript/src/funcs/events.tsapi/spec/packages/aip-client-javascript/src/index.tsapi/spec/packages/aip-client-javascript/src/models/operations/events.tsapi/spec/packages/aip-client-javascript/src/models/schemas.tsapi/spec/packages/aip-client-javascript/src/models/types.tsapi/spec/packages/aip-client-javascript/src/sdk/events.tsapi/spec/packages/aip/src/events/index.tspapi/spec/packages/aip/src/events/operations.tspapi/spec/packages/aip/src/events/subject.tspapi/spec/packages/aip/src/konnect.tspapi/spec/packages/aip/src/openmeter.tspapi/v3/api.gen.goapi/v3/handlers/events/handler.goapi/v3/handlers/events/list_subjects.goapi/v3/server/routes.goapp/common/streaming.goapp/config/aggregation.goe2e/events_subjects_v3_test.goe2e/v3helpers_test.goopenmeter/meterevent/adapter/subject.goopenmeter/meterevent/adapter/subject_test.goopenmeter/meterevent/service.goopenmeter/meterevent/subject.goopenmeter/meterevent/subject_test.goopenmeter/server/server_test.goopenmeter/streaming/clickhouse/connector.goopenmeter/streaming/clickhouse/subject_query.goopenmeter/streaming/clickhouse/subject_query_test.goopenmeter/streaming/connector.goopenmeter/streaming/retry/retry.goopenmeter/streaming/testutils/streaming.go
Greptile SummaryThis PR adds a new
Confidence Score: 5/5The change is safe to merge. The new endpoint is marked x-internal and x-unstable, the projection is opt-in and off by default, and the scan-loop logic, cursor pagination, and attribution resolution are all correctly implemented. No correctness bugs were found. The multi-batch scan loop correctly handles all edge cases: empty batches, exact full pages, over-full pages, and the scan-round cap. Attribution resolution via two ListCustomers lookups per batch is correct, and the cursor propagation through both early-return paths and the cap path is sound. No files require special attention beyond the minor suggestions on openmeter/streaming/connector.go and openmeter/streaming/clickhouse/subject_query.go. Important Files Changed
|
449cad9 to
3bf0c38
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openmeter/meterevent/adapter/subject.go`:
- Around line 128-131: The accumulator currently only adds attribution values
from c.GetUsageAttribution().GetValues(), missing the customer's own key; update
the loop over customerList.Items (variable c) to also insert the customer's key
into the attributed set (e.g., attributed[c.GetKey()] = struct{}{} or the
appropriate getter used in this type), guarding for empty/nil keys if needed so
the customer's own key match path is preserved for filtering.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c094f8c6-a5aa-4659-9ca7-3cba8a9eb910
⛔ Files ignored due to path filters (1)
api/v3/openapi.yamlis excluded by!**/openapi.yaml
📒 Files selected for processing (32)
api/spec/packages/aip-client-javascript/README.mdapi/spec/packages/aip-client-javascript/src/funcs/events.tsapi/spec/packages/aip-client-javascript/src/index.tsapi/spec/packages/aip-client-javascript/src/models/operations/events.tsapi/spec/packages/aip-client-javascript/src/models/schemas.tsapi/spec/packages/aip-client-javascript/src/models/types.tsapi/spec/packages/aip-client-javascript/src/sdk/events.tsapi/spec/packages/aip/src/events/index.tspapi/spec/packages/aip/src/events/operations.tspapi/spec/packages/aip/src/events/subject.tspapi/spec/packages/aip/src/konnect.tspapi/spec/packages/aip/src/openmeter.tspapi/v3/api.gen.goapi/v3/handlers/events/handler.goapi/v3/handlers/events/list_subjects.goapi/v3/server/routes.goapp/common/streaming.goapp/config/aggregation.goe2e/events_subjects_v3_test.goe2e/v3helpers_test.goopenmeter/meterevent/adapter/subject.goopenmeter/meterevent/adapter/subject_test.goopenmeter/meterevent/service.goopenmeter/meterevent/subject.goopenmeter/meterevent/subject_test.goopenmeter/server/server_test.goopenmeter/streaming/clickhouse/connector.goopenmeter/streaming/clickhouse/subject_query.goopenmeter/streaming/clickhouse/subject_query_test.goopenmeter/streaming/connector.goopenmeter/streaming/retry/retry.goopenmeter/streaming/testutils/streaming.go
✅ Files skipped from review due to trivial changes (2)
- api/spec/packages/aip/src/konnect.tsp
- api/spec/packages/aip-client-javascript/README.md
🚧 Files skipped from review as they are similar to previous changes (27)
- api/spec/packages/aip/src/openmeter.tsp
- api/spec/packages/aip/src/events/index.tsp
- openmeter/streaming/testutils/streaming.go
- api/spec/packages/aip-client-javascript/src/sdk/events.ts
- openmeter/server/server_test.go
- api/v3/handlers/events/handler.go
- app/config/aggregation.go
- app/common/streaming.go
- api/v3/server/routes.go
- e2e/events_subjects_v3_test.go
- openmeter/streaming/retry/retry.go
- api/spec/packages/aip-client-javascript/src/funcs/events.ts
- api/spec/packages/aip-client-javascript/src/index.ts
- openmeter/meterevent/service.go
- api/spec/packages/aip/src/events/subject.tsp
- e2e/v3helpers_test.go
- openmeter/streaming/connector.go
- api/spec/packages/aip/src/events/operations.tsp
- api/spec/packages/aip-client-javascript/src/models/operations/events.ts
- api/v3/handlers/events/list_subjects.go
- openmeter/streaming/clickhouse/subject_query_test.go
- openmeter/meterevent/adapter/subject_test.go
- openmeter/streaming/clickhouse/connector.go
- openmeter/streaming/clickhouse/subject_query.go
- openmeter/meterevent/subject.go
- api/spec/packages/aip-client-javascript/src/models/schemas.ts
- api/spec/packages/aip-client-javascript/src/models/types.ts
| for _, c := range customerList.Items { | ||
| for _, value := range c.GetUsageAttribution().GetValues() { | ||
| attributed[value] = struct{}{} | ||
| } |
There was a problem hiding this comment.
Include customer-key hits in the attributed set.
On Line 128 onward, the accumulator only adds GetUsageAttribution().GetValues(). That misses the “customer’s own key” match path documented above the function, so attributed filtering can drop valid subjects.
💡 Suggested fix
for _, c := range customerList.Items {
+ if c.Key != "" {
+ attributed[c.Key] = struct{}{}
+ }
for _, value := range c.GetUsageAttribution().GetValues() {
attributed[value] = struct{}{}
}
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@openmeter/meterevent/adapter/subject.go` around lines 128 - 131, The
accumulator currently only adds attribution values from
c.GetUsageAttribution().GetValues(), missing the customer's own key; update the
loop over customerList.Items (variable c) to also insert the customer's key into
the attributed set (e.g., attributed[c.GetKey()] = struct{}{} or the appropriate
getter used in this type), guarding for empty/nil keys if needed so the
customer's own key match path is preserved for filtering.
6c4034c to
d9996d4
Compare
d9996d4 to
2b13ab6
Compare
Drop the fake-based adapter scan tests and pin the behavior at the API layer instead: the e2e now attributes one subject via the customer's own key so both usage attribution legs are exercised end-to-end.
|
This pull request has been inactive for 45 days. Push a commit or leave a comment describing the next step to remove the |
|
This pull request was closed after 60 days of inactivity. Closing does not reject the idea; reopen it when the work is ready to continue. |
Summary by CodeRabbit
New Features
Documentation
Tests
Greptile Summary
This PR adds an internal API for listing event subjects. The main changes are:
Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (6): Last reviewed commit: "test(meterevent): replace adapter unit t..." | Re-trigger Greptile
Context used (3)