Skip to content

Conversation

@GAlexIHU
Copy link
Contributor

@GAlexIHU GAlexIHU commented Oct 1, 2025

Adds e2e tests to assert this works as expected and adds a missing mapping.

Overview

Fixes #(issue)

Notes for reviewer

Summary by CodeRabbit

  • New Features

    • Added metadata support when creating entitlement grants.
    • Metadata is now returned when retrieving entitlement grants.
    • Improved propagation of metadata throughout grant creation for more complete records.
  • Tests

    • Added end-to-end validation ensuring annotations created via the newer API are readable via the legacy API, confirming cross-version parity.

Adds e2e tests to assert this works as expected and adds a missing mapping.
@GAlexIHU GAlexIHU requested a review from a team as a code owner October 1, 2025 14:27
@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Oct 1, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 1, 2025

📝 Walkthrough

Walkthrough

Adds Metadata to entitlement grant create input and output types, updates e2e tests to set/assert Metadata, introduces an annotations parity test across V2 create and V1 get, and propagates Metadata during metered grant creation to the underlying CreateGrant input.

Changes

Cohort / File(s) Summary of changes
Entitlement grant Metadata in tests
e2e/e2e_test.go
Tests updated to include Metadata on EntitlementGrantCreateInput and EntitlementGrant assertions.
Cross-API annotations parity test
e2e/entitlement_parity_test.go
Adds test ensuring annotations set via V2 create are visible via V1 get.
Metadata propagation in metered grants
openmeter/entitlement/metered/entitlement_grant.go
Passes Metadata from CreateEntitlementGrantInputs into credit.CreateGrantInput.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 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 33.33% 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 pull request title clearly states that it addresses a fix in the grant creation mapping logic, which aligns with the main change of adding the missing metadata/annotations mapping during entitlement grant creation.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/entitlements/grant-metadata-annotations

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.

Copy link
Contributor

@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)
e2e/entitlement_parity_test.go (1)

372-403: Test only verifies Annotations but not Metadata.

The test name "Annotations and metadata parity (create and get)" suggests it should test both Annotations and Metadata, but the implementation only verifies Annotations. Since this PR adds Metadata mapping support, consider adding assertions for Metadata as well to ensure complete coverage of the fix.

Apply this diff to add Metadata verification:

 		t.Run("Annotations created with V2 API should show up in V1 API", func(t *testing.T) {
 			createGrantResponse, err := client.CreateCustomerEntitlementGrantV2WithResponse(ctx, customerID, feature1Key, api.CreateCustomerEntitlementGrantV2JSONRequestBody{
 				Amount:      100,
 				EffectiveAt: time.Now().Truncate(time.Minute).Add(time.Minute),
 				Expiration:  nil,
 				Annotations: &api.Annotations{
 					"some_annotation": "some_annotation_value",
 				},
+				Metadata: &api.Metadata{
+					"some_metadata_key": "some_metadata_value",
+				},
 			})
 			require.NoError(t, err)
 			require.Equal(t, http.StatusCreated, createGrantResponse.StatusCode(), "Invalid status code [response_body=%s]", string(createGrantResponse.Body))
 
 			getGrantResponse, err := client.ListEntitlementGrantsWithResponse(ctx, subjectKey, feature1Key, &api.ListEntitlementGrantsParams{})
 			require.NoError(t, err)
 			require.Equal(t, http.StatusOK, getGrantResponse.StatusCode(), "Invalid status code [response_body=%s]", string(getGrantResponse.Body))
 			require.NotNil(t, getGrantResponse.JSON200)
 			require.GreaterOrEqual(t, len(lo.FromPtr(getGrantResponse.JSON200)), 1, "Invalid number of grants [response_body=%s]", string(getGrantResponse.Body))
 
 			var found *api.EntitlementGrant
 
 			for _, grant := range lo.FromPtr(getGrantResponse.JSON200) {
 				if grant.Id == createGrantResponse.JSON201.Id {
 					found = &grant
 					break
 				}
 			}
 
 			require.NotNil(t, found, "Grant not found [response_body=%s]", string(getGrantResponse.Body))
 			require.Equal(t, "some_annotation_value", lo.FromPtr(found.Annotations)["some_annotation"])
+			require.Equal(t, "some_metadata_value", lo.FromPtr(found.Metadata)["some_metadata_key"])
 		})
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1696b9c and 8c86fa8.

📒 Files selected for processing (3)
  • e2e/e2e_test.go (2 hunks)
  • e2e/entitlement_parity_test.go (1 hunks)
  • openmeter/entitlement/metered/entitlement_grant.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
e2e/entitlement_parity_test.go (1)
api/api.gen.go (4)
  • CreateCustomerEntitlementGrantV2JSONRequestBody (9164-9164)
  • Annotations (1036-1036)
  • ListEntitlementGrantsParams (8741-8744)
  • EntitlementGrant (2775-2833)
e2e/e2e_test.go (3)
api/client/javascript/src/client/schemas.ts (1)
  • Metadata (11689-11689)
api/api.gen.go (1)
  • Metadata (4946-4946)
api/client/go/client.gen.go (1)
  • Metadata (4479-4479)
openmeter/entitlement/metered/entitlement_grant.go (3)
api/client/javascript/src/client/schemas.ts (1)
  • Metadata (11689-11689)
api/api.gen.go (1)
  • Metadata (4946-4946)
api/client/go/client.gen.go (1)
  • Metadata (4479-4479)
⏰ 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). (8)
  • GitHub Check: Artifacts / Container image
  • GitHub Check: Artifacts / Benthos Collector Container image
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: Build
  • GitHub Check: Code Generators
  • GitHub Check: Test
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
openmeter/entitlement/metered/entitlement_grant.go (1)

80-80: LGTM! Metadata propagation is correctly implemented.

The addition of Metadata field mapping is consistent with the existing Annotations pattern and correctly propagates metadata from the input to the underlying grant creation.

e2e/e2e_test.go (2)

959-961: LGTM! Metadata field correctly added to grant creation.

The Metadata field is properly included in the grant creation input, ensuring the new mapping is exercised in the e2e test.


988-990: LGTM! Expected grant output includes Metadata.

The expected grant response correctly includes the Metadata field, verifying that metadata is properly propagated through the grant creation and retrieval flow.

@GAlexIHU GAlexIHU enabled auto-merge (squash) October 1, 2025 14:34
@GAlexIHU GAlexIHU merged commit 4b6727e into main Oct 1, 2025
30 of 31 checks passed
@GAlexIHU GAlexIHU deleted the fix/entitlements/grant-metadata-annotations branch October 1, 2025 14:41
@coderabbitai coderabbitai bot mentioned this pull request Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants