Skip to content

Commit

Permalink
Merge pull request #193 from wormhole-foundation/processing-metrics-f…
Browse files Browse the repository at this point in the history
…ixes

remove old metrics + add receivedAt timestamp to RelayJob
  • Loading branch information
solanoepalacio authored Aug 28, 2023
2 parents 755cf25 + 7cc5aa0 commit 7a9e865
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 68 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/relayer-engine",
"version": "0.2.0",
"version": "0.2.1",
"description": "Relayer Engine",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions relayer/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ export class RelayerApp<ContextT extends Context> extends EventEmitter {
}
if (this.storage) {
const job = await this.storage.addVaaToQueue(parsedVaa.bytes);
// TODO: it would be ideal to only emit the added event only in
// the cases the job was actually added (not already in queue)
this.emit(RelayerEvents.Added, parsedVaa, job);
} else {
this.emit(RelayerEvents.Added, parsedVaa);
Expand Down
39 changes: 0 additions & 39 deletions relayer/storage.metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ export interface StorageMetrics {
waitingGauge: Gauge<string>;
activeGauge: Gauge<string>;
failedGauge: Gauge<string>;
completedCounter: Counter<string>;
failedWithMaxRetriesCounter: Counter<string>;
failedRunsCounter: Counter<string>;
completedDuration: Histogram<string>;
processedDuration: Histogram<string>;
}
export function createStorageMetrics(
storageRegistry: Registry = new Registry(),
Expand Down Expand Up @@ -41,40 +36,6 @@ export function createStorageMetrics(
labelNames: ["queue"],
registers: [storageRegistry],
}),
completedCounter: new Counter({
name: `completed_workflows_total`,
help: "Total number of completed jobs",
labelNames: ["queue"],
registers: [storageRegistry],
}),
failedRunsCounter: new Counter({
name: `failed_workflow_runs_total`,
help: "Total number of failed job runs",
labelNames: ["queue"],
registers: [storageRegistry],
}),
failedWithMaxRetriesCounter: new Counter({
name: `failed_with_max_retries_workflows_total`,
help: "Total number of jobs that failed after max retries. Eg: they will require manual intervention to succeed",
labelNames: ["queue"],
registers: [storageRegistry],
}),
processedDuration: new Histogram({
name: `worklow_processing_duration`,
help: "Processing time in ms for completed jobs (processing until completed)",
buckets: [6000, 7000, 7500, 8000, 8500, 9000, 10000, 12000],
labelNames: ["queue"],
registers: [storageRegistry],
}),
completedDuration: new Histogram({
name: `workflow_total_duration`,
help: "Completion time in ms for jobs (created until completed)",
buckets: [
7500, 10000, 20000, 30000, 45000, 60000, 90000, 120000, 240000,
],
labelNames: ["queue"],
registers: [storageRegistry],
}),
},
};
}
26 changes: 1 addition & 25 deletions relayer/storage/redis-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export class RedisStorage implements Storage {
id: job.id,
maxAttempts: this.opts.attempts,
name: job.name,
receivedAt: job.timestamp,
log: job.log.bind(job),
updateProgress: job.updateProgress.bind(job),
};
Expand All @@ -254,8 +255,6 @@ export class RedisStorage implements Storage {
);
this.workerId = this.worker.id;

this.worker.on("completed", this.onCompleted.bind(this));
this.worker.on("failed", this.onFailed.bind(this));
this.spawnGaugeUpdateWorker();
}

Expand Down Expand Up @@ -284,29 +283,6 @@ export class RedisStorage implements Storage {
this.metrics.failedGauge.labels({ queue: this.vaaQueue.name }).set(failed);
}

private async onCompleted(job: Job) {
const completedDuration = job.finishedOn! - job.timestamp!; // neither can be null
const processedDuration = job.finishedOn! - job.processedOn!; // neither can be null
this.metrics.completedCounter.labels({ queue: this.vaaQueue.name }).inc();
this.metrics.completedDuration
.labels({ queue: this.vaaQueue.name })
.observe(completedDuration);
this.metrics.processedDuration
.labels({ queue: this.vaaQueue.name })
.observe(processedDuration);
}

private async onFailed(job: Job) {
// TODO: Add a failed duration metric for processing time for failed jobs
this.metrics.failedRunsCounter.labels({ queue: this.vaaQueue.name }).inc();

if (job.attemptsMade === this.opts.attempts) {
this.metrics.failedWithMaxRetriesCounter
.labels({ queue: this.vaaQueue.name })
.inc();
}
}

storageKoaUI(path: string) {
// UI
const serverAdapter = new KoaAdapter();
Expand Down
2 changes: 1 addition & 1 deletion relayer/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface RelayJob {
};
attempts: number;
maxAttempts: number;
receivedAt?: number;
receivedAt: number;
log(logRow: string): Promise<number>;
updateProgress(progress: number | object): Promise<void>;
}
Expand Down

0 comments on commit 7a9e865

Please sign in to comment.