Registry Mirror
Skip to content

Conversation

@nisan-abeywickrama

Copy link
Copy Markdown
Contributor

Purpose

The gateway part of API monetization: a subscription carries its billing identifiers, and gateway analytics link a paid subscription's calls to its billing customer in Moesif, so Moesif can bill the usage. Split out of #3932 to keep each PR within 100 files.

Goals

  • The gateway controller keeps a subscription's billing customer and billing subscription, whether set through its REST API or sent by the control plane.
  • Gateway analytics link a paid subscription's calls to its billing customer in Moesif, so Moesif can bill the usage.

Approach

  • Gateway controller: a subscription carries its billing customer and billing subscription.
  • Policy engine: the Moesif publisher sets the event's company to the subscription's billing customer.

User stories

  • As a customer, my paid subscription's usage is billed to me, including calls over a quota that does not stop at it.

Documentation

N/A

Automation tests

  • Unit tests

    Patch coverage of this PR's new lines: gateway controller 100% (8 lines); policy engine 100% (20 lines).

  • Integration tests

    subscription_management.feature: a subscription's billing identifiers survive plan, token and status changes. subscription_analytics.feature: analytics carry a paid subscription's billing fields, and refused, throttled and free calls aren't attributed to a billing customer. On gateways newer than 1.2.0 only (runners subscription-analytics-billing-customer and platform-api-paid-subscription-suspension): calls are attributed to the billing customer under the operation's path template and over quota (subscription_analytics_billing_customer.feature), and suspending and resuming a paid subscription keeps its billing (paid_subscription_suspension.feature).

Security checks

Samples

N/A

Related PRs

Test environment

  • macOS, Docker (Colima), Go 1.26
  • Databases: SQLite and PostgreSQL

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 3e610d3 and fa0911f.

Files selected for processing: 7
  • platform-api/internal/client/http_retry_client.go
  • platform-api/internal/client/http_retry_client_test.go
  • platform-api/internal/repository/monetization.go
  • platform-api/internal/repository/monetization_test.go
  • platform-api/internal/repository/subscription_plan_repository.go
  • platform-api/internal/repository/subscription_plan_test.go
  • tests/framework/suites/it/it-suite.yaml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The changes carry subscription billing identifiers through gateway updates and analytics. They also update retryable HTTP client construction, batch subscription billing lookups, and accept blank REST API plan configuration.

Changes: Subscription billing IDs and analytics

Layer / File(s) Summary
Billing IDs in subscription updates
gateway/gateway-controller/pkg/controlplane/events.go, gateway/gateway-controller/pkg/controlplane/client.go, gateway/gateway-controller/pkg/utils/subscription_resource.go, gateway/gateway-controller/pkg/controlplane/api_deleted_test.go, gateway/gateway-controller/pkg/utils/subscription_resource_test.go, tests/framework/suites/it/features/gateway/core/subscription_management.feature
The update payload adds optional billing identifiers. Update handling preserves stored identifiers when new values are empty, and subscription field copying includes both IDs. Tests check identifier persistence across updates and subscription operations.
Moesif billing attribution and assertions
gateway/gateway-runtime/policy-engine/internal/analytics/publishers/moesif.go, gateway/gateway-runtime/policy-engine/internal/analytics/publishers/moesif_test.go, tests/framework/suites/it/steps/platformgateway/gateway.go, tests/framework/suites/it/steps/platformgateway/gateway_test.go
Moesif events use the billing customer ID as the company ID when present. Integration steps decode and assert company IDs and wait for analytics events with a matching status.
Subscription and analytics integration coverage
tests/framework/suites/it/features/gateway/observability/subscription_analytics.feature, tests/framework/suites/it/features/gateway/observability/subscription_analytics_billing_customer.feature, tests/framework/suites/it/features/management-portal/monetization/paid_subscription_suspension.feature, tests/framework/suites/it/it-suite.yaml
Scenarios check billing identifiers in analytics and subscription responses, and check access across billing and subscription status changes. The suite registers the scenarios with gateway-version conditions.

Retryable HTTP client timeouts

Layer / File(s) Summary
Configured upstream client construction
platform-api/internal/utils/guarded_http_client.go, platform-api/internal/server/shared_http_client.go, platform-api/internal/client/http_retry_client.go, platform-api/internal/client/http_retry_client_test.go
The shared client can retain its configuration. Retryable client construction uses a timeout-specific upstream client and returns errors when the transport cannot be configured. Tests cover timeout behavior and unsupported transports.

Subscription billing query batches

Layer / File(s) Summary
Batched billing lookup
platform-api/internal/repository/monetization.go, platform-api/internal/repository/monetization_test.go
GetMany queries UUIDs in batches of 500 and accumulates results. Empty input returns an empty map. Tests cover multiple batches and organization scoping.

Blank REST API plan configuration

Layer / File(s) Summary
Empty plan configuration handling
platform-api/internal/repository/subscription_plan_repository.go, platform-api/internal/repository/subscription_plan_test.go
The parser returns no plan handles for nil, empty, or whitespace-only configuration. Malformed JSON continues to produce an error.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SubscriptionUpdatedEventPayload
  participant handleSubscriptionUpdatedEvent
  participant Subscription
  participant Moesif.Publish
  SubscriptionUpdatedEventPayload->>handleSubscriptionUpdatedEvent: Provide billing identifiers
  handleSubscriptionUpdatedEvent->>Subscription: Store non-empty billing identifiers
  Subscription->>Moesif.Publish: Provide subscription billing data
  Moesif.Publish->>Moesif.Publish: Set company ID from billing customer ID
Loading
Merge Risk: Minimal · up to fa091

No material merge risk remains established from the inspected changes.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title "[Feature] API Monetization: Gateways Support" names the main change: gateway-side support for API monetization. The changeset adds billing customer and billing subscription IDs to gateway s…
Description check Passed The description follows the repository template. It includes Purpose, Goals, Approach, User stories, Documentation, Automation tests, Security checks, Samples, Related PRs, and Test environment. Purpo…
Docstring Coverage Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviv…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "[Feature] API Monetization: Gateways Support" names the main change: gateway-side support for API monetization. The changeset adds billing customer and billing subscription IDs to gateway subscriptions, and maps Moesif analytics company IDs to billing customers. The title is broad, and it does not name the specific billing-ID or analytics behavior. It is still related to the primary change, so it passes.

Full details: Description check

Explanation

The description follows the repository template. It includes Purpose, Goals, Approach, User stories, Documentation, Automation tests, Security checks, Samples, Related PRs, and Test environment. Purpose explains why the gateway needs billing identifiers and Moesif attribution. Goals and Approach state what the gateway controller and policy engine change. Unit and integration test coverage is listed. Security checks are answered. The description has some gaps. It does not link a related issue in the required 'Resolves' format. It does not name the JDK or other environment items, which do not apply to this Go change. The Related PRs section names stacked PRs, which is useful. Overall the description is mostly complete, so it passes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 18 functions across 15 files. (1 skipped: 1 unsupported.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@codecov-commenter

codecov-commenter commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.07937% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.38%. Comparing base (79759fa) to head (fa0911f).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
platform-api/internal/utils/guarded_http_client.go 51.61% 13 Missing and 2 partials ⚠️
platform-api/internal/repository/monetization.go 53.84% 4 Missing and 2 partials ⚠️
platform-api/internal/server/shared_http_client.go 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3937      +/-   ##
==========================================
- Coverage   60.93%   57.38%   -3.56%     
==========================================
  Files        1199     1197       -2     
  Lines      183063   182931     -132     
  Branches     6191     6192       +1     
==========================================
- Hits       111556   104976    -6580     
- Misses      62830    69843    +7013     
+ Partials     8677     8112     -565     
Flag Coverage Δ
ai-workspace-bff-integration 9.82% <ø> (ø)
ai-workspace-bff-unit 82.44% <ø> (ø)
ai-workspace-ui-integration 25.51% <ø> (-0.05%) ⬇️
ai-workspace-ui-unit 84.25% <ø> (+0.03%) ⬆️
api-portal-server-integration 58.05% <ø> (ø)
api-portal-ui-integration 29.24% <ø> (+0.15%) ⬆️
api-portal-unit 60.41% <ø> (-0.87%) ⬇️
gateway-controller-integration 27.11% <0.00%> (-26.90%) ⬇️
gateway-controller-unit 56.06% <100.00%> (+0.04%) ⬆️
platform-api-integration 25.89% <34.61%> (-22.64%) ⬇️
platform-api-unit 44.43% <32.69%> (-0.03%) ⬇️
policy-engine-integration 23.77% <0.00%> (-18.37%) ⬇️
policy-engine-unit 63.67% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…tches, and accept an empty REST API configuration

- The API Portal retry clients are built from the shared client's httpkit config with the attempt
  timeout, so it reaches the response-header wait even when httpkit wraps the transport; a
  transport that can't take it is refused instead of skipped.
- Subscription billing is read in batches of 500, below every database's parameter limit.
- A REST API with an empty configuration lists no subscription plans.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nisan-abeywickrama

Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nisan-abeywickrama
nisan-abeywickrama merged commit a3dc656 into wso2:main Oct 27, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants