Repository navigation
feat(api): add advancedMeterGroupByFilters to features - #3472
Conversation
📝 WalkthroughWalkthroughAdds 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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)e2e/e2e_test.go (4)
⏰ 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)
🔇 Additional comments (1)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
api/spec/src/productcatalog/features.tsp (1)
61-67: LGTM! Consider documenting the precedence.The new
advancedMeterGroupByFiltersfield is well-defined with clear examples. The implementation prioritizes this field over the legacymeterGroupByFilterswhen both are present.Consider adding a note in the documentation to clarify that
advancedMeterGroupByFilterstakes precedence when both fields are provided, or consider deprecatingmeterGroupByFiltersin a future version to reduce confusion.openmeter/apiconverter/filter.go (1)
29-29: Misleading function name.
ConvertStringMapToAPIPtrreturnsmap[string]api.FilterString(not a pointer), but thePtrsuffix suggests it should return*map[string]api.FilterString. Consider renaming toConvertStringMapToAPIto 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.FilterStringNote: 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
📒 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
MapFeatureCreateInputsRequestcentralizes 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
advancedMeterGroupByFiltersover legacymeterGroupByFilters, with the behavior explicitly documented in comments. The use oflo.FromPtrOrappropriately handles nil pointers with sensible defaults.
25-25: JSON tag for AdvancedMeterGroupByFilters is correct. BothFeatureandFeatureCreateInputsusejson:"advancedMeterGroupByFilters,omitempty", so no changes required.api/client/javascript/src/client/schemas.ts (2)
5732-5750: Advanced filters typed correctlyNice touch aligning the advanced filters with
FilterString; the inline example helps consumers understand the expected shape.
5794-5811: Consistent schema surfaceDuplicating 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
ConvertStringto 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
Ptrbut 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/Orfilters- 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 filtersThe optional object with
FilterStringvalues fits the new advanced group-by filter plumbing and keeps the examples in sync. Nicely done.
17020-17033: Consistent addition across feature schemasMirrors 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
meterGroupByFilterspattern 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.
d275440 to
b645fb6
Compare
There was a problem hiding this comment.
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 (viazod.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
advancedMeterGroupByFiltersis being introduced as the preferred approach and the implementation falls back tometerGroupByFiltersonly 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 renamingConvertStringMapToAPIPtrfor clarity.The reverse converters are functionally correct and properly support bidirectional conversion between internal and API types. However, the naming could be improved:
ConvertStringMapToAPIPtrhas a "Ptr" suffix but works withmap[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
ConvertStringMapToAPIto 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
📒 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
Featureschema change, ensuring consistent advanced filtering capabilities across both read and create operations.
5732-5750: LGTM TheFilterStringschema supports the$eqand$inoperators used in the example.api/openapi.cloud.yaml (1)
16952-16966: Additive schema change LGTMThe new
advancedMeterGroupByFiltersproperty 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
ConvertStringMapandConvertStringMapPtrcorrectly 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.
Summary by CodeRabbit
New Features
Documentation