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

Metrics should be defined or null #2446

Merged
merged 2 commits into from
May 1, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/lodestar/src/api/rest/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export interface IRestApiModules {
config: IBeaconConfig;
logger: ILogger;
api: IApi;
metrics?: IMetrics;
metrics: IMetrics | null;
}
16 changes: 9 additions & 7 deletions packages/lodestar/src/chain/blocks/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type BlockProcessorModules = {
regen: IStateRegenerator;
emitter: ChainEventEmitter;
bls: IBlsVerifier;
metrics?: IMetrics;
metrics: IMetrics | null;
clock: IBeaconClock;
checkpointStateCache: CheckpointStateCache;
};
Expand All @@ -46,12 +46,14 @@ export class BlockProcessor {
this.modules = modules;
this.jobQueue = new JobQueue(
{maxLength, signal},
modules.metrics && {
length: modules.metrics.blockProcessorQueueLength,
droppedJobs: modules.metrics.blockProcessorQueueDroppedJobs,
jobTime: modules.metrics.blockProcessorQueueJobTime,
jobWaitTime: modules.metrics.blockProcessorQueueJobWaitTime,
}
modules.metrics
? {
length: modules.metrics.blockProcessorQueueLength,
droppedJobs: modules.metrics.blockProcessorQueueDroppedJobs,
jobTime: modules.metrics.blockProcessorQueueJobTime,
jobWaitTime: modules.metrics.blockProcessorQueueJobWaitTime,
}
: undefined
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/lodestar/src/chain/bls/multithread/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {IMetrics} from "../../../metrics";

export type BlsMultiThreadWorkerPoolModules = {
logger: ILogger;
metrics?: IMetrics;
metrics: IMetrics | null;
signal: AbortSignal;
};

Expand Down Expand Up @@ -69,7 +69,7 @@ type WorkerDescriptor = {
*/
export class BlsMultiThreadWorkerPool {
private readonly logger: ILogger;
private readonly metrics?: IMetrics;
private readonly metrics: IMetrics | null;
private readonly signal: AbortSignal;

private readonly format: PointFormat;
Expand Down
4 changes: 2 additions & 2 deletions packages/lodestar/src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface IBeaconChainModules {
config: IBeaconConfig;
db: IBeaconDb;
logger: ILogger;
metrics?: IMetrics;
metrics: IMetrics | null;
anchorState: TreeBacked<allForks.BeaconState>;
}

Expand All @@ -60,7 +60,7 @@ export class BeaconChain implements IBeaconChain {
protected readonly config: IBeaconConfig;
protected readonly db: IBeaconDb;
protected readonly logger: ILogger;
protected readonly metrics?: IMetrics;
protected readonly metrics: IMetrics | null;
protected readonly opts: IChainOptions;
/**
* Internal event emitter is used internally to the chain to update chain state
Expand Down
4 changes: 2 additions & 2 deletions packages/lodestar/src/network/gossip/gossipsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface IGossipsubModules {
validatorFns: TopicValidatorFnMap;
forkDigestContext: IForkDigestContext;
logger: ILogger;
metrics?: IMetrics;
metrics: IMetrics | null;
}

/**
Expand All @@ -44,7 +44,7 @@ export class Eth2Gossipsub extends Gossipsub {
private readonly config: IBeaconConfig;
private readonly forkDigestContext: IForkDigestContext;
private readonly logger: ILogger;
private readonly metrics?: IMetrics;
private readonly metrics: IMetrics | null;
/**
* Cached gossip objects
*
Expand Down
18 changes: 10 additions & 8 deletions packages/lodestar/src/network/gossip/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const gossipQueueOpts: {[K in GossipType]: {maxLength: number; type: QueueType}}

export function createTopicValidatorFnMap(
modules: IObjectValidatorModules,
metrics: IMetrics | undefined,
metrics: IMetrics | null,
signal: AbortSignal
): TopicValidatorFnMap {
const wrappedValidatorFns = mapValues(validatorFns, (validatorFn, type) =>
Expand Down Expand Up @@ -59,17 +59,19 @@ export function wrapWithQueue<K extends GossipType>(
validatorFn: ValidatorFn<K>,
modules: IObjectValidatorModules,
queueOpts: JobQueueOpts,
metrics: IMetrics | undefined,
metrics: IMetrics | null,
type: GossipType
): TopicValidatorFn {
const jobQueue = new JobQueue(
queueOpts,
metrics && {
length: metrics.gossipValidationQueueLength.child({topic: type}),
droppedJobs: metrics.gossipValidationQueueDroppedJobs.child({topic: type}),
jobTime: metrics.gossipValidationQueueJobTime.child({topic: type}),
jobWaitTime: metrics.gossipValidationQueueJobWaitTime.child({topic: type}),
}
metrics
? {
length: metrics.gossipValidationQueueLength.child({topic: type}),
droppedJobs: metrics.gossipValidationQueueDroppedJobs.child({topic: type}),
jobTime: metrics.gossipValidationQueueJobTime.child({topic: type}),
jobWaitTime: metrics.gossipValidationQueueJobWaitTime.child({topic: type}),
}
: undefined
);
return async function (_topicStr, gossipMsg) {
const {gossipTopic, gossipObject} = parseGossipMsg<K>(gossipMsg);
Expand Down
2 changes: 1 addition & 1 deletion packages/lodestar/src/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface INetworkModules {
config: IBeaconConfig;
libp2p: LibP2p;
logger: ILogger;
metrics?: IMetrics;
metrics: IMetrics | null;
chain: IBeaconChain;
db: IBeaconDb;
reqRespHandler: IReqRespHandler;
Expand Down
4 changes: 2 additions & 2 deletions packages/lodestar/src/network/peers/peerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type PeerManagerOpts = {
export type PeerManagerModules = {
libp2p: LibP2p;
logger: ILogger;
metrics?: IMetrics;
metrics: IMetrics | null;
reqResp: IReqResp;
chain: IBeaconChain;
config: IBeaconConfig;
Expand All @@ -71,7 +71,7 @@ export type PeerManagerModules = {
export class PeerManager {
private libp2p: LibP2p;
private logger: ILogger;
private metrics?: IMetrics;
private metrics: IMetrics | null;
private reqResp: IReqResp;
private chain: IBeaconChain;
private config: IBeaconConfig;
Expand Down
6 changes: 3 additions & 3 deletions packages/lodestar/src/node/nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface IBeaconNodeModules {
opts: IBeaconNodeOptions;
config: IBeaconConfig;
db: IBeaconDb;
metrics?: IMetrics;
metrics: IMetrics | null;
network: INetwork;
chain: IBeaconChain;
api: IApi;
Expand Down Expand Up @@ -61,7 +61,7 @@ export class BeaconNode {
opts: IBeaconNodeOptions;
config: IBeaconConfig;
db: IBeaconDb;
metrics?: IMetrics;
metrics: IMetrics | null;
metricsServer?: HttpMetricsServer;
network: INetwork;
chain: IBeaconChain;
Expand Down Expand Up @@ -121,7 +121,7 @@ export class BeaconNode {
// start db if not already started
await db.start();

const metrics = opts.metrics.enabled ? createMetrics(opts.metrics) : undefined;
const metrics = opts.metrics.enabled ? createMetrics(opts.metrics) : null;
if (metrics) {
initBeaconMetrics(metrics, anchorState);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/lodestar/src/sync/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface ISyncModules {
db: IBeaconDb;
logger: ILogger;
chain: IBeaconChain;
metrics?: IMetrics;
metrics: IMetrics | null;
regularSync?: IRegularSync;
gossipHandler?: BeaconGossipHandler;
attestationCollector?: AttestationCollector;
Expand Down
2 changes: 1 addition & 1 deletion packages/lodestar/test/e2e/chain/bls/multithread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("chain / bls / multithread queue", function () {
});
}

const pool = new BlsMultiThreadWorkerPool("blst-native", {logger, signal: controller.signal});
const pool = new BlsMultiThreadWorkerPool("blst-native", {logger, metrics: null, signal: controller.signal});
const isValidArr = await Promise.all(
Array.from({length: 8}, (i) => i).map(() => pool.verifySignatureSets(sets, true))
);
Expand Down
2 changes: 1 addition & 1 deletion packages/lodestar/test/e2e/network/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("network", function () {
const loggerA = testLogger("A");
const loggerB = testLogger("B");

const modules = {config, chain, db, reqRespHandler, signal: controller.signal};
const modules = {config, chain, db, reqRespHandler, signal: controller.signal, metrics: null};
const netA = new Network(opts, {...modules, libp2p: libp2pA, logger: loggerA});
const netB = new Network(opts, {...modules, libp2p: libp2pB, logger: loggerB});

Expand Down
2 changes: 1 addition & 1 deletion packages/lodestar/test/e2e/network/reqresp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("network / ReqResp", function () {
...reqRespHandlerPartial,
};
const opts = {...networkOptsDefault, ...reqRespOpts};
const modules = {config, db, chain, reqRespHandler, signal: controller.signal};
const modules = {config, db, chain, reqRespHandler, signal: controller.signal, metrics: null};
const netA = new Network(opts, {...modules, libp2p: libp2pA, logger: testLogger("A")});
const netB = new Network(opts, {...modules, libp2p: libp2pB, logger: testLogger("B")});
await Promise.all([netA.start(), netB.start()]);
Expand Down
6 changes: 1 addition & 5 deletions packages/lodestar/test/unit/api/rest/debug/getState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ describe("rest - debug - getState", function () {
host: "127.0.0.1",
port: 0,
},
{
config,
logger: testLogger(),
api,
}
{config, logger: testLogger(), api, metrics: null}
);
debugBeaconStub = api.debug.beacon as SinonStubbedInstance<DebugBeaconApi>;
});
Expand Down
6 changes: 1 addition & 5 deletions packages/lodestar/test/unit/api/rest/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ export async function setupRestApiTestServer(): Promise<RestApi> {
host: "127.0.0.1",
port: 0,
},
{
config,
logger: testLogger(),
api,
}
{config, logger: testLogger(), api, metrics: null}
);
}
6 changes: 4 additions & 2 deletions packages/lodestar/test/unit/network/gossip/gossipsub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {testLogger} from "../../../utils/logger";
import {ForkDigestContext} from "../../../../src/util/forkDigestContext";

describe("gossipsub", function () {
const logger = testLogger();
const metrics = null;
let validatorFns: TopicValidatorFnMap;
let gossipSub: Eth2Gossipsub;
let message: InMessage;
Expand Down Expand Up @@ -52,7 +54,7 @@ describe("gossipsub", function () {
validatorFns.set(topicString, () => {
throw new GossipValidationError(ERR_TOPIC_VALIDATOR_REJECT);
});
gossipSub = new Eth2Gossipsub({config, validatorFns, logger: testLogger(), forkDigestContext, libp2p});
gossipSub = new Eth2Gossipsub({config, validatorFns, logger, forkDigestContext, libp2p, metrics});

try {
await gossipSub.validate(message);
Expand All @@ -63,7 +65,7 @@ describe("gossipsub", function () {
});

it("should not throw on successful validation", async () => {
gossipSub = new Eth2Gossipsub({config, validatorFns, logger: testLogger(), forkDigestContext, libp2p});
gossipSub = new Eth2Gossipsub({config, validatorFns, logger, forkDigestContext, libp2p, metrics});
await gossipSub.validate(message);
// no error means pass validation
});
Expand Down
1 change: 1 addition & 0 deletions packages/lodestar/test/unit/sync/gossip/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe("gossip handler", function () {
validatorFns: new Map<string, TopicValidatorFn>(),
logger: testLogger(),
forkDigestContext,
metrics: null,
});
networkStub.gossip = gossipsub;
gossipsub.start();
Expand Down