From e02237f805b7f91f83e3ef87f266c8d191a30d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Wed, 15 Jan 2025 12:42:52 +0100 Subject: [PATCH] fix(remotewrite2): do not send uninitialized garbage if there's no metadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found during testing for https://github.com/grafana/mimir/issues/9072 Debug printout showed: KRAJO: seriesName=cortex_request_duration_seconds_bucket, metricFamily=cortex_request_duration_seconds_bucket, type=GAUGE, help=cortex_bucket_index_load_duration_seconds_sum, unit= which is nonsense. I can imagine more cases where this is the case and makes actual sense. Some targets might miss metadata and if there's a pipeline that loses it. Signed-off-by: György Krajcsovits --- storage/remote/queue_manager.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/storage/remote/queue_manager.go b/storage/remote/queue_manager.go index f0ea33fb521b..731a0f405f4e 100644 --- a/storage/remote/queue_manager.go +++ b/storage/remote/queue_manager.go @@ -1919,12 +1919,17 @@ func populateV2TimeSeries(symbolTable *writev2.SymbolsTable, batch []timeSeries, var nPendingSamples, nPendingExemplars, nPendingHistograms, nPendingMetadata int for nPending, d := range batch { pendingData[nPending].Samples = pendingData[nPending].Samples[:0] - // todo: should we also safeguard against empty metadata here? if d.metadata != nil { pendingData[nPending].Metadata.Type = writev2.FromMetadataType(d.metadata.Type) pendingData[nPending].Metadata.HelpRef = symbolTable.Symbolize(d.metadata.Help) pendingData[nPending].Metadata.UnitRef = symbolTable.Symbolize(d.metadata.Unit) nPendingMetadata++ + } else { + // Safeguard against sending garbage in case of not having metadata + // for whatever reason. + pendingData[nPending].Metadata.Type = writev2.Metadata_METRIC_TYPE_UNSPECIFIED + pendingData[nPending].Metadata.HelpRef = symbolTable.Symbolize("") + pendingData[nPending].Metadata.UnitRef = symbolTable.Symbolize("") } if sendExemplars {