From 5fc3ac0a7fc1b91119cd737737f3afb6c7fd96a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Pazos?= Date: Thu, 21 Dec 2023 15:41:01 -0300 Subject: [PATCH] fix build and small bugfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Pazos --- storage/remote/codec.go | 2 +- storage/remote/codec_test.go | 4 ++-- storage/remote/queue_manager.go | 8 +++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/storage/remote/codec.go b/storage/remote/codec.go index b14920793bf..b7bd2563f7a 100644 --- a/storage/remote/codec.go +++ b/storage/remote/codec.go @@ -630,7 +630,7 @@ func exemplarProtoToExemplar(ep prompb.Exemplar) exemplar.Exemplar { } } -func minMetadataProtoToMetadata(mp *writev2.Metadata, symbols []string) metadata.Metadata { +func minMetadataProtoToMetadata(mp writev2.Metadata, symbols []string) metadata.Metadata { return metadata.Metadata{ Type: metricTypeFromProtoEquivalent(mp.Type), Unit: symbols[mp.UnitRef], // TODO: check for overflow diff --git a/storage/remote/codec_test.go b/storage/remote/codec_test.go index e6878b05b90..651514c7df6 100644 --- a/storage/remote/codec_test.go +++ b/storage/remote/codec_test.go @@ -107,14 +107,14 @@ var writeRequestMinimizedFixture = func() *writev2.WriteRequest { Samples: []writev2.Sample{{Value: 1, Timestamp: 0}}, Exemplars: []writev2.Exemplar{{LabelsRefs: []uint32{10, 11}, Value: 1, Timestamp: 0}}, Histograms: []writev2.Histogram{HistogramToMinHistogramProto(0, &testHistogram), FloatHistogramToMinHistogramProto(1, testHistogram.ToFloat(nil))}, - Metadata: &writev2.Metadata{Type: writev2.Metadata_COUNTER, HelpRef: 14, UnitRef: 15}, + Metadata: writev2.Metadata{Type: writev2.Metadata_COUNTER, HelpRef: 14, UnitRef: 15}, }, { LabelsRefs: labels, Samples: []writev2.Sample{{Value: 2, Timestamp: 1}}, Exemplars: []writev2.Exemplar{{LabelsRefs: []uint32{12, 13}, Value: 2, Timestamp: 1}}, Histograms: []writev2.Histogram{HistogramToMinHistogramProto(2, &testHistogram), FloatHistogramToMinHistogramProto(3, testHistogram.ToFloat(nil))}, - Metadata: &writev2.Metadata{Type: writev2.Metadata_GAUGE, HelpRef: 16, UnitRef: 17}, + Metadata: writev2.Metadata{Type: writev2.Metadata_GAUGE, HelpRef: 16, UnitRef: 17}, }, }, Symbols: st.LabelsStrings(), diff --git a/storage/remote/queue_manager.go b/storage/remote/queue_manager.go index 0947c633131..9bbe65ca781 100644 --- a/storage/remote/queue_manager.go +++ b/storage/remote/queue_manager.go @@ -1663,17 +1663,15 @@ func populateMinimizedTimeSeriesStr(symbolTable *rwSymbolTable, batch []timeSeri if sendNativeHistograms { pendingData[nPending].Histograms = pendingData[nPending].Histograms[:0] } - if sendMetadata { - pendingData[nPending].Metadata = &writev2.Metadata{} - } + // Number of pending samples is limited by the fact that sendSamples (via sendSamplesWithBackoff) // retries endlessly, so once we reach max samples, if we can never send to the endpoint we'll // stop reading from the queue. This makes it safe to reference pendingSamples by index. // pendingData[nPending].Labels = labelsToLabelsProto(d.seriesLabels, pendingData[nPending].Labels) pendingData[nPending].LabelsRefs = labelsToUint32SliceStr(d.seriesLabels, symbolTable, pendingData[nPending].LabelsRefs) - if sendMetadata { - pendingData[nPending].Metadata = &writev2.Metadata{ + if sendMetadata && d.metadata != nil { + pendingData[nPending].Metadata = writev2.Metadata{ Type: metricTypeToProtoEquivalent(d.metadata.Type), HelpRef: symbolTable.RefStr(d.metadata.Help), UnitRef: symbolTable.RefStr(d.metadata.Unit),