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

common: log endpoint in freshness checker #839

Merged
merged 1 commit into from
Aug 6, 2024
Merged
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
2 changes: 2 additions & 0 deletions packages/indexer-common/src/epoch-subgraph.ts
Original file line number Diff line number Diff line change
@@ -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' },
6 changes: 5 additions & 1 deletion packages/indexer-common/src/graph-node.ts
Original file line number Diff line number Diff line change
@@ -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)
}
13 changes: 13 additions & 0 deletions packages/indexer-common/src/network-subgraph.ts
Original file line number Diff line number Diff line change
@@ -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!
}
4 changes: 4 additions & 0 deletions packages/indexer-common/src/subgraphs.ts
Original file line number Diff line number Diff line change
@@ -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 */

@@ -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)