Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Gateway Stats Batch API in the Console #6689

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 32 additions & 33 deletions pkg/webui/console/store/middleware/logics/gateways.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,39 +118,38 @@ const getGatewaysLogic = createRequestLogic({
if (options.withStatus) {
const gsConfig = selectGsConfig()
const consoleGsAddress = getHostFromUrl(gsConfig.base_url)

entities = await Promise.all(
data.gateways.map(gateway => {
const gatewayServerAddress = getHostFromUrl(gateway.gateway_server_address)

if (!Boolean(gatewayServerAddress)) {
return Promise.resolve({ ...gateway, status: 'unknown' })
}

if (gatewayServerAddress !== consoleGsAddress) {
return Promise.resolve({ ...gateway, status: 'other-cluster' })
}

const id = getGatewayId(gateway)
return tts.Gateways.getStatisticsById(id)
.then(stats => {
let status = 'unknown'
if (Boolean(stats) && Boolean(stats.connected_at)) {
status = 'connected'
} else if (Boolean(stats) && Boolean(stats.disconnected_at)) {
status = 'disconnected'
}
return { ...gateway, status }
})
.catch(err => {
if (err && err.code === 5) {
return { ...gateway, status: 'disconnected' }
}

return { ...gateway, status: 'unknown' }
})
}),
)
const gatewayIds = entities.map(e => e.ids)
const gatewaysStats = await tts.Gateways.getBatchStatistics(gatewayIds)

entities = data.gateways.map(gateway => {
const gatewayServerAddress = getHostFromUrl(gateway.gateway_server_address)

if (!Boolean(gatewayServerAddress)) {
return { ...gateway, status: 'unknown' }
}

if (gatewayServerAddress !== consoleGsAddress) {
return { ...gateway, status: 'other-cluster' }
}

if (!gatewaysStats?.entries) {
return { ...gateway, status: 'disconnected' }
}

const id = getGatewayId(gateway)
let status = 'unknown'

if (Boolean(gatewaysStats.entries[id]) && Boolean(gatewaysStats.entries[id].connected_at)) {
status = 'connected'
} else if (
!Boolean(gatewaysStats.entries[id]) ||
Boolean(gatewaysStats.entries[id].disconnected_at)
) {
status = 'disconnected'
}

return { ...gateway, status }
})
}

return {
Expand Down
8 changes: 8 additions & 0 deletions sdk/js/src/service/gateways.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ class Gateways {
return Marshaler.payloadSingleResponse(response)
}

async getBatchStatistics(gatewayIds) {
const response = await this._api.Gs.BatchGetGatewayConnectionStats(undefined, {
gateway_ids: gatewayIds
})

return Marshaler.payloadSingleResponse(response)
}

async getRightsById(gatewayId) {
const result = await this._api.GatewayAccess.ListRights({
routeParams: { gateway_id: gatewayId },
Expand Down
Loading