From 8c2b08f1c8bd06038d2328a70fabd90a8d79c955 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 Today indexers do not have a way to know what subgraph is "not fresh" this PR aims to introduce the endpoint of subgraph we consider is "not fresh" in the freshness checker --- packages/indexer-common/src/epoch-subgraph.ts | 2 ++ packages/indexer-common/src/graph-node.ts | 6 +++++- packages/indexer-common/src/network-subgraph.ts | 13 +++++++++++++ packages/indexer-common/src/subgraphs.ts | 4 ++++ 4 files changed, 24 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 62cc6fa7c..8b829ff79 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..ff8b4766d 100644 --- a/packages/indexer-common/src/network-subgraph.ts +++ b/packages/indexer-common/src/network-subgraph.ts @@ -44,6 +44,11 @@ export class NetworkSubgraph { logger: Logger freshnessChecker: SubgraphFreshnessChecker | undefined endpointClient?: AxiosInstance + /** Endpoint URL for the Network Subgraph Endpoint from the config */ + private networkSubgraphConfigEndpoint?: string + /** Endpoint URL for the Network Subgraph Endpoint from the deployment */ + private networkSubgraphDeploymentEndpoint?: string + endpoint?: string public readonly deployment?: { id: SubgraphDeploymentID @@ -54,6 +59,9 @@ export class NetworkSubgraph { private constructor(options: NetworkSubgraphOptions) { this.logger = options.logger this.freshnessChecker = options.subgraphFreshnessChecker + this.networkSubgraphConfigEndpoint = options.endpoint + this.networkSubgraphDeploymentEndpoint = + options.deployment?.graphNode.getQueryEndpoint(options.deployment.id.ipfsHash) if (options.endpoint) { this.endpointClient = axios.create({ @@ -66,6 +74,7 @@ export class NetworkSubgraph { // Don't transform responses transformResponse: (data) => data, }) + this.endpoint = this.networkSubgraphConfigEndpoint } if (options.deployment) { @@ -80,6 +89,7 @@ export class NetworkSubgraph { status, endpointClient: graphNodeEndpointClient, } + this.endpoint = this.networkSubgraphDeploymentEndpoint } } @@ -147,9 +157,11 @@ export class NetworkSubgraph { if (healthy) { this.logger.trace('Use own deployment for network subgraph query') + this.endpoint = this.networkSubgraphDeploymentEndpoint return this.deployment.endpointClient } else if (this.endpointClient) { this.logger.trace('Use provided endpoint for network subgraph query') + this.endpoint = this.networkSubgraphConfigEndpoint return this.endpointClient } else { // We have no endpoint and our deployment is not synced or unhealthy; @@ -161,6 +173,7 @@ export class NetworkSubgraph { } } else { this.logger.trace('Use provided endpoint for network subgraph query') + this.endpoint = this.networkSubgraphConfigEndpoint // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return this.endpointClient! } diff --git a/packages/indexer-common/src/subgraphs.ts b/packages/indexer-common/src/subgraphs.ts index 0854c670e..f4b668daf 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)