Skip to content

Commit

Permalink
Log GQL requests in watcher (#517)
Browse files Browse the repository at this point in the history
* Update config for server GQL

* Add winston logger for GQL requests

* Fix codegen templates for resolver and package

* Update package versions

---------

Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
  • Loading branch information
nikugogoi and prathamesh0 authored Jun 6, 2024
1 parent 836fe45 commit 8d052ad
Show file tree
Hide file tree
Showing 26 changed files with 374 additions and 96 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.2.93",
"version": "0.2.94",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/cache",
"version": "0.2.93",
"version": "0.2.94",
"description": "Generic object cache",
"main": "dist/index.js",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/cli",
"version": "0.2.93",
"version": "0.2.94",
"main": "dist/index.js",
"license": "AGPL-3.0",
"scripts": {
Expand All @@ -15,13 +15,13 @@
},
"dependencies": {
"@apollo/client": "^3.7.1",
"@cerc-io/cache": "^0.2.93",
"@cerc-io/ipld-eth-client": "^0.2.93",
"@cerc-io/cache": "^0.2.94",
"@cerc-io/ipld-eth-client": "^0.2.94",
"@cerc-io/libp2p": "^0.42.2-laconic-0.1.4",
"@cerc-io/nitro-node": "^0.1.15",
"@cerc-io/peer": "^0.2.93",
"@cerc-io/rpc-eth-client": "^0.2.93",
"@cerc-io/util": "^0.2.93",
"@cerc-io/peer": "^0.2.94",
"@cerc-io/rpc-eth-client": "^0.2.94",
"@cerc-io/util": "^0.2.94",
"@ethersproject/providers": "^5.4.4",
"@graphql-tools/utils": "^9.1.1",
"@ipld/dag-cbor": "^8.0.0",
Expand Down
13 changes: 10 additions & 3 deletions packages/cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import assert from 'assert';
import { ConnectionOptions } from 'typeorm';
import express, { Application } from 'express';
import { ApolloServer } from 'apollo-server-express';
import winston from 'winston';

import { JsonRpcProvider } from '@ethersproject/providers';
import {
Expand All @@ -30,7 +31,8 @@ import {
Consensus,
readParty,
UpstreamConfig,
fillBlocks
fillBlocks,
createGQLLogger
} from '@cerc-io/util';
import { TypeSource } from '@graphql-tools/utils';
import type {
Expand Down Expand Up @@ -268,7 +270,11 @@ export class ServerCmd {
}

async exec (
createResolvers: (indexer: IndexerInterface, eventWatcher: EventWatcher) => Promise<any>,
createResolvers: (
indexer: IndexerInterface,
eventWatcher: EventWatcher,
gqlLogger: winston.Logger
) => Promise<any>,
typeDefs: TypeSource,
paymentsManager?: PaymentsManager
): Promise<{
Expand Down Expand Up @@ -308,7 +314,8 @@ export class ServerCmd {
await eventWatcher.start();
}

const resolvers = await createResolvers(indexer, eventWatcher);
const gqlLogger = createGQLLogger(config.server.gql.logDir);
const resolvers = await createResolvers(indexer, eventWatcher, gqlLogger);

// Create an Express app
const app: Application = express();
Expand Down
4 changes: 2 additions & 2 deletions packages/codegen/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/codegen",
"version": "0.2.93",
"version": "0.2.94",
"description": "Code generator",
"private": true,
"main": "index.js",
Expand All @@ -20,7 +20,7 @@
},
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@cerc-io/util": "^0.2.93",
"@cerc-io/util": "^0.2.94",
"@graphql-tools/load-files": "^6.5.2",
"@npmcli/package-json": "^5.0.0",
"@poanet/solidity-flattener": "https://github.com/vulcanize/solidity-flattener.git",
Expand Down
2 changes: 2 additions & 0 deletions packages/codegen/src/assets/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ out/

.vscode
.idea

gql-logs/
36 changes: 21 additions & 15 deletions packages/codegen/src/templates/config-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
host = "127.0.0.1"
port = {{port}}
kind = "{{watcherKind}}"
gqlPath = "/graphql"

# Checkpointing state.
checkpointing = true
Expand All @@ -24,25 +23,32 @@
clearEntitiesCacheInterval = 1000

{{/if}}
# Max block range for which to return events in eventsInRange GQL query.
# Use -1 for skipping check on block range.
maxEventsBlockRange = 1000

# Flag to specify whether RPC endpoint supports block hash as block tag parameter
rpcSupportsBlockHashParam = true

# GQL cache settings
[server.gqlCache]
enabled = true
# Server GQL config
[server.gql]
path = "/graphql"

# Max block range for which to return events in eventsInRange GQL query.
# Use -1 for skipping check on block range.
maxEventsBlockRange = 1000

# Log directory for GQL requests
logDir = "./gql-logs"

# GQL cache settings
[server.gql.cache]
enabled = true

# Max in-memory cache size (in bytes) (default 8 MB)
# maxCacheSize
# Max in-memory cache size (in bytes) (default 8 MB)
# maxCacheSize

# GQL cache-control max-age settings (in seconds)
maxAge = 15
{{#if (subgraphPath)}}
timeTravelMaxAge = 86400 # 1 day
{{/if}}
# GQL cache-control max-age settings (in seconds)
maxAge = 15
{{#if (subgraphPath)}}
timeTravelMaxAge = 86400 # 1 day
{{/if}}

[metrics]
host = "127.0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/src/templates/indexer-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ export class Indexer implements IndexerInterface {
}

async getEventsInRange (fromBlockNumber: number, toBlockNumber: number): Promise<Array<Event>> {
return this._baseIndexer.getEventsInRange(fromBlockNumber, toBlockNumber, this._serverConfig.maxEventsBlockRange);
return this._baseIndexer.getEventsInRange(fromBlockNumber, toBlockNumber, this._serverConfig.gql.maxEventsBlockRange);
}

async getSyncStatus (): Promise<SyncStatus | undefined> {
Expand Down
13 changes: 7 additions & 6 deletions packages/codegen/src/templates/package-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@apollo/client": "^3.3.19",
"@cerc-io/cli": "^0.2.93",
"@cerc-io/ipld-eth-client": "^0.2.93",
"@cerc-io/solidity-mapper": "^0.2.93",
"@cerc-io/util": "^0.2.93",
"@cerc-io/cli": "^0.2.94",
"@cerc-io/ipld-eth-client": "^0.2.94",
"@cerc-io/solidity-mapper": "^0.2.94",
"@cerc-io/util": "^0.2.94",
{{#if (subgraphPath)}}
"@cerc-io/graph-node": "^0.2.93",
"@cerc-io/graph-node": "^0.2.94",
{{/if}}
"@ethersproject/providers": "^5.4.4",
"debug": "^4.3.1",
Expand Down Expand Up @@ -75,6 +75,7 @@
"eslint-plugin-standard": "^5.0.0",
"husky": "^7.0.2",
"ts-node": "^10.2.1",
"typescript": "^5.0.2"
"typescript": "^5.0.2",
"winston": "^3.13.0"
}
}
2 changes: 1 addition & 1 deletion packages/codegen/src/templates/readme-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

To enable GQL requests caching:

* Update the `server.gqlCache` config with required settings.
* Update the `server.gql.cache` config with required settings.

* In the GQL [schema file](./src/schema.gql), use the `cacheControl` directive to apply cache hints at schema level.

Expand Down
Loading

0 comments on commit 8d052ad

Please sign in to comment.