Skip to content

implement multi platform api support#2185

Merged
tharindu1st merged 2 commits into
wso2:mainfrom
tharindu1st:platform-api-high-availability
Jun 17, 2026
Merged

implement multi platform api support#2185
tharindu1st merged 2 commits into
wso2:mainfrom
tharindu1st:platform-api-high-availability

Conversation

@tharindu1st

Copy link
Copy Markdown
Contributor

implement multi platform api support

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

Dependency name: github.com/knadh/koanf/v2
Version: v2.3.0 (was v2.3.2)
Approved: ❌ No - Version constraint not met - approved versions: [>=v2.3.2]

Dependency name: github.com/knadh/koanf/v2
Version: v2.3.0 (was v2.3.2)
Approved: ❌ No - Version constraint not met - approved versions: [>=v2.3.2]

Dependency name: github.com/knadh/koanf/v2
Version: v2.3.0 (was v2.3.2)
Approved: ❌ No - Version constraint not met - approved versions: [>=v2.3.2]

Dependency name: github.com/wso2/api-platform/sdk/core
Version: v0.2.12 (was v0.2.14)
Approved: ❌ No - Module not found in dependency registry

Dependency name: github.com/knadh/koanf/v2
Version: v2.3.0 (was v2.3.2)
Approved: ❌ No - Version constraint not met - approved versions: [>=v2.3.2]

Dependency name: github.com/kelseyhightower/envconfig
Version: v1.4.0
Allowed range: >=v1.4.0
Approved: ✅ Yes


Next Steps

  1. Review the validation failures listed above
  2. Check if dependencies are in the approved dependency list
  3. Options to resolve:
    • Remove the unapproved dependencies from this PR
    • OR submit a PR to add these dependencies to the approved list in engineering-governance
  4. Once resolved, push changes to re-run validation

This PR is blocked until all dependencies are approved.

⚠️ Please verify the scope of the dependencies usage is necessary

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@tharindu1st, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 6 minutes and 18 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00c7dd35-082a-4e2c-9fee-85f8ae9cc2fc

📥 Commits

Reviewing files that changed from the base of the PR and between a4efa7e and 002595e.

📒 Files selected for processing (5)
  • common/eventhub/eventhub_test.go
  • common/eventhub/sqlbackend.go
  • common/eventhub/topic.go
  • platform-api/src/internal/service/event_dispatcher.go
  • platform-api/src/internal/websocket/manager.go
📝 Walkthrough

Walkthrough

The PR integrates an EventHub subsystem for multi-replica HA event delivery. An EventHub configuration struct with three time.Duration fields is added to the Server config along with validation and default values. All three SQL schema dialects (SQLite, PostgreSQL, generic) gain gateway_states and events tables with appropriate foreign key and index definitions. GatewayEventsService is refactored to publish eventhub.Event objects instead of directly writing to WebSocket connections. A new EventDispatcher service maintains per-gateway EventHub subscriptions with reference counting and forwards events to WebSocket connections. The ws.Manager gains optional onConnect/onDisconnect lifecycle hooks. The server startup wires all components together and the shutdown sequence is consolidated to close EventHub, dispatcher, and HTTP server in order.

Sequence Diagram

sequenceDiagram
  participant wsManager
  participant EventDispatcher
  participant EventHub
  participant GatewayEventsService
  participant WebSocketConn

  Note over wsManager,EventDispatcher: Gateway connects
  wsManager->>EventDispatcher: onConnect(gatewayID)
  EventDispatcher->>EventHub: Register + Subscribe(gatewayID)
  EventHub-->>EventDispatcher: subscription channel

  Note over GatewayEventsService,EventHub: Event published
  GatewayEventsService->>EventHub: PublishEvent(eventhub.Event)
  EventHub->>EventDispatcher: event via subscription channel
  EventDispatcher->>wsManager: GetConnections(gatewayID)
  wsManager-->>EventDispatcher: []Connection
  EventDispatcher->>WebSocketConn: Send(EventData)

  Note over wsManager,EventDispatcher: Gateway disconnects
  wsManager->>EventDispatcher: onDisconnect(gatewayID)
  EventDispatcher->>EventHub: Unsubscribe(gatewayID)
Loading

Suggested reviewers

  • pubudu538
  • malinthaprasan
  • tgtshanika
  • Krishanx92
  • Arshardh
  • VirajSalaka
  • RakhithaRR
  • Tharsanan1
  • HiranyaKavishani
  • renuka-fernando
  • AnuGayan
  • CrowleyRajapakse
  • dushaniw
  • senthuran16
  • HeshanSudarshana
  • ashera96
  • hisanhunais
  • PasanT9
  • chamilaadhi
  • tharikaGitHub
🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is identical to the title and lacks all required template sections including Purpose, Goals, Approach, User Stories, Documentation, Testing, Security, and related information. Complete the PR description template with details on why EventHub was introduced, what problems it solves, implementation approach, affected user stories, documentation links, test coverage, and security validations performed.
Docstring Coverage ⚠️ Warning Docstring coverage is 57.89% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'implement multi platform api support' is vague and does not clearly convey the specific changes introduced in this changeset. Revise the title to be more specific about the primary change, such as 'Add EventHub for multi-gateway HA synchronization' or 'Implement event-based gateway state management.'
✅ Passed checks (2 passed)
Check name Status Explanation
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@tharindu1st tharindu1st force-pushed the platform-api-high-availability branch from 9de7aa0 to 43b5ace Compare June 13, 2026 16:19
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

@tharindu1st tharindu1st force-pushed the platform-api-high-availability branch from 43b5ace to 7412a7c Compare June 13, 2026 16:21
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

@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: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@platform-api/src/config/config.go`:
- Around line 63-79: Add a new validation step that rejects zero or negative
durations for the EventHub config: implement validateEventHubConfig(e EventHub)
error that returns an error if any of e.PollInterval, e.CleanupInterval, or
e.RetentionPeriod is <= 0 (with clear field-specific messages), and wire it into
GetConfig() alongside validateDeploymentsConfig so GetConfig() fails fast on
invalid EVENT_HUB_* values before server.go calls eventhub.New(...). Ensure the
error is propagated the same way other validation errors are (same error
type/format) so callers receive a consistent failure.

In `@platform-api/src/internal/server/server.go`:
- Around line 537-544: Start() currently only performs full cleanup in the
signal branch and never shuts down s.wsManager, so move the teardown logic into
a single helper (e.g., s.teardown or deferable function) and call it on every
exit path: when ListenAndServeTLS returns an error, in the signal-case branch,
and on normal shutdown. The helper should call httpServer.Shutdown(shutdownCtx)
(log errors), s.wsManager.Shutdown(), s.dispatcher.Shutdown(), and
s.eventHub.Close() (log errors) in a safe order and ensure it’s invoked exactly
once from Start()’s return paths.

In `@platform-api/src/internal/service/gateway_events.go`:
- Around line 298-307: The actionForEventType function currently maps ".created"
and ".deployed" to "CREATE" and ".deleted" to "DELETE", but misses ".undeployed"
so those events fall through to "UPDATE"; update actionForEventType to treat
event types ending with ".undeployed" as "DELETE" (e.g., add a case using
strings.HasSuffix(eventType, ".undeployed") that returns "DELETE" or include
".undeployed" alongside ".deleted") so the normalized action field correctly
reflects delete/undeploy operations.

In `@platform-api/src/internal/websocket/manager.go`:
- Around line 151-157: The connection hook invocations (m.onConnect /
m.onDisconnect) must not be dispatched in detached goroutines because that
allows out-of-order execution; change all call sites that do "go
m.onConnect(...)" or "go m.onDisconnect(...)" to call the hooks synchronously
immediately after the Manager updates its map/state (i.e., invoke
m.onConnect(gatewayID) and m.onDisconnect(gatewayID) inline, still keeping the
comment that callbacks must not depend on manager locks), or alternatively
implement per-gateway serialization (a small per-gateway mutex/serial queue) and
call the hooks through that serializer instead of with "go". Ensure the
inline/serialized call happens after the state change that made the
connect/disconnect effective so dispatcher sees consistent ordering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 05aea41e-a877-4e3a-bff5-dc9fb7633485

📥 Commits

Reviewing files that changed from the base of the PR and between 5e92c07 and 9de7aa0.

⛔ Files ignored due to path filters (1)
  • platform-api/src/go.sum is excluded by !**/*.sum
📒 Files selected for processing (13)
  • kubernetes/helm/event-gateway-helm-chart/templates/event-gateway/controller/deployment.yaml
  • kubernetes/helm/event-gateway-helm-chart/values.yaml
  • kubernetes/helm/gateway-helm-chart/templates/gateway/controller/deployment.yaml
  • kubernetes/helm/gateway-helm-chart/values.yaml
  • platform-api/src/config/config.go
  • platform-api/src/go.mod
  • platform-api/src/internal/database/schema.postgres.sql
  • platform-api/src/internal/database/schema.sql
  • platform-api/src/internal/database/schema.sqlite.sql
  • platform-api/src/internal/server/server.go
  • platform-api/src/internal/service/event_dispatcher.go
  • platform-api/src/internal/service/gateway_events.go
  • platform-api/src/internal/websocket/manager.go

Comment thread platform-api/src/config/config.go Outdated
Comment thread platform-api/src/internal/server/server.go
Comment thread platform-api/src/internal/service/gateway_events.go
@tharindu1st tharindu1st force-pushed the platform-api-high-availability branch from 7412a7c to 3b4e81c Compare June 13, 2026 17:58
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

@tharindu1st tharindu1st force-pushed the platform-api-high-availability branch from 3b4e81c to a18f150 Compare June 13, 2026 17:59
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

@tharindu1st tharindu1st force-pushed the platform-api-high-availability branch from a18f150 to 4708466 Compare June 13, 2026 17:59
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

@tharindu1st

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 14, 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.

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@platform-api/src/internal/websocket/manager.go`:
- Around line 87-89: The comment describing the connection lifecycle hooks
(onConnect and onDisconnect) incorrectly states they are "called asynchronously"
when the actual implementation invokes them synchronously. Update the comment
block to replace "asynchronously" with "synchronously" to accurately reflect the
actual behavior of these hooks.
- Around line 151-157: The SetConnectionHooks method writes to the m.onConnect
and m.onDisconnect fields without synchronization while Register and Unregister
read these fields concurrently, creating a potential data race. Document this
constraint since current usage is safe (SetConnectionHooks is called only once
during initialization before Server.Start). Add a note to the SetConnectionHooks
function comment explaining that it must be called only during initialization
before the gateway accepts connections. Additionally, add documentation comments
to the m.onConnect and m.onDisconnect struct fields indicating that
SetConnectionHooks must be called only during initialization to avoid concurrent
access issues.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6eefc776-3a68-480e-9bbf-4b4862948584

📥 Commits

Reviewing files that changed from the base of the PR and between 9de7aa0 and 4708466.

⛔ Files ignored due to path filters (1)
  • platform-api/src/go.sum is excluded by !**/*.sum
📒 Files selected for processing (10)
  • platform-api/src/config/config.go
  • platform-api/src/config/default_config.go
  • platform-api/src/go.mod
  • platform-api/src/internal/database/schema.postgres.sql
  • platform-api/src/internal/database/schema.sql
  • platform-api/src/internal/database/schema.sqlite.sql
  • platform-api/src/internal/server/server.go
  • platform-api/src/internal/service/event_dispatcher.go
  • platform-api/src/internal/service/gateway_events.go
  • platform-api/src/internal/websocket/manager.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • platform-api/src/go.mod
  • platform-api/src/internal/database/schema.postgres.sql
  • platform-api/src/internal/service/event_dispatcher.go
  • platform-api/src/internal/service/gateway_events.go
  • platform-api/src/internal/database/schema.sql
  • platform-api/src/internal/server/server.go

Comment thread platform-api/src/internal/websocket/manager.go Outdated
Comment thread platform-api/src/internal/websocket/manager.go
@tharindu1st tharindu1st force-pushed the platform-api-high-availability branch from 4708466 to 3b9e67e Compare June 15, 2026 05:24
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

Comment thread platform-api/src/internal/service/event_dispatcher.go Outdated
Comment thread platform-api/src/internal/service/event_dispatcher.go
Comment thread platform-api/src/internal/service/event_dispatcher.go
Comment thread platform-api/src/internal/service/gateway_events.go
@tharindu1st tharindu1st force-pushed the platform-api-high-availability branch from 67c26af to 6db1e9f Compare June 16, 2026 12:25
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

@tharindu1st tharindu1st requested a review from VirajSalaka June 16, 2026 13:16
VirajSalaka
VirajSalaka previously approved these changes Jun 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
platform-api/src/internal/service/gateway_events.go (1)

244-296: ⚠️ Potential issue | 🟠 Major

Extract entity identifiers from payload to set EntityID instead of using gatewayID.

The broadcastEventWithUserID function sets EntityID to gatewayID for all event types. However, each event model (DeploymentEvent, LLMProviderDeploymentEvent, etc.) contains the specific entity identifier (ApiId, ProviderId, ProxyId). This is inconsistent with the rest of the codebase, where EntityID represents the affected resource, not the container.

To align with codebase patterns and improve event semantics for downstream consumers, extract the entity identifier from the payload based on event type and set EntityID accordingly:

  • For API-related events: use ApiId from the payload
  • For LLM provider/proxy events: use ProviderId/ProxyId from the payload
  • Similar mapping for other event types
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@platform-api/src/internal/service/gateway_events.go` around lines 244 - 296,
In the broadcastEventWithUserID function, the EntityID field in the
eventhub.Event struct is currently hardcoded to gatewayID for all event types.
Instead, extract the actual entity identifier from the payload parameter based
on the eventType and use that for EntityID. Create a helper function or add
logic that uses type assertion to extract the appropriate field (such as ApiId,
ProviderId, or ProxyId) from the payload object based on the eventType, then set
EntityID to this extracted value instead of gatewayID.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@platform-api/src/internal/service/gateway_events.go`:
- Around line 244-296: In the broadcastEventWithUserID function, the EntityID
field in the eventhub.Event struct is currently hardcoded to gatewayID for all
event types. Instead, extract the actual entity identifier from the payload
parameter based on the eventType and use that for EntityID. Create a helper
function or add logic that uses type assertion to extract the appropriate field
(such as ApiId, ProviderId, or ProxyId) from the payload object based on the
eventType, then set EntityID to this extracted value instead of gatewayID.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dee31f90-1772-4b29-925f-03d452a3a5ef

📥 Commits

Reviewing files that changed from the base of the PR and between 3b9e67e and a4efa7e.

⛔ Files ignored due to path filters (1)
  • platform-api/src/go.sum is excluded by !**/*.sum
📒 Files selected for processing (13)
  • common/eventhub/eventhub_test.go
  • common/eventhub/sqlbackend.go
  • common/eventhub/topic.go
  • platform-api/src/config/config.go
  • platform-api/src/config/default_config.go
  • platform-api/src/go.mod
  • platform-api/src/internal/database/schema.postgres.sql
  • platform-api/src/internal/database/schema.sql
  • platform-api/src/internal/database/schema.sqlite.sql
  • platform-api/src/internal/server/server.go
  • platform-api/src/internal/service/event_dispatcher.go
  • platform-api/src/internal/service/gateway_events.go
  • platform-api/src/internal/websocket/manager.go
✅ Files skipped from review due to trivial changes (1)
  • platform-api/src/go.mod
🚧 Files skipped from review as they are similar to previous changes (8)
  • platform-api/src/internal/database/schema.sqlite.sql
  • platform-api/src/config/default_config.go
  • platform-api/src/internal/database/schema.postgres.sql
  • platform-api/src/internal/websocket/manager.go
  • platform-api/src/internal/database/schema.sql
  • platform-api/src/config/config.go
  • platform-api/src/internal/service/event_dispatcher.go
  • platform-api/src/internal/server/server.go

@tharindu1st tharindu1st force-pushed the platform-api-high-availability branch from a4efa7e to 002595e Compare June 17, 2026 06:04
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

⚠️ Please verify the scope of the dependencies usage is necessary

@tharindu1st tharindu1st merged commit b141336 into wso2:main Jun 17, 2026
6 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.

2 participants