Skip to content

Commit

Permalink
feat(metrics): instrument success and failure rates of chunk broadcas…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
hlolli authored and djwhitt committed Nov 20, 2024
1 parent 1cc1276 commit 5c98e0a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/arweave/composite-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@ export class ArweaveCompositeClient

successCount++;

metrics.arweaveChunkPostCounter.inc({
endpoint: url,
status: 'success',
});

return {
success: true,
statusCode: resp.status,
Expand All @@ -765,6 +770,11 @@ export class ArweaveCompositeClient

failureCount++;

metrics.arweaveChunkPostCounter.inc({
endpoint: url,
status: 'fail',
});

return {
success: false,
statusCode: error.response?.status,
Expand Down
12 changes: 12 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ export const arweaveTxFetchCounter = new promClient.Counter({
labelNames: ['node_type'],
});

export const arweaveChunkPostCounter = new promClient.Counter({
name: 'arweave_chunk_post_total',
help: 'Counts individual POST request to endpoint',
labelNames: ['endpoint', 'status'],
});

export const arweaveChunkBroadcastCounter = new promClient.Counter({
name: 'arweave_chunk_broadcast_total',
help: 'Counts successful broadcast accounting for min threshold count etc',
labelNames: ['status'],
});

//
// SQLite metrics
//
Expand Down
3 changes: 3 additions & 0 deletions src/routes/arweave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Router, default as express } from 'express';

import log from '../log.js';
import * as system from '../system.js';
import * as metrics from '../metrics.js';
import {
CHUNK_POST_URLS,
CHUNK_POST_ABORT_TIMEOUT_MS,
Expand Down Expand Up @@ -54,8 +55,10 @@ arweaveRouter.post('/chunk', async (req, res) => {
if (
result.successCount >= Math.min(MIN_SUCCESS_COUNT, CHUNK_POST_URLS.length)
) {
metrics.arweaveChunkBroadcastCounter.inc({ status: 'success' });
res.status(200).send(result);
} else {
metrics.arweaveChunkBroadcastCounter.inc({ status: 'fail' });
res.status(500).send(result);
}
} catch (error: any) {
Expand Down

0 comments on commit 5c98e0a

Please sign in to comment.