From bb086fe1aa41942bd0ee3dacb368a149609fb680 Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Mon, 8 Jan 2024 13:04:23 -0600 Subject: [PATCH] common: log endpoint in freshness checker style: run prettier --- packages/indexer-common/src/epoch-subgraph.ts | 2 ++ packages/indexer-common/src/graph-node.ts | 6 +++++- packages/indexer-common/src/network-subgraph.ts | 5 +++++ packages/indexer-common/src/subgraphs.ts | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/indexer-common/src/epoch-subgraph.ts b/packages/indexer-common/src/epoch-subgraph.ts index d2248c4eb..e6c9241b7 100644 --- a/packages/indexer-common/src/epoch-subgraph.ts +++ b/packages/indexer-common/src/epoch-subgraph.ts @@ -8,12 +8,14 @@ export class EpochSubgraph { endpointClient: AxiosInstance freshnessChecker: SubgraphFreshnessChecker logger: Logger + endpoint: string constructor( endpoint: string, freshnessChecker: SubgraphFreshnessChecker, logger: Logger, ) { + this.endpoint = endpoint this.endpointClient = axios.create({ baseURL: endpoint, headers: { 'content-type': 'application/json' }, diff --git a/packages/indexer-common/src/graph-node.ts b/packages/indexer-common/src/graph-node.ts index 5157ea4a2..bd85c797b 100644 --- a/packages/indexer-common/src/graph-node.ts +++ b/packages/indexer-common/src/graph-node.ts @@ -128,13 +128,17 @@ export class GraphNode { // AxiosClient factory scoped by subgraph IFPS hash getQueryClient(deploymentIpfsHash: string): AxiosInstance { return axios.create({ - baseURL: new URL(deploymentIpfsHash, this.queryBaseURL).toString(), + baseURL: this.getQueryEndpoint(deploymentIpfsHash), headers: { 'content-type': 'application/json' }, responseType: 'text', // Don't parse responses as JSON transformResponse: (data) => data, // Don't transform responses }) } + getQueryEndpoint(deploymentIpfsHash: string): string { + return new URL(deploymentIpfsHash, this.queryBaseURL).toString() + } + public async subgraphDeployments(): Promise { return (await this.subgraphDeploymentsAssignments()).map((details) => details.id) } diff --git a/packages/indexer-common/src/network-subgraph.ts b/packages/indexer-common/src/network-subgraph.ts index 8a41390a4..48ff082b2 100644 --- a/packages/indexer-common/src/network-subgraph.ts +++ b/packages/indexer-common/src/network-subgraph.ts @@ -44,6 +44,7 @@ export class NetworkSubgraph { logger: Logger freshnessChecker: SubgraphFreshnessChecker | undefined endpointClient?: AxiosInstance + endpoint: string public readonly deployment?: { id: SubgraphDeploymentID @@ -54,6 +55,10 @@ export class NetworkSubgraph { private constructor(options: NetworkSubgraphOptions) { this.logger = options.logger this.freshnessChecker = options.subgraphFreshnessChecker + this.endpoint = + options?.endpoint || + options.deployment?.graphNode.getQueryEndpoint(options.deployment.id.ipfsHash) || + '' if (options.endpoint) { this.endpointClient = axios.create({ diff --git a/packages/indexer-common/src/subgraphs.ts b/packages/indexer-common/src/subgraphs.ts index f06e03bd0..0b0a086b3 100644 --- a/packages/indexer-common/src/subgraphs.ts +++ b/packages/indexer-common/src/subgraphs.ts @@ -344,6 +344,7 @@ export interface SubgraphQueryInterface { query: DocumentNode, variables?: Record, ): Promise> + endpoint: string } /* eslint-enable @typescript-eslint/no-explicit-any */ @@ -427,6 +428,7 @@ export class SubgraphFreshnessChecker { this.logger.error(errorMsg, { subgraph: this.subgraphName, query: print(updatedQuery), + endpoint: subgraph.endpoint, }) throw new Error(errorMsg) } @@ -455,6 +457,7 @@ export class SubgraphFreshnessChecker { subgraph: this.subgraphName, error: queryShapeError, subgraphQueryResult, + endpoint: subgraph.endpoint, }) throw new Error(errorMsg) } @@ -471,6 +474,7 @@ export class SubgraphFreshnessChecker { freshnessThreshold: this.threshold, subgraph: this.subgraphName, retriesLeft, + endpoint: subgraph.endpoint, } this.logger.trace('Performing subgraph freshness check', logInfo)