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

client: make prom client optional #3469

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 14 additions & 8 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { loadKZG } from 'kzg-wasm'
import { Level } from 'level'
import { homedir } from 'os'
import * as path from 'path'
import * as promClient from 'prom-client'
import * as readline from 'readline'
import * as url from 'url'
import * as yargs from 'yargs'
Expand All @@ -54,7 +53,7 @@ import { LevelDB } from '../src/execution/level.js'
import { getLogger } from '../src/logging.js'
import { Event } from '../src/types.js'
import { parseMultiaddrs } from '../src/util/index.js'
import { setupMetrics } from '../src/util/metrics.js'
import { loadPromClient, setupMetrics } from '../src/util/metrics.js'

import { helprpc, startRPCServers } from './startRpc.js'

Expand Down Expand Up @@ -1088,7 +1087,8 @@ async function run() {
let metricsServer: http.Server | undefined
if (args.prometheus === true) {
// Create custom metrics
prometheusMetrics = setupMetrics()
const promClient = await loadPromClient()
prometheusMetrics = await setupMetrics()

const register = new promClient.Registry()
register.setDefaultLabels({
Expand Down
4 changes: 3 additions & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"level": "^8.0.0",
"mcl-wasm": "^1.5.0",
"memory-level": "^1.0.0",
"prom-client": "^15.1.0",
"verkle-cryptography-wasm": "^0.4.5",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5",
Expand All @@ -108,6 +107,9 @@
"testdouble-timers": "^0.1.1",
"ws": "^8.14.2"
},
"optionalDependencies": {
"prom-client": "^15.1.0"
},
"engines": {
"node": ">=18"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { Event, EventBus } from './types.js'
import { isBrowser, short } from './util/index.js'

import type { Logger } from './logging.js'
import type { EventBusType, MultiaddrLike, PrometheusMetrics } from './types.js'
import type { EventBusType, MultiaddrLike } from './types.js'
import type { PrometheusMetrics } from './util/metrics.js'
import type { BlockHeader } from '@ethereumjs/block'
import type { VM, VMProfilerOpts } from '@ethereumjs/vm'
import type { Multiaddr } from '@multiformats/multiaddr'
Expand Down
8 changes: 0 additions & 8 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { Block, BlockHeader } from '@ethereumjs/block'
import type { DefaultStateManager } from '@ethereumjs/statemanager'
import type { Address } from '@ethereumjs/util'
import type { Multiaddr } from '@multiformats/multiaddr'
import type * as promClient from 'prom-client'

/**
* Types for the central event bus, emitted
Expand Down Expand Up @@ -176,10 +175,3 @@ export interface ClientOpts {
ignoreStatelessInvalidExecs?: boolean
useJsCrypto?: boolean
}

export type PrometheusMetrics = {
legacyTxGauge: promClient.Gauge<string>
accessListEIP2930TxGauge: promClient.Gauge<string>
feeMarketEIP1559TxGauge: promClient.Gauge<string>
blobEIP4844TxGauge: promClient.Gauge<string>
}
21 changes: 19 additions & 2 deletions packages/client/src/util/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import * as promClient from 'prom-client'
import type * as promClient from 'prom-client'

export const setupMetrics = () => {
export const loadPromClient = async () => {
try {
const promClient = await import('prom-client')
return promClient
} catch (error) {
throw new Error('Missing prom-client import')
}
}

export const setupMetrics = async () => {
const promClient = await loadPromClient()
return {
legacyTxGauge: new promClient.Gauge({
name: 'legacy_transactions_in_transaction_pool',
Expand All @@ -20,3 +30,10 @@ export const setupMetrics = () => {
}),
}
}

export type PrometheusMetrics = {
legacyTxGauge: promClient.Gauge<string>
accessListEIP2930TxGauge: promClient.Gauge<string>
feeMarketEIP1559TxGauge: promClient.Gauge<string>
blobEIP4844TxGauge: promClient.Gauge<string>
}
Loading
Loading