Skip to content

Commit

Permalink
common: log endpoint in freshness checker
Browse files Browse the repository at this point in the history
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
  • Loading branch information
saihaj committed Jan 31, 2024
1 parent 0f48b17 commit 8c2b08f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/indexer-common/src/epoch-subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
6 changes: 5 additions & 1 deletion packages/indexer-common/src/graph-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubgraphDeploymentID[]> {
return (await this.subgraphDeploymentsAssignments()).map((details) => details.id)
}
Expand Down
13 changes: 13 additions & 0 deletions packages/indexer-common/src/network-subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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({
Expand All @@ -66,6 +74,7 @@ export class NetworkSubgraph {
// Don't transform responses
transformResponse: (data) => data,
})
this.endpoint = this.networkSubgraphConfigEndpoint
}

if (options.deployment) {
Expand All @@ -80,6 +89,7 @@ export class NetworkSubgraph {
status,
endpointClient: graphNodeEndpointClient,
}
this.endpoint = this.networkSubgraphDeploymentEndpoint
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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!
}
Expand Down
4 changes: 4 additions & 0 deletions packages/indexer-common/src/subgraphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export interface SubgraphQueryInterface {
query: DocumentNode,
variables?: Record<string, any>,
): Promise<QueryResult<Data>>
endpoint?: string
}
/* eslint-enable @typescript-eslint/no-explicit-any */

Expand Down Expand Up @@ -427,6 +428,7 @@ export class SubgraphFreshnessChecker {
this.logger.error(errorMsg, {
subgraph: this.subgraphName,
query: print(updatedQuery),
endpoint: subgraph.endpoint,
})
throw new Error(errorMsg)
}
Expand Down Expand Up @@ -455,6 +457,7 @@ export class SubgraphFreshnessChecker {
subgraph: this.subgraphName,
error: queryShapeError,
subgraphQueryResult,
endpoint: subgraph.endpoint,
})
throw new Error(errorMsg)
}
Expand All @@ -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)

Expand Down

0 comments on commit 8c2b08f

Please sign in to comment.