diff --git a/packages/api/src/metrics/ModularizedInstrumentation.ts b/packages/api/src/metrics/ModularizedInstrumentation.ts index ac18b063..2faf6afc 100644 --- a/packages/api/src/metrics/ModularizedInstrumentation.ts +++ b/packages/api/src/metrics/ModularizedInstrumentation.ts @@ -1,4 +1,4 @@ -import { injectable, injectAll } from "tsyringe"; +import { injectable, injectAll, Lifecycle, scoped } from "tsyringe"; import { PollInstrumentation, PushInstrumentation } from "@proto-kit/sequencer"; import { InstrumentationBase } from "@opentelemetry/instrumentation"; import { mapSequential, splitArray } from "@proto-kit/common"; @@ -6,11 +6,8 @@ import { mapSequential, splitArray } from "@proto-kit/common"; const INSTRUMENTATION_PREFIX = "protokit"; @injectable() +@scoped(Lifecycle.ContainerScoped) export class ModularizedInstrumentation extends InstrumentationBase<{}> { - // private readonly pushInstrumentations: PushInstrumentation[]; - - // private readonly pollInstrumentations: PollInstrumentation[]; - public constructor( @injectAll("Instrumentation") private readonly instrumentations: ( diff --git a/packages/api/src/metrics/OpenTelemetryServer.ts b/packages/api/src/metrics/OpenTelemetryServer.ts index bb871c79..c6c9b1df 100644 --- a/packages/api/src/metrics/OpenTelemetryServer.ts +++ b/packages/api/src/metrics/OpenTelemetryServer.ts @@ -14,7 +14,12 @@ import { RuntimeNodeInstrumentation } from "@opentelemetry/instrumentation-runti import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-grpc"; import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api"; import { inject } from "tsyringe"; -import { dependencyFactory, DependencyRecord, log } from "@proto-kit/common"; +import { + dependencyFactory, + DependencyRecord, + log, + ModuleContainerLike, +} from "@proto-kit/common"; import { OpenTelemetryTracer } from "./OpenTelemetryTracer"; import { ModularizedInstrumentation } from "./ModularizedInstrumentation"; @@ -35,7 +40,8 @@ export type OpenTelemetryServerConfig = { @dependencyFactory() export class OpenTelemetryServer extends SequencerModule { public constructor( - @inject("Sequencer") private readonly sequencer: Sequencer + @inject("ParentContainer") + private readonly parentContainer: ModuleContainerLike ) { super(); } @@ -54,7 +60,7 @@ export class OpenTelemetryServer extends SequencerModule> @@ -26,9 +27,18 @@ export class Indexer< return this.container.resolve("TaskQueue"); } + public static dependencies() { + return { + IndexerHeightInstrumentation: { + useClass: IndexerHeightInstrumentation, + }, + }; + } + public create(childContainerProvider: ChildContainerProvider) { super.create(childContainerProvider); this.useDependencyFactory(ConsoleTracingFactory); + this.useDependencyFactory(Indexer); } public async start() { diff --git a/packages/indexer/src/IndexerHeightInstrumentation.ts b/packages/indexer/src/IndexerHeightInstrumentation.ts new file mode 100644 index 00000000..daf2ab93 --- /dev/null +++ b/packages/indexer/src/IndexerHeightInstrumentation.ts @@ -0,0 +1,23 @@ +import { inject, injectable } from "tsyringe"; +import { + BlockStorage, + instrumentation, + PollInstrumentation, +} from "@proto-kit/sequencer"; + +@instrumentation() +@injectable() +export class IndexerHeightInstrumentation implements PollInstrumentation { + name = "indexer_block_height"; + + description = "Indexer block height"; + + public constructor( + @inject("BlockStorage") + private readonly blockStorage: BlockStorage + ) {} + + public async poll() { + return await this.blockStorage.getCurrentBlockHeight(); + } +} diff --git a/packages/indexer/src/index.ts b/packages/indexer/src/index.ts index 07f57a70..b4eca872 100644 --- a/packages/indexer/src/index.ts +++ b/packages/indexer/src/index.ts @@ -7,3 +7,4 @@ export * from "./tasks/IndexBlockTaskParameters"; export * from "./tasks/IndexPendingTxTask"; export * from "./tasks/IndexBatchTask"; export * from "./tasks/IndexSettlementTask"; +export * from "./IndexerHeightInstrumentation"; diff --git a/packages/sequencer/src/metrics/SettlementInstrumentation.ts b/packages/sequencer/src/metrics/SettlementInstrumentation.ts new file mode 100644 index 00000000..42dd0ed8 --- /dev/null +++ b/packages/sequencer/src/metrics/SettlementInstrumentation.ts @@ -0,0 +1,29 @@ +import { inject, injectable } from "tsyringe"; + +import type { SettlementModule } from "../settlement/SettlementModule"; + +import { instrumentation, PushInstrumentation } from "./Instrumentation"; + +@instrumentation() +@injectable() +export class SettlementInstrumentation extends PushInstrumentation { + names = ["settlement_height"]; + + description = "Settlement height"; + + public constructor( + @inject("SettlementModule") + private readonly settlementModule: SettlementModule + ) { + super(); + } + + public async start() { + this.settlementModule.events.on("settlement-submitted", (settlement) => { + this.pushValue( + "settlement_height", + parseInt(settlement.batches.at(-1)!.toString(), 10) + ); + }); + } +} diff --git a/packages/sequencer/src/protocol/production/tasks/compile/CircuitCompileTask.ts b/packages/sequencer/src/protocol/production/tasks/compile/CircuitCompileTask.ts index 3a87809d..a5091d15 100644 --- a/packages/sequencer/src/protocol/production/tasks/compile/CircuitCompileTask.ts +++ b/packages/sequencer/src/protocol/production/tasks/compile/CircuitCompileTask.ts @@ -84,8 +84,6 @@ export abstract class CircuitCompileTask< public abstract getTargets(): Promise; public async compute(input: CompilerTaskParams): Promise { - log.info("Computing VKs"); - this.compileRegistry.addArtifactsRaw(input.existingArtifacts); // We need to initialize the VK tree root if we have it, so that diff --git a/packages/sequencer/src/settlement/SettlementModule.ts b/packages/sequencer/src/settlement/SettlementModule.ts index 45f54052..6712c66f 100644 --- a/packages/sequencer/src/settlement/SettlementModule.ts +++ b/packages/sequencer/src/settlement/SettlementModule.ts @@ -26,6 +26,7 @@ import type { MinaBaseLayer } from "../protocol/baselayer/MinaBaseLayer"; import { SettleableBatch } from "../storage/model/Batch"; import { Settlement } from "../storage/model/Settlement"; import { SettlementStorage } from "../storage/repositories/SettlementStorage"; +import { SettlementInstrumentation } from "../metrics/SettlementInstrumentation"; import { SettlementUtils } from "./utils/SettlementUtils"; import type { BridgingModule } from "./BridgingModule"; @@ -83,6 +84,9 @@ export class SettlementModule AddressRegistry: { useClass: InMemoryAddressRegistry, }, + SettlementInstrumentation: { + useClass: SettlementInstrumentation, + }, }; } diff --git a/packages/stack/src/scripts/graphql/server.ts b/packages/stack/src/scripts/graphql/server.ts index 57f526a7..94494982 100644 --- a/packages/stack/src/scripts/graphql/server.ts +++ b/packages/stack/src/scripts/graphql/server.ts @@ -243,7 +243,7 @@ export async function startServer() { let nonce = Number(as?.nonce.toString() ?? "0"); setInterval(async () => { - const random = 0; //Math.floor(Math.random() * 5); + const random = Math.floor(Math.random() * 5); await mapSequential(range(0, random), async () => { const tx = await appChain.transaction( priv.toPublicKey(),