Skip to content

Commit

Permalink
cli: fix missing endpoints from the status command
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Jun 22, 2023
1 parent 06d5bf9 commit 9a2648b
Showing 1 changed file with 46 additions and 28 deletions.
74 changes: 46 additions & 28 deletions packages/indexer-cli/src/commands/indexer/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
parseOutputFormat,
pickFields,
} from '../../command-helpers'
import { resolveChainAlias } from '@graphprotocol/indexer-common'

const HELP = `
${chalk.bold('graph indexer status')}
Expand All @@ -23,6 +24,18 @@ ${chalk.dim('Options:')}
-n, --network [Required] the rule's protocol network
`

interface Endpoint {
url: string | null
healthy: boolean
protocolNetwork: string
tests: any[]
}

interface Endpoints {
service: Endpoint
status: Endpoint
}

module.exports = {
name: 'status',
alias: [],
Expand All @@ -42,17 +55,6 @@ module.exports = {
return
}

let protocolNetwork: string
try {
// TODO:L2: Protocol Network should be optional in this case. To make it so, we
// also need to relax the requirement for the protocol network field on the
// GrapQL quieries and the respective resolvers for the indexer status.
protocolNetwork = requireProtocolNetworkOption(toolbox.parameters.options)
} catch (error) {
print.error(error.message)
process.exit(1)
}

const config = loadValidatedConfig()

// Create indexer API client
Expand All @@ -61,6 +63,10 @@ module.exports = {
// Query status information
let result: any | undefined
try {
// TODO:L2: Consider making Protocol Network optional, showing status for all
// networks, combined.
const protocolNetwork = requireProtocolNetworkOption(toolbox.parameters.options)

result = await client
.query(
gql`
Expand Down Expand Up @@ -124,6 +130,7 @@ module.exports = {
status {
url
healthy
protocolNetwork
tests {
test
error
Expand Down Expand Up @@ -188,24 +195,25 @@ module.exports = {
}

if (result.data.indexerEndpoints) {
const keys = Object.keys(pickFields(result.data.indexerEndpoints, []))
keys.sort()

const statusUp = outputFormat == 'table' ? chalk.green('up') : 'up'
const statusDown = outputFormat == 'table' ? chalk.red('down') : 'down'

data.endpoints = keys.reduce(
(out, key) => [
...out,
data.endpoints = result.data.indexerEndpoints.flatMap((endpoints: Endpoints) => {
const { service, status } = endpoints
return [
{
name: key,
url: result.data.indexerEndpoints[key].url,
status: result.data.indexerEndpoints[key].healthy ? statusUp : statusDown,
tests: result.data.indexerEndpoints[key].tests,
name: 'service',
url: service.url,
tests: service.tests,
protocolNetwork: resolveChainAlias(service.protocolNetwork),
status: formatStatus(outputFormat, service.healthy),
},
],
[] as any,
)
{
name: 'status',
url: status.url,
tests: status.tests,
protocolNetwork: resolveChainAlias(status.protocolNetwork),
status: formatStatus(outputFormat, status.healthy),
},
]
})
} else {
data.endpoints = {
error:
Expand Down Expand Up @@ -249,7 +257,7 @@ module.exports = {
print.info(
formatData(
data.endpoints.map((endpoint: any) =>
pickFields(endpoint, ['name', 'url', 'status']),
pickFields(endpoint, ['name', 'protocolNetwork', 'url', 'status']),
),
outputFormat,
),
Expand Down Expand Up @@ -323,3 +331,13 @@ module.exports = {
}
},
}

function formatStatus(outputFormat: string, status: boolean) {
return outputFormat === 'table'
? status
? chalk.green('up')
: chalk.red('down')
: status
? 'up'
: 'down'
}

0 comments on commit 9a2648b

Please sign in to comment.