Repository navigation
feat: change internal feature & meter query filters type - #3462
Conversation
📝 WalkthroughWalkthroughMeterGroupByFilters/FilterGroupBy types replaced from simple string/slice maps to map[string]filter.FilterString across the codebase; helpers, validation, tests, HTTP mapping, entitlement/billing, and ClickHouse SQL generation were updated to use and validate FilterString and produce parameterized WHERE expressions. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
test/notification/consumer_balance.go (1)
135-141: Fix pointer aliasing inConvertMapStringToMeterGroupByFilters.
feature.ConvertMapStringToMeterGroupByFilterscurrently builds eachFilterStringas{Eq: &v}wherevis the range variable. Go reuses the same storage forv, so every entry returned by this helper ends up pointing to the last iterated value. The moment you call it here the resulting filters collapse to a single value, breaking all downstream filtering. Please copy the value before taking its address:diff --git a/openmeter/productcatalog/feature/feature.go b/openmeter/productcatalog/feature/feature.go @@ - for k, v := range m { - result[k] = filter.FilterString{Eq: &v} - } + for k, v := range m { + value := v + result[k] = filter.FilterString{Eq: &value} + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
go.sumis excluded by!**/*.sumtools/migrate/migrations/atlas.sumis excluded by!**/*.sum
📒 Files selected for processing (26)
openmeter/billing/service/lineservice/meters.go(1 hunks)openmeter/ent/db/feature.go(2 hunks)openmeter/ent/db/feature_create.go(5 hunks)openmeter/ent/db/feature_update.go(3 hunks)openmeter/ent/db/mutation.go(5 hunks)openmeter/ent/db/setorclear.go(2 hunks)openmeter/ent/schema/feature.go(2 hunks)openmeter/entitlement/metered/balance_test.go(3 hunks)openmeter/entitlement/metered/grant_owner_adapter.go(1 hunks)openmeter/entitlement/metered/lateevents_test.go(2 hunks)openmeter/entitlement/metered/reset_test.go(2 hunks)openmeter/meter/httphandler/mapping.go(2 hunks)openmeter/productcatalog/adapter/feature_test.go(5 hunks)openmeter/productcatalog/driver/feature.go(1 hunks)openmeter/productcatalog/driver/parser.go(1 hunks)openmeter/productcatalog/feature/feature.go(4 hunks)openmeter/productcatalog/testutils/feature.go(1 hunks)openmeter/streaming/clickhouse/meter_query.go(3 hunks)openmeter/streaming/clickhouse/meter_query_test.go(5 hunks)openmeter/streaming/query_params.go(3 hunks)test/notification/consumer_balance.go(3 hunks)test/notification/event.go(1 hunks)test/notification/rule.go(1 hunks)tools/migrate/feature_meter_group_by_filters_test.go(1 hunks)tools/migrate/migrations/20251005111411_feature-meter-group-by-filters.down.sql(1 hunks)tools/migrate/migrations/20251005111411_feature-meter-group-by-filters.up.sql(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (19)
openmeter/entitlement/metered/grant_owner_adapter.go (1)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)
openmeter/billing/service/lineservice/meters.go (2)
openmeter/ent/db/feature.go (2)
Feature(18-46)Feature(89-104)openmeter/productcatalog/feature/feature.go (2)
Feature(120-143)MeterGroupByFilters(67-67)
openmeter/ent/db/setorclear.go (2)
openmeter/ent/db/feature_update.go (2)
FeatureUpdate(23-27)FeatureUpdateOne(471-476)api/api.gen.go (1)
FilterString(3576-3618)
openmeter/streaming/clickhouse/meter_query.go (2)
api/api.gen.go (2)
FilterString(3576-3618)Meter(4949-4998)openmeter/meter/meter.go (1)
Meter(139-148)
openmeter/streaming/clickhouse/meter_query_test.go (2)
api/api.gen.go (1)
FilterString(3576-3618)api/client/go/client.gen.go (1)
FilterString(3230-3272)
test/notification/rule.go (1)
openmeter/productcatalog/feature/feature.go (2)
MeterGroupByFilters(67-67)ConvertMapStringToMeterGroupByFilters(87-98)
test/notification/consumer_balance.go (1)
openmeter/productcatalog/feature/feature.go (2)
MeterGroupByFilters(67-67)ConvertMapStringToMeterGroupByFilters(87-98)
openmeter/streaming/query_params.go (2)
api/api.gen.go (1)
FilterString(3576-3618)pkg/models/validator.go (1)
Validate(16-26)
openmeter/entitlement/metered/reset_test.go (2)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)api/api.gen.go (1)
FilterString(3576-3618)
openmeter/productcatalog/adapter/feature_test.go (2)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)api/api.gen.go (1)
FilterString(3576-3618)
openmeter/productcatalog/testutils/feature.go (1)
openmeter/productcatalog/feature/feature.go (2)
MeterGroupByFilters(67-67)ConvertMapStringToMeterGroupByFilters(87-98)
openmeter/entitlement/metered/balance_test.go (2)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)api/api.gen.go (1)
FilterString(3576-3618)
openmeter/ent/db/feature.go (1)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)
openmeter/productcatalog/driver/parser.go (3)
openmeter/ent/db/feature.go (2)
Feature(18-46)Feature(89-104)openmeter/productcatalog/feature/feature.go (3)
Feature(120-143)ConvertMeterGroupByFiltersToMapString(102-116)MeterGroupByFilters(67-67)api/api.gen.go (2)
Feature(3432-3461)Metadata(4946-4946)
openmeter/meter/httphandler/mapping.go (1)
api/api.gen.go (1)
FilterString(3576-3618)
test/notification/event.go (1)
openmeter/productcatalog/feature/feature.go (2)
MeterGroupByFilters(67-67)ConvertMapStringToMeterGroupByFilters(87-98)
openmeter/ent/db/mutation.go (3)
api/api.gen.go (1)
FilterString(3576-3618)api/client/go/client.gen.go (1)
FilterString(3230-3272)openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)
openmeter/entitlement/metered/lateevents_test.go (2)
openmeter/productcatalog/feature/feature.go (1)
MeterGroupByFilters(67-67)api/api.gen.go (1)
FilterString(3576-3618)
openmeter/productcatalog/driver/feature.go (3)
openmeter/productcatalog/feature/feature.go (2)
ConvertMapStringToMeterGroupByFilters(87-98)MeterGroupByFilters(67-67)openmeter/productcatalog/feature/connector.go (1)
CreateFeatureInputs(17-24)openmeter/ent/db/feature/where.go (1)
MeterSlug(99-101)
⏰ 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: Test
- GitHub Check: Lint
- GitHub Check: Migration Checks
- GitHub Check: Code Generators
- GitHub Check: Build
- GitHub Check: Analyze (go)
🔇 Additional comments (13)
openmeter/streaming/query_params.go (3)
9-9: LGTM: Filter package import added.The import supports the new
filter.FilterStringtype used inFilterGroupBy.
19-19: LGTM: Type migration to FilterString.The migration from
map[string][]stringtomap[string]filter.FilterStringprovides a more structured and type-safe representation for group-by filters.
61-66: LGTM: Per-filter validation added.The validation loop ensures that each
FilterStringinFilterGroupByis validated individually, accumulating errors appropriately. This is a necessary addition to maintain data integrity with the new filter type.openmeter/productcatalog/testutils/feature.go (1)
30-30: LGTM: Conversion helper applied correctly.The use of
ConvertMapStringToMeterGroupByFiltersproperly converts the legacymeter.GroupBymap to the newMeterGroupByFilterstype.openmeter/ent/db/feature.go (2)
14-14: LGTM: Filter import added to generated code.The import supports the updated
MeterGroupByFiltersfield type.
39-39: LGTM: Generated field type updated.The
MeterGroupByFiltersfield type has been updated tomap[string]filter.FilterStringin the generated code, consistent with the schema changes.openmeter/billing/service/lineservice/meters.go (1)
63-65: LGTM: Simplified assignment pattern.The direct assignment is cleaner and more efficient than the previous approach of iterating and building a new map. This is possible because
Feature.MeterGroupByFiltersis now already of the correct type (map[string]filter.FilterString).test/notification/rule.go (1)
107-107: LGTM: Conversion helper applied correctly.The use of
ConvertMapStringToMeterGroupByFiltersproperly converts the legacymeter.GroupBymap to the newMeterGroupByFilterstype, consistent with the broader migration pattern.openmeter/entitlement/metered/grant_owner_adapter.go (1)
108-110: LGTM: Simplified assignment pattern.The direct assignment is cleaner and more efficient than iterating and building a new map. This works because
feature.MeterGroupByFiltersis now already of typemap[string]filter.FilterString.openmeter/productcatalog/driver/feature.go (1)
104-111: LGTM: Clean conversion and assignment pattern.The code properly converts the incoming
MeterGroupByFiltersfrom the request body usingConvertMapStringToMeterGroupByFilters, with appropriate nil handling vialo.FromPtrOr. Computing the value before struct construction improves readability.test/notification/event.go (1)
200-200: LGTM: Conversion helper applied correctly.The use of
ConvertMapStringToMeterGroupByFiltersproperly converts the legacym.GroupBymap to the newMeterGroupByFilterstype, maintaining consistency with the migration pattern used across the codebase.openmeter/ent/schema/feature.go (1)
32-32: Confirm zero-value JSON default works
field.JSON(..., map[string]filter.FilterString{})uses the zero value of our new filter type. Please double-check Ent still serializes this as{}rather thannull, otherwise existing rows w/out filters may fail validation.openmeter/meter/httphandler/mapping.go (1)
164-176: Handle empty filter arrays explicitlyIf the client passes
FilterGroupBy[k]=[], we now drop the key entirely instead of translating it. Previously we kept[]string{}which meant “no values ⇒ match nothing/ everything?”. Please ensure this behavior change is intentional and covered by tests. If empty slices should translate to$in: [], populateFilterString{In: lo.ToPtr([]string{})}instead.
99edf29 to
d69c188
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
openmeter/productcatalog/driver/feature.go (1)
72-76: LGTM! Proper error handling and type conversion.The handler correctly:
- Fetches the feature from the connector
- Returns early on error
- Maps the internal type to the API response type
The dereference on line 76 is safe assuming
GetFeaturefollows Go conventions (returning non-nil pointer when error is nil). For extra defensive programming, you could add a nil check, but it's not required given standard Go patterns.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
openmeter/productcatalog/driver/feature.go(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
openmeter/productcatalog/driver/feature.go (5)
openmeter/productcatalog/feature/feature.go (3)
Feature(120-143)ConvertMapStringToMeterGroupByFilters(87-98)MeterGroupByFilters(67-67)api/api.gen.go (2)
Feature(3432-3461)Metadata(4946-4946)openmeter/productcatalog/driver/parser.go (1)
MapFeatureToResponse(10-25)pkg/convert/ptr.go (1)
DerefHeaderPtr(59-64)pkg/framework/commonhttp/encoder.go (1)
JSONResponseEncoderWithStatus(65-69)
⏰ 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: E2E
- GitHub Check: Quickstart
- GitHub Check: Lint
- GitHub Check: Test
- GitHub Check: Code Generators
- GitHub Check: Build
- GitHub Check: Analyze (go)
🔇 Additional comments (4)
openmeter/productcatalog/driver/feature.go (4)
52-52: LGTM! Type change aligns with API separation.The change from
*feature.Featuretoapi.Featureproperly separates internal domain types from API responses, improving the boundary between layers.
89-89: LGTM! Consistent type change.The response type change to
api.Featuremaintains consistency with theGetFeaturehandler and properly separates API types from internal domain types.
108-115: LGTM! Proper conversion from API to internal types.The implementation correctly:
- Handles optional API field with
lo.FromPtrOrproviding a safe default- Converts from
map[string]stringto the newMeterGroupByFilterstype- Aligns with the PR objective to migrate to
map[string]filter.FilterStringThe conversion logic properly handles nil/empty cases and maintains type safety.
119-126: LGTM! Consistent handler implementation.The handler implementation correctly:
- Creates the feature through the connector
- Handles errors appropriately
- Maps the internal type to the API response using
MapFeatureToResponse- Uses explicit type parameter on line 126 for clarity
The pattern is consistent with
GetFeatureand properly separates internal domain logic from API responses.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
openmeter/productcatalog/driver/parser.go (1)
4-5: Inconsistent pointer utility usage.The introduction of
lo.ToPtralongside the existingconvert.MapToPointercreates inconsistency in how map pointers are handled across this function. Consider standardizing on one approach for consistency.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
openmeter/productcatalog/driver/parser.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
openmeter/productcatalog/driver/parser.go (3)
openmeter/productcatalog/feature/feature.go (3)
Feature(120-143)ConvertMeterGroupByFiltersToMapString(102-116)MeterGroupByFilters(67-67)api/api.gen.go (2)
Feature(3432-3461)Metadata(4946-4946)pkg/convert/ptr.go (1)
MapToPointer(16-21)
⏰ 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). (9)
- GitHub Check: Artifacts / Benthos Collector Container image
- GitHub Check: Migration Checks
- GitHub Check: Artifacts / Container image
- GitHub Check: Test
- GitHub Check: Code Generators
- GitHub Check: Lint
- GitHub Check: Build
- GitHub Check: Repository Scan
- GitHub Check: Analyze (go)
🔇 Additional comments (2)
openmeter/productcatalog/driver/parser.go (2)
23-23: LGTM!The use of
convert.MapToPointeron the convertedmeterGroupByFilterscorrectly handles the case where the conversion returnsnilor an empty map, ensuring the API field is omitted appropriately.
12-13: ```bash
#!/bin/bashFind and inspect ConvertMeterGroupByFiltersToMapString implementation
rg -n "ConvertMeterGroupByFiltersToMapString" -C3
</blockquote></details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
a77997d to
f0cbefd
Compare
Summary by CodeRabbit
New Features
Improvements
Tests