From a5c841321334988abd3adf3514dbc852944ebbd2 Mon Sep 17 00:00:00 2001 From: tilacog Date: Wed, 6 Sep 2023 15:03:41 -0300 Subject: [PATCH] common, agent: add auto and manual deployment management modes --- packages/indexer-agent/src/agent.ts | 48 +++++++++++++------ .../src/commands/common-options.ts | 9 ++++ packages/indexer-agent/src/commands/start.ts | 1 + packages/indexer-common/src/types.ts | 16 +++++++ 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/packages/indexer-agent/src/agent.ts b/packages/indexer-agent/src/agent.ts index eae81f1c9..69ba9a14d 100644 --- a/packages/indexer-agent/src/agent.ts +++ b/packages/indexer-agent/src/agent.ts @@ -35,6 +35,7 @@ import { TransferredSubgraphDeployment, networkIsL2, networkIsL1, + DeploymentManagementMode, } from '@graphprotocol/indexer-common' import PQueue from 'p-queue' @@ -204,6 +205,7 @@ export class Agent { indexerManagement: IndexerManagementClient offchainSubgraphs: SubgraphDeploymentID[] autoMigrationSupport: boolean + deploymentManagement: DeploymentManagementMode constructor( logger: Logger, @@ -214,6 +216,7 @@ export class Agent { networks: Network[], offchainSubgraphs: SubgraphDeploymentID[], autoMigrationSupport: boolean, + deploymentManagement: DeploymentManagementMode, ) { this.logger = logger.child({ component: 'Agent' }) this.metrics = metrics @@ -222,6 +225,7 @@ export class Agent { this.multiNetworks = createMultiNetworks(networks, operators) this.offchainSubgraphs = offchainSubgraphs this.autoMigrationSupport = !!autoMigrationSupport + this.deploymentManagement = deploymentManagement } async start(): Promise { @@ -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( diff --git a/packages/indexer-agent/src/commands/common-options.ts b/packages/indexer-agent/src/commands/common-options.ts index c867bbe79..9d40e82b7 100644 --- a/packages/indexer-agent/src/commands/common-options.ts +++ b/packages/indexer-agent/src/commands/common-options.ts @@ -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 { @@ -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)', diff --git a/packages/indexer-agent/src/commands/start.ts b/packages/indexer-agent/src/commands/start.ts index 4f8f7da08..7a6ebd868 100644 --- a/packages/indexer-agent/src/commands/start.ts +++ b/packages/indexer-agent/src/commands/start.ts @@ -581,6 +581,7 @@ export async function run( networks, argv.offchainSubgraphs.map((s: string) => new SubgraphDeploymentID(s)), argv.enableAutoMigrationSupport, + argv.deploymentManagement, ) await agent.start() } diff --git a/packages/indexer-common/src/types.ts b/packages/indexer-common/src/types.ts index 356396573..cfd62747a 100644 --- a/packages/indexer-common/src/types.ts +++ b/packages/indexer-common/src/types.ts @@ -7,6 +7,11 @@ export enum AllocationManagementMode { OVERSIGHT = 'oversight', } +export enum DeploymentManagementMode { + AUTO = 'auto', + MANUAL = 'manual', +} + export enum OrderDirection { ASC = 'asc', DESC = 'desc', @@ -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}`) + } +}