Skip to content

feat(api): add advancedMeterGroupByFilters to features - #3472

Merged
tothandras merged 3 commits into
mainfrom
feat/api-features-v2
Oct 7, 2025
Merged

tothandras merged 3 commits into
mainfrom
feat/api-features-v2

Conversation

@tothandras

@tothandras tothandras commented Oct 7, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added advancedMeterGroupByFilters to feature data and creation flows, allowing rich logical filters on meter group-by fields (e.g., $in, $eq, $and/$or). API responses and create requests now surface advanced filters and fall back to legacy meterGroupByFilters when advanced filters aren’t provided.
  • Documentation

    • API schemas and examples updated to document and illustrate the new advanced filtering options.

@tothandras
tothandras requested a review from a team as a code owner October 7, 2025 10:54
@tothandras tothandras added kind/feature New feature or request release-note/feature Release note: Exciting New Features and removed kind/feature New feature or request labels Oct 7, 2025
@coderabbitai

coderabbitai Bot commented Oct 7, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds an optional advancedMeterGroupByFilters property across API specs, TypeSpec, client Zod/types, and server code; introduces map converters for FilterString in Go; updates request/response mapping to prefer advancedMeterGroupByFilters with fallback to legacy meterGroupByFilters.

Changes

Cohort / File(s) Summary
API specifications
api/openapi.yaml, api/openapi.cloud.yaml
Added advancedMeterGroupByFilters (object with additionalProperties → FilterString) to Feature and FeatureCreateInputs with descriptions and examples; retained legacy meterGroupByFilters.
Client TypeScript schemas
api/client/javascript/src/client/schemas.ts
Added advancedMeterGroupByFilters?: { [key: string]: components['schemas']['FilterString'] } to Feature and FeatureCreateInputs.
Client validation (Zod)
api/client/javascript/src/zod/index.ts
Extended createFeatureBody and related Zod schemas with optional advancedMeterGroupByFilters as record(string, object(...)) supporting $and, $or, comparison and list operators for FilterString.
TypeSpec definitions
api/spec/src/productcatalog/features.tsp
Replaced meterGroupByFilters in FeatureCreateInputs with advancedMeterGroupByFilters?: Record<FilterString>; updated summary, example, and removed a legacy TODO.
Go converters (API ⇄ internal filters)
openmeter/apiconverter/filter.go, openmeter/apiconverter/filter.gen.go
Added map-level converters and API↔internal helpers: ConvertStringMap, ConvertStringMapPtr, ConvertStringToAPI, ConvertStringMapToAPIPtr, plus recursive conversion helper for FilterString.
Server driver & parser
openmeter/productcatalog/driver/feature.go, openmeter/productcatalog/driver/parser.go
Added MapFeatureCreateInputsRequest(namespace, f) which prefers AdvancedMeterGroupByFilters and falls back to legacy MeterGroupByFilters; response mapping now includes MeterGroupByFilters and AdvancedMeterGroupByFilters.
End-to-end tests / API model
e2e/e2e_test.go
Updated API Feature model to include AdvancedMeterGroupByFilters *map[string]api.FilterString and adjusted test expectations to surface the new field.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change introduced by this pull request, namely the addition of the advancedMeterGroupByFilters feature across the API schemas and related code. It follows a conventional commit style with a clear scope and description, making it easy for maintainers to understand the essence of the change when scanning history.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/api-features-v2

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66985c5 and 59c7d26.

📒 Files selected for processing (1)
  • e2e/e2e_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
e2e/e2e_test.go (4)
api/client/javascript/src/client/schemas.ts (1)
  • FilterString (11615-11615)
api/api.gen.go (1)
  • FilterString (3584-3626)
api/client/go/client.gen.go (1)
  • FilterString (3238-3280)
pkg/convert/ptr.go (1)
  • ToPointer (10-12)
⏰ 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). (6)
  • GitHub Check: Quickstart
  • GitHub Check: E2E
  • GitHub Check: Lint
  • GitHub Check: Code Generators
  • GitHub Check: Build
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
e2e/e2e_test.go (1)

794-798: Expectation for advanced filters looks good.

The added assertion correctly models the $eq constraint for the new advanced filters map and will guard the end-to-end path. Nice coverage.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
api/spec/src/productcatalog/features.tsp (1)

61-67: LGTM! Consider documenting the precedence.

The new advancedMeterGroupByFilters field is well-defined with clear examples. The implementation prioritizes this field over the legacy meterGroupByFilters when both are present.

Consider adding a note in the documentation to clarify that advancedMeterGroupByFilters takes precedence when both fields are provided, or consider deprecating meterGroupByFilters in a future version to reduce confusion.

openmeter/apiconverter/filter.go (1)

29-29: Misleading function name.

ConvertStringMapToAPIPtr returns map[string]api.FilterString (not a pointer), but the Ptr suffix suggests it should return *map[string]api.FilterString. Consider renaming to ConvertStringMapToAPI to align the name with the actual return type.

Apply this diff to clarify the function name:

-	ConvertStringMapToAPIPtr func(map[string]filter.FilterString) map[string]api.FilterString
+	ConvertStringMapToAPI func(map[string]filter.FilterString) map[string]api.FilterString

Note: If this naming is a goverter convention or is used consistently elsewhere in the codebase, you may choose to keep it as-is.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e90abbf and d275440.

📒 Files selected for processing (9)
  • api/client/javascript/src/client/schemas.ts (2 hunks)
  • api/client/javascript/src/zod/index.ts (1 hunks)
  • api/openapi.cloud.yaml (2 hunks)
  • api/openapi.yaml (2 hunks)
  • api/spec/src/productcatalog/features.tsp (1 hunks)
  • openmeter/apiconverter/filter.gen.go (3 hunks)
  • openmeter/apiconverter/filter.go (1 hunks)
  • openmeter/productcatalog/driver/feature.go (2 hunks)
  • openmeter/productcatalog/driver/parser.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
openmeter/productcatalog/driver/parser.go (5)
api/api.gen.go (4)
  • Feature (3432-3465)
  • Metadata (4954-4954)
  • FeatureCreateInputs (3469-3487)
  • FilterString (3584-3626)
openmeter/productcatalog/feature/feature.go (4)
  • Feature (120-143)
  • ConvertMeterGroupByFiltersToMapString (102-116)
  • MeterGroupByFilters (67-67)
  • ConvertMapStringToMeterGroupByFilters (87-98)
pkg/convert/ptr.go (2)
  • MapToPointer (16-21)
  • DerefHeaderPtr (59-64)
openmeter/apiconverter/filter.go (2)
  • ConvertStringMapToAPIPtr (29-29)
  • ConvertStringMapPtr (16-16)
openmeter/productcatalog/feature/connector.go (1)
  • CreateFeatureInputs (17-24)
openmeter/productcatalog/driver/feature.go (1)
openmeter/productcatalog/driver/parser.go (1)
  • MapFeatureCreateInputsRequest (30-46)
openmeter/apiconverter/filter.gen.go (3)
openmeter/apiconverter/filter.go (5)
  • ConvertStringMap (15-15)
  • ConvertString (13-13)
  • ConvertStringMapPtr (16-16)
  • ConvertStringMapToAPIPtr (29-29)
  • ConvertStringToAPI (28-28)
api/api.gen.go (1)
  • FilterString (3584-3626)
pkg/filter/filter.go (1)
  • FilterString (32-47)
openmeter/apiconverter/filter.go (2)
api/api.gen.go (1)
  • FilterString (3584-3626)
pkg/filter/filter.go (1)
  • FilterString (32-47)
⏰ 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). (7)
  • GitHub Check: Artifacts / Container image
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: Test
  • GitHub Check: Code Generators
  • GitHub Check: Build
  • GitHub Check: Analyze (go)
🔇 Additional comments (14)
openmeter/productcatalog/driver/feature.go (1)

109-109: LGTM! Clean refactoring.

Delegating to MapFeatureCreateInputsRequest centralizes the mapping logic and properly handles the new advanced filter selection.

openmeter/productcatalog/driver/parser.go (2)

30-46: LGTM! Clear fallback logic.

The function correctly prioritizes advancedMeterGroupByFilters over legacy meterGroupByFilters, with the behavior explicitly documented in comments. The use of lo.FromPtrOr appropriately handles nil pointers with sensible defaults.


25-25: JSON tag for AdvancedMeterGroupByFilters is correct. Both Feature and FeatureCreateInputs use json:"advancedMeterGroupByFilters,omitempty", so no changes required.

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

5732-5750: Advanced filters typed correctly

Nice touch aligning the advanced filters with FilterString; the inline example helps consumers understand the expected shape.


5794-5811: Consistent schema surface

Duplicating the advanced filter option here keeps the feature summary shape in sync with the full resource—looks good.

openmeter/apiconverter/filter.gen.go (5)

150-159: LGTM!

The map conversion correctly handles nil input, pre-sizes the result map, and applies ConvertString to each value.


160-167: LGTM!

Standard pointer wrapper pattern correctly implemented.


168-177: LGTM!

The conversion logic is correct: nil-safe map creation with proper sizing and per-value conversion via the helper function. Note that the function name includes Ptr but doesn't return a pointer—this mirrors the signature defined in the configuration file.


186-193: LGTM!

Standard pointer conversion pattern correctly implemented with proper nil handling.


231-266: LGTM!

The inverse conversion helper correctly:

  • Recursively processes nested And/Or filters
  • Copies all primitive fields (Eq, Ne, In, Nin, Like, Nlike, Ilike, Nilike, Gt, Gte, Lt, Lte)
  • Maintains nil-safety throughout
api/openapi.cloud.yaml (2)

16952-16966: Schema addition aligns with advanced filters

The optional object with FilterString values fits the new advanced group-by filter plumbing and keeps the examples in sync. Nicely done.


17020-17033: Consistent addition across feature schemas

Mirrors the earlier schema update so the advanced filters remain uniformly documented. Looks good.

api/openapi.yaml (2)

17324-17338: Schema addition matches FilterString contract.

Mirrors the existing meterGroupByFilters pattern precisely, so the advanced map will validate and document as expected. Nicely done.


17392-17405: Consistent create-input schema.

Creation payload now accepts the same advanced filter map, keeping API surface aligned. All good.

Comment thread api/client/javascript/src/zod/index.ts Resolved
GAlexIHU
GAlexIHU previously approved these changes Oct 7, 2025
GAlexIHU
GAlexIHU previously approved these changes Oct 7, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
api/client/javascript/src/zod/index.ts (1)

7935-8004: Restore recursive typing for $and/$or.

zod.array(zod.any()) still bypasses validation and erases type inference, so malformed nested filters slip through—exactly the issue already flagged earlier. Please switch these to arrays of the same filter schema (via zod.lazy) so nested filters remain strongly validated.

+const advancedMeterGroupByStringFilter: zod.ZodTypeAny = zod.lazy(() =>
+  zod
+    .object({
+      $and: zod
+        .array(advancedMeterGroupByStringFilter)
+        .nullish()
+        .describe(
+          'Provide a list of filters to be combined with a logical AND.',
+        ),
+      $eq: zod.coerce
+        .string()
+        .nullish()
+        .describe('The field must be equal to the provided value.'),
+      ...
+      $or: zod
+        .array(advancedMeterGroupByStringFilter)
+        .nullish()
+        .describe(
+          'Provide a list of filters to be combined with a logical OR.',
+        ),
+    })
+    .describe('A filter for a string field.'),
+);
+
 export const createFeatureBody = zod
   .object({
     advancedMeterGroupByFilters: zod
       .record(
         zod.string(),
-        zod
-          .object({
-            $and: zod
-              .array(zod.any())
-              .nullish()
-              .describe(
-                'Provide a list of filters to be combined with a logical AND.',
-              ),
-            ...
-            $or: zod
-              .array(zod.any())
-              .nullish()
-              .describe(
-                'Provide a list of filters to be combined with a logical OR.',
-              ),
-          })
-          .describe('A filter for a string field.'),
+        advancedMeterGroupByStringFilter,
       )
       .optional()
🧹 Nitpick comments (2)
api/spec/src/productcatalog/features.tsp (1)

51-59: Consider adding a deprecation notice to the legacy field.

Since advancedMeterGroupByFilters is being introduced as the preferred approach and the implementation falls back to meterGroupByFilters only when advanced filters are not provided, consider marking this field as deprecated to guide users toward the new API.

Apply this diff to add a deprecation notice:

  /**
   * Optional meter group by filters.
   * Useful if the meter scope is broader than what feature tracks.
   * Example scenario would be a meter tracking all token use with groupBy fields for the model,
   * then the feature could filter for model=gpt-4.
+  * @deprecated Use advancedMeterGroupByFilters instead for more powerful filtering capabilities.
   */
  @summary("Meter group by filters")
  @example(#{ `model`: "gpt-4", type: "input" })
  meterGroupByFilters?: Record<string>;
openmeter/apiconverter/filter.go (1)

28-29: Consider renaming ConvertStringMapToAPIPtr for clarity.

The reverse converters are functionally correct and properly support bidirectional conversion between internal and API types. However, the naming could be improved:

  • ConvertStringMapToAPIPtr has a "Ptr" suffix but works with map[string]filter.FilterString → map[string]api.FilterString (no pointer to map involved)
  • Compare with ConvertStringMapPtr (line 16), which correctly uses "Ptr" for *map[string]... → *map[string]...

Consider renaming to ConvertStringMapToAPI to match the actual signature, or if a pointer variant is needed, add it separately.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d275440 and b645fb6.

📒 Files selected for processing (9)
  • api/client/javascript/src/client/schemas.ts (2 hunks)
  • api/client/javascript/src/zod/index.ts (1 hunks)
  • api/openapi.cloud.yaml (2 hunks)
  • api/openapi.yaml (2 hunks)
  • api/spec/src/productcatalog/features.tsp (1 hunks)
  • openmeter/apiconverter/filter.gen.go (3 hunks)
  • openmeter/apiconverter/filter.go (1 hunks)
  • openmeter/productcatalog/driver/feature.go (2 hunks)
  • openmeter/productcatalog/driver/parser.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • openmeter/productcatalog/driver/feature.go
  • openmeter/apiconverter/filter.gen.go
  • openmeter/productcatalog/driver/parser.go
🧰 Additional context used
🧬 Code graph analysis (1)
openmeter/apiconverter/filter.go (2)
api/api.gen.go (6)
  • FilterString (3584-3626)
  • FilterIDExact (3551-3554)
  • FilterInteger (3557-3581)
  • FilterFloat (3524-3548)
  • FilterTime (3629-3647)
  • FilterBoolean (3518-3521)
pkg/filter/filter.go (5)
  • FilterString (32-47)
  • FilterInteger (161-170)
  • FilterFloat (270-279)
  • FilterTime (378-385)
  • FilterBoolean (481-483)
⏰ 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). (7)
  • GitHub Check: Artifacts / Container image
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: Test
  • GitHub Check: Code Generators
  • GitHub Check: Build
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
api/client/javascript/src/client/schemas.ts (2)

5794-5812: LGTM! Consistent schema extension.

The addition mirrors the Feature schema change, ensuring consistent advanced filtering capabilities across both read and create operations.


5732-5750: LGTM The FilterString schema supports the $eq and $in operators used in the example.

api/openapi.cloud.yaml (1)

16952-16966: Additive schema change LGTM

The new advancedMeterGroupByFilters property cleanly extends the schema with optional advanced filter semantics, keeps backward compatibility, and mirrors the existing examples for clarity. Nicely done.

Also applies to: 17019-17033

openmeter/apiconverter/filter.go (2)

15-16: LGTM! New map-level converters align with the PR objective.

The addition of ConvertStringMap and ConvertStringMapPtr correctly supports the new advanced filter map functionality. The type signatures are accurate and follow the existing naming pattern.


18-27: LGTM! Reordering has no functional impact.

The reordering of existing converter declarations is cosmetic only and does not affect the generated code functionality.

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.

2 participants