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

Auto and Manual deployment management modes #769

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
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 {
tilacog marked this conversation as resolved.
Show resolved Hide resolved
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}`)
}
}
Loading