Skip to content
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
7 changes: 2 additions & 5 deletions packages/api/src/metrics/ModularizedInstrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
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";

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: (
Expand Down
12 changes: 9 additions & 3 deletions packages/api/src/metrics/OpenTelemetryServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -35,7 +40,8 @@ export type OpenTelemetryServerConfig = {
@dependencyFactory()
export class OpenTelemetryServer extends SequencerModule<OpenTelemetryServerConfig> {
public constructor(
@inject("Sequencer") private readonly sequencer: Sequencer<any>
@inject("ParentContainer")
private readonly parentContainer: ModuleContainerLike
) {
super();
}
Expand All @@ -54,7 +60,7 @@ export class OpenTelemetryServer extends SequencerModule<OpenTelemetryServerConf
config: { metrics, tracing },
} = this;

const seqMetrics = this.sequencer.dependencyContainer.resolve(
const seqMetrics = this.parentContainer.dependencyContainer.resolve(
ModularizedInstrumentation
);

Expand Down
10 changes: 10 additions & 0 deletions packages/indexer/src/Indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ConsoleTracingFactory } from "@proto-kit/sequencer";
import { container } from "tsyringe";

import { IndexerModule } from "./IndexerModule";
import { IndexerHeightInstrumentation } from "./IndexerHeightInstrumentation";

export type IndexerModulesRecord = ModulesRecord<
TypedClass<IndexerModule<unknown>>
Expand All @@ -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() {
Expand Down
23 changes: 23 additions & 0 deletions packages/indexer/src/IndexerHeightInstrumentation.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
1 change: 1 addition & 0 deletions packages/indexer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from "./tasks/IndexBlockTaskParameters";
export * from "./tasks/IndexPendingTxTask";
export * from "./tasks/IndexBatchTask";
export * from "./tasks/IndexSettlementTask";
export * from "./IndexerHeightInstrumentation";
29 changes: 29 additions & 0 deletions packages/sequencer/src/metrics/SettlementInstrumentation.ts
Original file line number Diff line number Diff line change
@@ -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)
);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ export abstract class CircuitCompileTask<
public abstract getTargets(): Promise<CompilableModule[]>;

public async compute(input: CompilerTaskParams): Promise<ArtifactRecord> {
log.info("Computing VKs");

this.compileRegistry.addArtifactsRaw(input.existingArtifacts);

// We need to initialize the VK tree root if we have it, so that
Expand Down
4 changes: 4 additions & 0 deletions packages/sequencer/src/settlement/SettlementModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -83,6 +84,9 @@ export class SettlementModule
AddressRegistry: {
useClass: InMemoryAddressRegistry,
},
SettlementInstrumentation: {
useClass: SettlementInstrumentation,
},
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/stack/src/scripts/graphql/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading