From 81d6369a3444f2500f82470ff167e881083a5640 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 11 Jan 2024 23:41:56 +0100 Subject: [PATCH] Fix incorrect merging of samples from hosts The Prometheus library has an optimisation for metrics that expose multiple time series such as Summary that provide two values in the time series consisting of the metric name suffixed with _sum and _count. These are provided as a series of sufixes with corresponding samples such that a serialised summary metric named some_value would have a samples mapping looking something like this: [ ["_sum", ["label=\"value\"", 3]], ["_count", ["lavel=\"value\"", 2]], ] If multiple hosts expose the same metric then these need to be merged, which is the job of mergeSamples, which merges the samples from each sufix into the destination. One corner case that may occur is if the source and destination metric that's being merged have different lists of suffixed samples. In this case the suffixes that are present in the source but not in the destination needs to be added verbatim to the destination. The code for handling this case incorrectly added these samples to the source metric instead of the destination metric. This corner case only occrs if a metric's type differs between two hosts connected to the same controller. For example if a Gauge metric is turned into a Summary metric. --- packages/controller/src/routes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/controller/src/routes.ts b/packages/controller/src/routes.ts index 852f4b59..ab67aeaf 100644 --- a/packages/controller/src/routes.ts +++ b/packages/controller/src/routes.ts @@ -39,7 +39,7 @@ function mergeSamples(destinationResult: lib.CollectorResultSerialized, sourceRe } for (let entry of receivedSamples) { - sourceResult.samples.push(entry); + destinationResult.samples.push(entry); } }