mirror of
https://github.com/graphql-hive/console
synced 2026-05-22 16:48:56 +00:00
Measure the write time of ClickHouse (#439)
This commit is contained in:
parent
549072506e
commit
caa991ee4b
2 changed files with 27 additions and 1 deletions
|
|
@ -20,6 +20,12 @@ export const processTime = new metrics.Summary({
|
|||
help: 'Time spent processing and writing reports',
|
||||
});
|
||||
|
||||
export const writeTime = new metrics.Summary({
|
||||
name: 'usage_ingestor_write_time',
|
||||
help: 'Time spent writing reports',
|
||||
labelNames: ['query', 'destination', 'status'],
|
||||
});
|
||||
|
||||
export const errors = new metrics.Counter({
|
||||
name: 'usage_ingestor_errors',
|
||||
help: 'Number of errors occurred during processing and writing reports',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import * as Sentry from '@sentry/node';
|
||||
import { got } from 'got';
|
||||
import { got, Response as GotResponse } from 'got';
|
||||
import Agent from 'agentkeepalive';
|
||||
import type { FastifyLoggerInstance } from '@hive/service-common';
|
||||
import { compress } from '@hive/usage-common';
|
||||
|
|
@ -10,6 +10,13 @@ import {
|
|||
legacyRegistryOrder,
|
||||
joinIntoSingleMessage,
|
||||
} from './serializer';
|
||||
import { writeTime } from './metrics';
|
||||
|
||||
function hasResponse(error: unknown): error is {
|
||||
response: GotResponse;
|
||||
} {
|
||||
return error instanceof Error && 'response' in error;
|
||||
}
|
||||
|
||||
export interface ClickHouseConfig {
|
||||
protocol: string;
|
||||
|
|
@ -131,6 +138,10 @@ async function writeCsv(
|
|||
logger: FastifyLoggerInstance,
|
||||
maxRetry: number
|
||||
) {
|
||||
const stopTimer = writeTime.startTimer({
|
||||
query,
|
||||
destination: config.host,
|
||||
});
|
||||
return got
|
||||
.post(`${config.protocol ?? 'https'}://${config.host}:${config.port}`, {
|
||||
body,
|
||||
|
|
@ -168,7 +179,16 @@ async function writeCsv(
|
|||
https: agents.https,
|
||||
},
|
||||
})
|
||||
.then(response => {
|
||||
stopTimer({
|
||||
status: response.statusCode,
|
||||
});
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
stopTimer({
|
||||
status: hasResponse(error) && error.response.statusCode ? error.response.statusCode : 'unknown',
|
||||
});
|
||||
Sentry.captureException(error, {
|
||||
level: 'error',
|
||||
tags: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue