Add config for query limit in compare CLI (#175)

* Add config for query limit in compare CLI

* Fix JSON stringify bigint for GQL query params

* Take last N entity ids to compare in GQL
This commit is contained in:
nikugogoi 2022-09-08 16:54:02 +05:30 committed by GitHub
parent 93584bf28d
commit 4e5ec36f07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 31 deletions

View File

@ -8,7 +8,7 @@ import debug from 'debug';
import Decimal from 'decimal.js';
import { GraphQLScalarType } from 'graphql';
import { ValueResult, BlockHeight, StateKind, gqlTotalQueryCount, gqlQueryCount } from '@vulcanize/util';
import { ValueResult, BlockHeight, StateKind, gqlTotalQueryCount, gqlQueryCount, jsonBigIntStringReplacer } from '@vulcanize/util';
import { Indexer } from './indexer';
import { EventWatcher } from './events';
@ -79,7 +79,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
{{~#each subgraphQueries}}
{{this.queryName}}: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('{{this.queryName}}', id, block);
log('{{this.queryName}}', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('{{this.queryName}}').inc(1);

View File

@ -8,7 +8,7 @@ import debug from 'debug';
import Decimal from 'decimal.js';
import { GraphQLScalarType } from 'graphql';
import { BlockHeight, OrderDirection, StateKind, gqlTotalQueryCount, gqlQueryCount } from '@vulcanize/util';
import { BlockHeight, OrderDirection, StateKind, gqlTotalQueryCount, gqlQueryCount, jsonBigIntStringReplacer } from '@vulcanize/util';
import { Indexer } from './indexer';
import { EventWatcher } from './events';
@ -78,7 +78,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
Query: {
producer: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('producer', id, block);
log('producer', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('producer').inc(1);
@ -86,7 +86,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
producers: async (_: any, { block = {}, first, skip }: { block: BlockHeight, first: number, skip: number }) => {
log('producers', block, first, skip);
log('producers', JSON.stringify(block, jsonBigIntStringReplacer), first, skip);
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('producers').inc(1);
@ -99,7 +99,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
producerSet: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('producerSet', id, block);
log('producerSet', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('producerSet').inc(1);
@ -107,7 +107,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
producerSetChange: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('producerSetChange', id, block);
log('producerSetChange', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('producerSetChange').inc(1);
@ -115,7 +115,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
producerRewardCollectorChange: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('producerRewardCollectorChange', id, block);
log('producerRewardCollectorChange', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('producerRewardCollectorChange').inc(1);
@ -123,7 +123,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
rewardScheduleEntry: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('rewardScheduleEntry', id, block);
log('rewardScheduleEntry', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('rewardScheduleEntry').inc(1);
@ -131,7 +131,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
rewardSchedule: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('rewardSchedule', id, block);
log('rewardSchedule', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('rewardSchedule').inc(1);
@ -139,7 +139,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
producerEpoch: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('producerEpoch', id, block);
log('producerEpoch', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('producerEpoch').inc(1);
@ -147,7 +147,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
block: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('block', id, block);
log('block', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('block').inc(1);
@ -155,7 +155,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
blocks: async (_: any, { block = {}, where, first, skip, orderBy, orderDirection }: { block: BlockHeight, where: { [key: string]: any }, first: number, skip: number, orderBy: string, orderDirection: OrderDirection }) => {
log('blocks', block, where, first, skip, orderBy, orderDirection);
log('blocks', JSON.stringify(block, jsonBigIntStringReplacer), JSON.stringify(where, jsonBigIntStringReplacer), first, skip, orderBy, orderDirection);
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('blocks').inc(1);
@ -168,7 +168,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
epoch: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('epoch', id, block);
log('epoch', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('epoch').inc(1);
@ -176,7 +176,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
epoches: async (_: any, { block = {}, where, first, skip }: { block: BlockHeight, where: { [key: string]: any }, first: number, skip: number }) => {
log('epoches', block, where, first, skip);
log('epoches', JSON.stringify(block, jsonBigIntStringReplacer), JSON.stringify(where, jsonBigIntStringReplacer), first, skip);
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('epoches').inc(1);
@ -189,7 +189,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
slotClaim: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('slotClaim', id, block);
log('slotClaim', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('slotClaim').inc(1);
@ -197,7 +197,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
slot: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('slot', id, block);
log('slot', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('slot').inc(1);
@ -205,7 +205,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
staker: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('staker', id, block);
log('staker', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('staker').inc(1);
@ -213,7 +213,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
stakers: async (_: any, { block = {}, where, first, skip, orderBy, orderDirection }: { block: BlockHeight, where: { [key: string]: any }, first: number, skip: number, orderBy: string, orderDirection: OrderDirection }) => {
log('stakers', block, where, first, skip, orderBy, orderDirection);
log('stakers', JSON.stringify(block, jsonBigIntStringReplacer), JSON.stringify(where, jsonBigIntStringReplacer), first, skip, orderBy, orderDirection);
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('stakers').inc(1);
@ -226,7 +226,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
network: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('network', id, block);
log('network', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('network').inc(1);
@ -234,7 +234,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
distributor: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('distributor', id, block);
log('distributor', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('distributor').inc(1);
@ -242,7 +242,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
distribution: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('distribution', id, block);
log('distribution', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('distribution').inc(1);
@ -250,7 +250,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
claim: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('claim', id, block);
log('claim', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('claim').inc(1);
@ -258,7 +258,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
slash: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('slash', id, block);
log('slash', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('slash').inc(1);
@ -266,7 +266,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
account: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
log('account', id, block);
log('account', id, JSON.stringify(block, jsonBigIntStringReplacer));
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('account').inc(1);

View File

@ -3,13 +3,14 @@
gqlEndpoint2 = "http://localhost:3008/graphql"
[queries]
queryDir = "../graph-test-watcher/src/gql/queries"
queryDir = "../../graph-test-watcher/src/gql/queries"
names = []
blockDelayInMs = 250
queryLimits = {}
[watcher]
configPath = "../../graph-test-watcher/environments/local.toml"
entitiesDir = "../../graph-test-watcher/src/entity"
entitiesDir = "../../graph-test-watcher/dist/entity/*"
endpoint = "gqlEndpoint2"
verifyState = true
derivedFields = []

View File

@ -120,6 +120,14 @@ export const main = async (): Promise<void> => {
let resultDiff = '';
if (fetchIds) {
const queryLimit = config.queries.queryLimits[queryName];
if (queryLimit) {
// Take only last `queryLimit` entity ids to compare in GQL.
const idsLength = updatedEntityIds[index].length;
updatedEntityIds[index].splice(0, idsLength - queryLimit);
}
for (const id of updatedEntityIds[index]) {
const { diff, result1: result } = await compareQuery(
clients,

View File

@ -36,6 +36,7 @@ interface QueryConfig {
queryDir: string;
names: string[];
blockDelayInMs: number;
queryLimits: { [queryName: string]: number }
}
interface EntityDerivedFields {

View File

@ -8,7 +8,7 @@ import debug from 'debug';
import Decimal from 'decimal.js';
import { GraphQLScalarType } from 'graphql';
import { ValueResult, BlockHeight, StateKind } from '@vulcanize/util';
import { ValueResult, BlockHeight, StateKind, jsonBigIntStringReplacer } from '@vulcanize/util';
import { Indexer } from './indexer';
import { EventWatcher } from './events';
@ -73,19 +73,19 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
},
blog: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }): Promise<Blog | undefined> => {
log('blog', id, block);
log('blog', id, JSON.stringify(block, jsonBigIntStringReplacer));
return indexer.getSubgraphEntity(Blog, id, block);
},
category: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }): Promise<Category | undefined> => {
log('category', id, block);
log('category', id, JSON.stringify(block, jsonBigIntStringReplacer));
return indexer.getSubgraphEntity(Category, id, block);
},
author: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }): Promise<Author | undefined> => {
log('author', id, block);
log('author', id, JSON.stringify(block, jsonBigIntStringReplacer));
return indexer.getSubgraphEntity(Author, id, block);
},