mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-07-28 02:52:08 +00:00
Implement health query for uniswap-info. (#228)
Co-authored-by: nabarun <nabarun@deepstacksoft.com>
This commit is contained in:
parent
afd7c954a2
commit
5941a929d2
@ -0,0 +1,66 @@
|
|||||||
|
scalar BigInt
|
||||||
|
|
||||||
|
type Block {
|
||||||
|
hash: Bytes!
|
||||||
|
number: BigInt!
|
||||||
|
}
|
||||||
|
|
||||||
|
scalar Bytes
|
||||||
|
|
||||||
|
interface ChainIndexingStatus {
|
||||||
|
network: String!
|
||||||
|
chainHeadBlock: Block
|
||||||
|
earliestBlock: Block
|
||||||
|
latestBlock: Block
|
||||||
|
lastHealthyBlock: Block
|
||||||
|
}
|
||||||
|
|
||||||
|
type EthereumIndexingStatus implements ChainIndexingStatus {
|
||||||
|
network: String!
|
||||||
|
chainHeadBlock: Block
|
||||||
|
earliestBlock: Block
|
||||||
|
latestBlock: Block
|
||||||
|
lastHealthyBlock: Block
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Health {
|
||||||
|
"""Subgraph syncing normally"""
|
||||||
|
healthy
|
||||||
|
|
||||||
|
"""Subgraph syncing but with errors"""
|
||||||
|
unhealthy
|
||||||
|
|
||||||
|
"""Subgraph halted due to errors"""
|
||||||
|
failed
|
||||||
|
}
|
||||||
|
|
||||||
|
type Query {
|
||||||
|
indexingStatusForCurrentVersion(subgraphName: String!): SubgraphIndexingStatus
|
||||||
|
indexingStatusForPendingVersion(subgraphName: String!): SubgraphIndexingStatus
|
||||||
|
indexingStatusesForSubgraphName(subgraphName: String!): [SubgraphIndexingStatus!]!
|
||||||
|
indexingStatuses(subgraphs: [String!]): [SubgraphIndexingStatus!]!
|
||||||
|
proofOfIndexing(subgraph: String!, blockNumber: Int!, blockHash: Bytes!, indexer: Bytes): Bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubgraphError {
|
||||||
|
message: String!
|
||||||
|
block: Block
|
||||||
|
handler: String
|
||||||
|
deterministic: Boolean!
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubgraphIndexingStatus {
|
||||||
|
subgraph: String!
|
||||||
|
synced: Boolean!
|
||||||
|
health: Health!
|
||||||
|
|
||||||
|
"""If the subgraph has failed, this is the error caused it"""
|
||||||
|
fatalError: SubgraphError
|
||||||
|
|
||||||
|
"""Sorted from first to last, limited to first 1000"""
|
||||||
|
nonFatalErrors: [SubgraphError!]!
|
||||||
|
chains: [ChainIndexingStatus!]!
|
||||||
|
entityCount: BigInt!
|
||||||
|
node: String
|
||||||
|
}
|
||||||
|
|
@ -22,6 +22,7 @@
|
|||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"generate:schema": "get-graphql-schema https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-alt > docs/analysis/schema/full-schema.graphql",
|
"generate:schema": "get-graphql-schema https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-alt > docs/analysis/schema/full-schema.graphql",
|
||||||
|
"generate:health-schema": "get-graphql-schema https://api.thegraph.com/index-node/graphql > docs/analysis/schema/health-schema.graphql",
|
||||||
"lint:schema": "graphql-schema-linter",
|
"lint:schema": "graphql-schema-linter",
|
||||||
"smoke-test": "mocha src/smoke.test.ts",
|
"smoke-test": "mocha src/smoke.test.ts",
|
||||||
"test:gpev": "mocha src/get-prev-entity.test.ts",
|
"test:gpev": "mocha src/get-prev-entity.test.ts",
|
||||||
|
@ -33,6 +33,8 @@ import { PositionSnapshot } from './entity/PositionSnapshot';
|
|||||||
import { SyncStatus } from './entity/SyncStatus';
|
import { SyncStatus } from './entity/SyncStatus';
|
||||||
import { BlockProgress } from './entity/BlockProgress';
|
import { BlockProgress } from './entity/BlockProgress';
|
||||||
|
|
||||||
|
const SYNC_DELTA = 5;
|
||||||
|
|
||||||
const log = debug('vulcanize:indexer');
|
const log = debug('vulcanize:indexer');
|
||||||
|
|
||||||
export interface ValueResult {
|
export interface ValueResult {
|
||||||
@ -175,6 +177,29 @@ export class Indexer implements IndexerInterface {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getIndexingStatus (): Promise<any> {
|
||||||
|
const syncStatus = await this.getSyncStatus();
|
||||||
|
assert(syncStatus);
|
||||||
|
const synced = (syncStatus.chainHeadBlockNumber - syncStatus.latestIndexedBlockNumber) <= SYNC_DELTA;
|
||||||
|
|
||||||
|
return {
|
||||||
|
synced,
|
||||||
|
health: 'healthy',
|
||||||
|
chains: [
|
||||||
|
{
|
||||||
|
chainHeadBlock: {
|
||||||
|
number: syncStatus.chainHeadBlockNumber,
|
||||||
|
hash: syncStatus.chainHeadBlockHash
|
||||||
|
},
|
||||||
|
latestBlock: {
|
||||||
|
number: syncStatus.latestIndexedBlockNumber,
|
||||||
|
hash: syncStatus.latestIndexedBlockHash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async markBlocksAsPruned (blocks: BlockProgress[]): Promise<void> {
|
async markBlocksAsPruned (blocks: BlockProgress[]): Promise<void> {
|
||||||
return this._baseIndexer.markBlocksAsPruned(blocks);
|
return this._baseIndexer.markBlocksAsPruned(blocks);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,12 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
return {
|
return {
|
||||||
BigInt: new BigInt('bigInt'),
|
BigInt: new BigInt('bigInt'),
|
||||||
|
|
||||||
|
ChainIndexingStatus: {
|
||||||
|
__resolveType: () => {
|
||||||
|
return 'EthereumIndexingStatus';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
Subscription: {
|
Subscription: {
|
||||||
onBlockProgressEvent: {
|
onBlockProgressEvent: {
|
||||||
subscribe: () => eventWatcher.getBlockProgressEventIterator()
|
subscribe: () => eventWatcher.getBlockProgressEventIterator()
|
||||||
@ -148,6 +154,12 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
log('blocks', first, orderBy, orderDirection, where);
|
log('blocks', first, orderBy, orderDirection, where);
|
||||||
|
|
||||||
return indexer.getBlocks(where, { limit: first, orderBy, orderDirection });
|
return indexer.getBlocks(where, { limit: first, orderBy, orderDirection });
|
||||||
|
},
|
||||||
|
|
||||||
|
indexingStatusForCurrentVersion: async (_: any, { subgraphName }: { subgraphName: string }) => {
|
||||||
|
log('health', subgraphName);
|
||||||
|
|
||||||
|
return indexer.getIndexingStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -291,6 +291,33 @@ enum Block_orderBy {
|
|||||||
timestamp
|
timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ChainIndexingStatus {
|
||||||
|
chainHeadBlock: Block
|
||||||
|
latestBlock: Block
|
||||||
|
}
|
||||||
|
|
||||||
|
type EthereumIndexingStatus implements ChainIndexingStatus {
|
||||||
|
chainHeadBlock: Block
|
||||||
|
latestBlock: Block
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Health {
|
||||||
|
"""Syncing normally"""
|
||||||
|
healthy
|
||||||
|
|
||||||
|
"""Syncing but with errors"""
|
||||||
|
unhealthy
|
||||||
|
|
||||||
|
"""Halted due to errors"""
|
||||||
|
failed
|
||||||
|
}
|
||||||
|
|
||||||
|
type SubgraphIndexingStatus {
|
||||||
|
synced: Boolean!
|
||||||
|
health: Health!
|
||||||
|
chains: [ChainIndexingStatus!]!
|
||||||
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
bundle(
|
bundle(
|
||||||
id: ID!
|
id: ID!
|
||||||
@ -443,6 +470,10 @@ type Query {
|
|||||||
orderDirection: OrderDirection
|
orderDirection: OrderDirection
|
||||||
where: Block_filter
|
where: Block_filter
|
||||||
): [Block!]!
|
): [Block!]!
|
||||||
|
|
||||||
|
indexingStatusForCurrentVersion(
|
||||||
|
subgraphName: String
|
||||||
|
): SubgraphIndexingStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user