From 277bac622ac74240bbe6b75cbe96fe3472a7dc48 Mon Sep 17 00:00:00 2001 From: ide-rea <30512600+ide-rea@users.noreply.github.com> Date: Wed, 12 May 2021 22:47:05 +0800 Subject: [PATCH] validate exemplar labelSet length first (#8816) * ignore check exemplar labelSet length when append Signed-off-by: XiaoYu Zhang * validate exemplar labelSet length firstly Signed-off-by: XiaoYu Zhang --- tsdb/exemplar.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tsdb/exemplar.go b/tsdb/exemplar.go index 6332c1fe3..d5b7be57f 100644 --- a/tsdb/exemplar.go +++ b/tsdb/exemplar.go @@ -176,16 +176,11 @@ func (ce *CircularExemplarStorage) ValidateExemplar(l labels.Labels, e exemplar. return ce.validateExemplar(seriesLabels, e, false) } -// Not thread safe. The append parameters tells us whether this is an external validation, or interal -// as a reuslt of an AddExemplar call, in which case we should update any relevant metrics. +// Not thread safe. The append parameters tells us whether this is an external validation, or internal +// as a result of an AddExemplar call, in which case we should update any relevant metrics. func (ce *CircularExemplarStorage) validateExemplar(l string, e exemplar.Exemplar, append bool) error { - idx, ok := ce.index[l] - if !ok { - return nil - } - // Exemplar label length does not include chars involved in text rendering such as quotes - // equals sign, or commas. See definiton of const ExemplarMaxLabelLength. + // equals sign, or commas. See definition of const ExemplarMaxLabelLength. labelSetLen := 0 for _, l := range e.Labels { labelSetLen += utf8.RuneCountInString(l.Name) @@ -196,6 +191,11 @@ func (ce *CircularExemplarStorage) validateExemplar(l string, e exemplar.Exempla } } + idx, ok := ce.index[l] + if !ok { + return nil + } + // Check for duplicate vs last stored exemplar for this series. // NB these are expected, and appending them is a no-op. if ce.exemplars[idx.newest].exemplar.Equals(e) {