Skip to content

Commit

Permalink
common, agent: add auto and manual deployment management modes
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Sep 6, 2023
1 parent 7a1aea4 commit a5c8413
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
48 changes: 33 additions & 15 deletions packages/indexer-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
TransferredSubgraphDeployment,
networkIsL2,
networkIsL1,
DeploymentManagementMode,
} from '@graphprotocol/indexer-common'

import PQueue from 'p-queue'
Expand Down Expand Up @@ -204,6 +205,7 @@ export class Agent {
indexerManagement: IndexerManagementClient
offchainSubgraphs: SubgraphDeploymentID[]
autoMigrationSupport: boolean
deploymentManagement: DeploymentManagementMode

constructor(
logger: Logger,
Expand All @@ -214,6 +216,7 @@ export class Agent {
networks: Network[],
offchainSubgraphs: SubgraphDeploymentID[],
autoMigrationSupport: boolean,
deploymentManagement: DeploymentManagementMode,
) {
this.logger = logger.child({ component: 'Agent' })
this.metrics = metrics
Expand All @@ -222,6 +225,7 @@ export class Agent {
this.multiNetworks = createMultiNetworks(networks, operators)
this.offchainSubgraphs = offchainSubgraphs
this.autoMigrationSupport = !!autoMigrationSupport
this.deploymentManagement = deploymentManagement
}

async start(): Promise<Agent> {
Expand Down Expand Up @@ -799,22 +803,36 @@ export class Agent {
...Object.values(activeAllocations).flat(),
]

try {
// Reconcile deployments
await this.reconcileDeployments(
activeDeployments,
targetDeployments,
eligibleAllocations,
)
} catch (err) {
logger.warn(
`Exited early while reconciling deployments. Skipped reconciling actions.`,
{
err: indexerError(IndexerErrorCode.IE005, err),
},
)
return
// Reconcile deployments
switch (this.deploymentManagement) {
case DeploymentManagementMode.AUTO:
try {
await this.reconcileDeployments(
activeDeployments,
targetDeployments,
eligibleAllocations,
)
} catch (err) {
logger.warn(
`Exited early while reconciling deployments. Skipped reconciling actions.`,
{
err: indexerError(IndexerErrorCode.IE005, err),
},
)
return
}
break
case DeploymentManagementMode.MANUAL:
this.logger.debug(
`Skipping subgraph deployment reconciliation since DeploymentManagementMode = 'manual'`,
)
break
default:
throw new Error(
`Unexpected parameter for DeploymentManagementMode: ${this.deploymentManagement}`,
)
}

try {
// Reconcile allocation actions
await this.reconcileActions(
Expand Down
9 changes: 9 additions & 0 deletions packages/indexer-agent/src/commands/common-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs'

import { Argv } from 'yargs'
import { parse as yaml_parse } from 'yaml'
import { parseDeploymentManagementMode } from '@graphprotocol/indexer-common'

// Injects all CLI options shared between this module's commands into a `yargs.Argv` object.
export function injectCommonStartupOptions(argv: Argv): Argv {
Expand Down Expand Up @@ -128,6 +129,14 @@ export function injectCommonStartupOptions(argv: Argv): Argv {
default: false,
group: 'Indexer Infrastructure',
})
.option('deployment-management', {
describe: 'Subgraph deployments management mode',
required: false,
default: 'auto',
choices: ['auto', 'manual'],
coerce: parseDeploymentManagementMode,
group: 'Indexer Infrastructure',
})
.config({
key: 'config-file',
description: 'Indexer agent configuration file (YAML format)',
Expand Down
1 change: 1 addition & 0 deletions packages/indexer-agent/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ export async function run(
networks,
argv.offchainSubgraphs.map((s: string) => new SubgraphDeploymentID(s)),
argv.enableAutoMigrationSupport,
argv.deploymentManagement,
)
await agent.start()
}
Expand Down
16 changes: 16 additions & 0 deletions packages/indexer-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export enum AllocationManagementMode {
OVERSIGHT = 'oversight',
}

export enum DeploymentManagementMode {
AUTO = 'auto',
MANUAL = 'manual',
}

export enum OrderDirection {
ASC = 'asc',
DESC = 'desc',
Expand Down Expand Up @@ -90,3 +95,14 @@ export interface TransactionConfig extends providers.TransactionRequest {
gasBump: BigNumber
type: TransactionType
}

export function parseDeploymentManagementMode(input: string): DeploymentManagementMode {
switch (input) {
case DeploymentManagementMode.AUTO:
return DeploymentManagementMode.AUTO
case DeploymentManagementMode.MANUAL:
return DeploymentManagementMode.MANUAL
default:
throw new Error(`Invalid value for deployment management mode: ${input}`)
}
}

0 comments on commit a5c8413

Please sign in to comment.