Skip to content

Commit

Permalink
common: log endpoint in freshness checker
Browse files Browse the repository at this point in the history
style: run prettier
  • Loading branch information
saihaj committed Jan 11, 2024
1 parent 1b78523 commit bb086fe
Show file tree
Hide file tree
Showing 4 changed files with 16 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
5 changes: 5 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,7 @@ export class NetworkSubgraph {
logger: Logger
freshnessChecker: SubgraphFreshnessChecker | undefined
endpointClient?: AxiosInstance
endpoint: string

public readonly deployment?: {
id: SubgraphDeploymentID
Expand All @@ -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({
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 bb086fe

Please sign in to comment.