From 984ab4fd77b8e2ae3489fc54ffdc79672de08a4b Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Tue, 17 Dec 2024 17:53:20 +0000 Subject: [PATCH] Loki: allow configuring `LOKI_RETRIES_ENABLED` and `LOKI_PUSH_TIMEOUT` Change-type: minor --- src/features/device-logs/lib/backends/loki.ts | 10 ++++------ src/lib/config.ts | 5 +++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/features/device-logs/lib/backends/loki.ts b/src/features/device-logs/lib/backends/loki.ts index 1dc9b78d8..9a1096655 100644 --- a/src/features/device-logs/lib/backends/loki.ts +++ b/src/features/device-logs/lib/backends/loki.ts @@ -13,6 +13,8 @@ import { LOKI_HISTORY_GZIP, LOKI_GRPC_SEND_GZIP, LOKI_GRPC_RECEIVE_COMPRESSION_LEVEL, + LOKI_RETRIES_ENABLED, + LOKI_PUSH_TIMEOUT, } from '../../../../lib/config.js'; import type { DeviceLog, @@ -52,10 +54,6 @@ const statusKeys = _.transform( const lokiQueryAddress = `${LOKI_QUERY_HOST}:${LOKI_QUERY_HTTP_PORT}`; const lokiIngesterAddress = `${LOKI_INGESTER_HOST}:${LOKI_INGESTER_GRPC_PORT}`; -// Retries disabled so that writes to Redis are not delayed on Loki error -const RETRIES_ENABLED = false; -// Timeout set to 1s so that writes to Redis are not delayed if Loki is slow -const PUSH_TIMEOUT = 1000; const MIN_BACKOFF = 100; const MAX_BACKOFF = 10 * 1000; const VERSION = 2; @@ -170,7 +168,7 @@ export class LokiBackend implements DeviceLogsBackend { err.code ? statusKeys[err.code] : 'UNDEFINED', ); return ( - RETRIES_ENABLED && + LOKI_RETRIES_ENABLED && [loki.status.UNAVAILABLE, loki.status.RESOURCE_EXHAUSTED].includes( err.code ?? -1, ) @@ -273,7 +271,7 @@ export class LokiBackend implements DeviceLogsBackend { pushRequest, loki.createOrgIdMetadata(ctx.orgId), { - deadline: startAt + PUSH_TIMEOUT, + deadline: startAt + LOKI_PUSH_TIMEOUT, }, (err, response) => { if (err) { diff --git a/src/lib/config.ts b/src/lib/config.ts index ac6264309..458198994 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -325,6 +325,11 @@ if (LOKI_WRITE_PCT < 100 && LOKI_READ_PCT > 0) { throw new Error('LOKI_READ_PCT can only be set if LOKI_WRITE_PCT is 100'); } +// Retries disabled so that writes to Redis are not delayed on Loki error +export const LOKI_RETRIES_ENABLED = boolVar('LOKI_RETRIES_ENABLED', false); +// Timeout set to 1s so that writes to Redis are not delayed if Loki is slow +export const LOKI_PUSH_TIMEOUT = intVar('LOKI_PUSH_TIMEOUT', 1000); + export const NDJSON_CTYPE = 'application/x-ndjson'; // Logs read config