From 8129c1add9a89eeec936a88c574246033ba76103 Mon Sep 17 00:00:00 2001 From: akvlad Date: Wed, 24 Jan 2024 13:51:37 +0200 Subject: [PATCH] support ADVANCED_PROFILES_MERGE_LIMIT limit --- pyroscope/pyroscope.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyroscope/pyroscope.js b/pyroscope/pyroscope.js index 97836db8..1849b17b 100644 --- a/pyroscope/pyroscope.js +++ b/pyroscope/pyroscope.js @@ -172,7 +172,10 @@ const selectMergeStacktraces = async (req, res) => { Sql.Lte('timestamp_ns', new Sql.Raw(Math.floor(toTimeSec) + '000000000')), new Sql.In('fingerprint', 'IN', idxSelect) )) - const profiles = await clickhouse.rawRequest(sqlReq.toString() + 'FORMAT RowBinary', null, DATABASE_NAME(), { + if (process.env.ADVANCED_PROFILES_MERGE_LIMIT) { + sqlReq.orderBy(['timestamp_ns', 'desc']).limit(parseInt(process.env.ADVANCED_PROFILES_MERGE_LIMIT)) + } + const profiles = await clickhouse.rawRequest(sqlReq.toString() + ' FORMAT RowBinary', null, DATABASE_NAME(), { responseType: 'arraybuffer' }) const binData = Uint8Array.from(profiles.data)