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

feat: add s3 ops metrics #317

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
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 .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ docker-compose.yml
/ops/docker-publish.sh

**/.DS_Store

*.temp
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ common/autoinstallers/*/.npmrc

# IDE
.idea
.vscode

# Built js libs
/*/*/lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/graphql-server",
"comment": "add dialect system support",
"type": "minor"
}
],
"packageName": "@subsquid/graphql-server"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"changes": [
{
"packageName": "@subsquid/openreader",
"comment": "introduce dialect system",
"type": "major"
},
{
"packageName": "@subsquid/openreader",
"comment": "remove `ByUniqueInput` queries",
"type": "major"
},
{
"packageName": "@subsquid/openreader",
"comment": "add `thegraph` dialect support",
"type": "minor"
}
],
"packageName": "@subsquid/openreader"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/solana-stream",
"comment": "allow to request all instructions of transaction",
"type": "minor"
}
],
"packageName": "@subsquid/solana-stream"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/solana-stream",
"comment": "allow to request all balances of transaction",
"type": "minor"
}
],
"packageName": "@subsquid/solana-stream"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/util-internal-dump-cli",
"comment": "add prometheus metrics for S3 file system handler",
"type": "patch"
}
],
"packageName": "@subsquid/util-internal-dump-cli"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/util-internal-fs",
"comment": "add metrics for S3 file system handler",
"type": "patch"
}
],
"packageName": "@subsquid/util-internal-fs"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/util-internal-ingest-cli",
"comment": "add prometheus metrics",
"type": "minor"
}
],
"packageName": "@subsquid/util-internal-ingest-cli"
}
24 changes: 19 additions & 5 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions graphql/graphql-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {registerTsNodeIfRequired} from '@subsquid/util-internal-ts-node'
import assert from 'assert'
import {Command, Option} from 'commander'
import {DumbInMemoryCacheOptions, DumbRedisCacheOptions, Server} from './server'
import {Dialect} from '@subsquid/openreader/lib/dialect'


const LOG = createLogger('sqd:graphql-server')
Expand All @@ -26,6 +27,7 @@ runProgram(async () => {
program.option('--dumb-cache-max-age <ms>', 'cache-control max-age in milliseconds', nat, 5000)
program.option('--dumb-cache-ttl <ms>', 'in-memory cached item TTL in milliseconds', nat, 5000)
program.option('--dumb-cache-size <mb>', 'max in-memory cache size in megabytes', nat, 50)
program.addOption(new Option('--dialect <type>').choices(Object.values(Dialect)))

let opts = program.parse().opts() as {
maxRequestSize: number
Expand All @@ -41,6 +43,7 @@ runProgram(async () => {
subscriptionPollInterval: number
subscriptionMaxResponseSize?: number
tsNode?: boolean
dialect?: Dialect
}

await registerTsNodeIfRequired()
Expand Down
22 changes: 14 additions & 8 deletions graphql/graphql-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {InMemoryLRUCache} from '@apollo/utils.keyvaluecache'
import {mergeSchemas} from '@graphql-tools/schema'
import {Logger} from '@subsquid/logger'
import {Context, OpenreaderContext} from '@subsquid/openreader/lib/context'
import {PoolOpenreaderContext} from '@subsquid/openreader/lib/db'
import {Dialect} from '@subsquid/openreader/lib/dialect'
import {DbType, PoolOpenreaderContext} from '@subsquid/openreader/lib/db'
import {Dialect, getSchemaBuilder} from '@subsquid/openreader/lib/dialect'
import type {Model} from '@subsquid/openreader/lib/model'
import {SchemaBuilder} from '@subsquid/openreader/lib/opencrud/schema'
import {addServerCleanup, Dispose, runApollo} from '@subsquid/openreader/lib/server'
import {loadModel, resolveGraphqlSchema} from '@subsquid/openreader/lib/tools'
import {ResponseSizeLimit} from '@subsquid/openreader/lib/util/limit'
Expand Down Expand Up @@ -38,6 +37,7 @@ export interface ServerOptions {
subscriptionPollInterval?: number
subscriptionMaxResponseNodes?: number
dumbCache?: DumbRedisCacheOptions | DumbInMemoryCacheOptions
dialect?: Dialect
}


Expand Down Expand Up @@ -103,8 +103,14 @@ export class Server {

@def
private async schema(): Promise<GraphQLSchema> {
const schemaBuilder = await getSchemaBuilder({
model: this.model(),
subscriptions: this.options.subscriptions,
dialect: this.options.dialect,
})

let schemas = [
new SchemaBuilder({model: this.model(), subscriptions: this.options.subscriptions}).build()
schemaBuilder.build(),
]

if (this.options.squidStatus !== false) {
Expand Down Expand Up @@ -185,14 +191,14 @@ export class Server {

@def
private async context(): Promise<() => Context> {
let dialect = this.dialect()
let dbType = this.dbType()
let createOpenreader: () => OpenreaderContext
if (await this.customResolvers()) {
let con = await this.createTypeormConnection({sqlStatementTimeout: this.options.sqlStatementTimeout})
this.disposals.push(() => con.destroy())
createOpenreader = () => {
return new TypeormOpenreaderContext(
dialect,
dbType,
con,
con,
this.options.subscriptionPollInterval,
Expand All @@ -204,7 +210,7 @@ export class Server {
this.disposals.push(() => pool.end())
createOpenreader = () => {
return new PoolOpenreaderContext(
dialect,
dbType,
pool,
pool,
this.options.subscriptionPollInterval,
Expand Down Expand Up @@ -261,7 +267,7 @@ export class Server {
return envNat('GQL_DB_CONNECTION_POOL_SIZE') || 5
}

private dialect(): Dialect {
private dbType(): DbType {
let type = process.env.DB_TYPE
if (!type) return 'postgres'
switch(type) {
Expand Down
3 changes: 2 additions & 1 deletion graphql/graphql-server/src/typeorm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {Logger} from '@subsquid/logger'
import type {OpenreaderContext} from '@subsquid/openreader/lib/context'
import {DbType} from '@subsquid/openreader/lib/db'
import type {Dialect} from '@subsquid/openreader/lib/dialect'
import type {Query} from '@subsquid/openreader/lib/sql/query'
import {Subscription} from '@subsquid/openreader/lib/subscription'
Expand All @@ -19,7 +20,7 @@ export class TypeormOpenreaderContext implements OpenreaderContext {
private queryCounter = 0

constructor(
public readonly dialect: Dialect,
public readonly dbType: DbType,
private connection: DataSource,
subscriptionConnection?: DataSource,
private subscriptionPollInterval: number = 1000,
Expand Down
6 changes: 4 additions & 2 deletions graphql/openreader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"graphql-parse-resolve-info": "^4.14.0",
"graphql-ws": "^5.14.2",
"pg": "^8.11.3",
"ws": "^8.14.2"
"ws": "^8.14.2",
"inflected": "^2.1.0"
},
"peerDependencies": {
"@subsquid/big-decimal": "^1.0.0"
Expand All @@ -63,6 +64,7 @@
"expect": "^29.7.0",
"gql-test-client": "^0.0.0",
"mocha": "^10.2.0",
"typescript": "~5.3.2"
"typescript": "~5.3.2",
"@types/inflected": "^2.1.3"
}
}
4 changes: 2 additions & 2 deletions graphql/openreader/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Logger} from '@subsquid/logger'
import type {Dialect} from './dialect'
import type {DbType} from './db'
import type {Query} from './sql/query'
import type {Limit} from './util/limit'

Expand All @@ -11,7 +11,7 @@ export interface Context {

export interface OpenreaderContext {
id: number
dialect: Dialect
dbType: DbType
executeQuery<T>(query: Query<T>): Promise<T>
subscription<T>(query: Query<T>): AsyncIterable<T>
responseSizeLimit?: Limit
Expand Down
6 changes: 4 additions & 2 deletions graphql/openreader/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {addErrorContext} from '@subsquid/util-internal'
import type {ClientBase, Pool} from 'pg'
import {QueryResult} from 'pg'
import {OpenreaderContext} from './context'
import {Dialect} from './dialect'
import {Query} from './sql/query'
import {Subscription} from './subscription'
import {LazyTransaction} from './util/lazy-transaction'
Expand All @@ -12,6 +11,9 @@ import {LazyTransaction} from './util/lazy-transaction'
let CTX_COUNTER = 0


export type DbType = 'postgres' | 'cockroach'


export class PoolOpenreaderContext implements OpenreaderContext {
public id = (CTX_COUNTER = (CTX_COUNTER + 1) % Number.MAX_SAFE_INTEGER)
public log?: Logger
Expand All @@ -20,7 +22,7 @@ export class PoolOpenreaderContext implements OpenreaderContext {
private queryCounter = 0

constructor(
public readonly dialect: Dialect,
public readonly dbType: DbType,
pool: Pool,
subscriptionPool?: Pool,
private subscriptionPollInterval: number = 1000,
Expand Down
2 changes: 0 additions & 2 deletions graphql/openreader/src/dialect.ts

This file was deleted.

Loading
Loading