From 77963758626d6d1b430f66187830c8637fdc27ed Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 4 Oct 2022 10:58:54 +0000 Subject: [PATCH] Use Histogram for write and process duration --- packages/services/usage-ingestor/src/ingestor.ts | 3 +++ packages/services/usage-ingestor/src/metrics.ts | 9 +++++++-- packages/services/usage-ingestor/src/writer.ts | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/services/usage-ingestor/src/ingestor.ts b/packages/services/usage-ingestor/src/ingestor.ts index 55b901252..28127c0e4 100644 --- a/packages/services/usage-ingestor/src/ingestor.ts +++ b/packages/services/usage-ingestor/src/ingestor.ts @@ -3,6 +3,7 @@ import { decompress } from '@hive/usage-common'; import { errors, processTime, + processDuration, reportMessageBytes, ingestedOperationsWrites, ingestedOperationsFailures, @@ -150,6 +151,7 @@ export function createIngestor(config: { partitionsConsumedConcurrently: config.kafka.concurrency, eachMessage({ message }) { const stopTimer = processTime.startTimer(); + const processDurationStop = processDuration.startTimer(); return processMessage({ message, logger, @@ -162,6 +164,7 @@ export function createIngestor(config: { }) .finally(() => { stopTimer(); + processDurationStop(); }); }, }); diff --git a/packages/services/usage-ingestor/src/metrics.ts b/packages/services/usage-ingestor/src/metrics.ts index f4d84623b..f3d5106fe 100644 --- a/packages/services/usage-ingestor/src/metrics.ts +++ b/packages/services/usage-ingestor/src/metrics.ts @@ -20,8 +20,13 @@ export const processTime = new metrics.Summary({ help: 'Time spent processing and writing reports', }); -export const writeTime = new metrics.Summary({ - name: 'usage_ingestor_write_time', +export const processDuration = new metrics.Histogram({ + name: 'usage_ingestor_process_duration_seconds', + help: 'Time spent processing and writing reports', +}); + +export const writeDuration = new metrics.Histogram({ + name: 'usage_ingestor_write_duration_seconds', help: 'Time spent writing reports', labelNames: ['query', 'destination', 'status'], }); diff --git a/packages/services/usage-ingestor/src/writer.ts b/packages/services/usage-ingestor/src/writer.ts index d42dfb958..575a40eed 100644 --- a/packages/services/usage-ingestor/src/writer.ts +++ b/packages/services/usage-ingestor/src/writer.ts @@ -10,7 +10,7 @@ import { legacyRegistryOrder, joinIntoSingleMessage, } from './serializer'; -import { writeTime } from './metrics'; +import { writeDuration } from './metrics'; function hasResponse(error: unknown): error is { response: GotResponse; @@ -138,7 +138,7 @@ async function writeCsv( logger: FastifyLoggerInstance, maxRetry: number ) { - const stopTimer = writeTime.startTimer({ + const stopTimer = writeDuration.startTimer({ query, destination: config.host, });