validate exemplar labelSet length first (#8816)

* ignore check exemplar labelSet length when append

Signed-off-by: XiaoYu Zhang <ideoutrea@163.com>

* validate exemplar labelSet length firstly

Signed-off-by: XiaoYu Zhang <ideoutrea@163.com>
pull/6671/head
ide-rea 4 years ago committed by GitHub
parent e313ffa8ab
commit 277bac622a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -176,16 +176,11 @@ func (ce *CircularExemplarStorage) ValidateExemplar(l labels.Labels, e exemplar.
return ce.validateExemplar(seriesLabels, e, false) return ce.validateExemplar(seriesLabels, e, false)
} }
// Not thread safe. The append parameters tells us whether this is an external validation, or interal // Not thread safe. The append parameters tells us whether this is an external validation, or internal
// as a reuslt of an AddExemplar call, in which case we should update any relevant metrics. // 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 { 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 // 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 labelSetLen := 0
for _, l := range e.Labels { for _, l := range e.Labels {
labelSetLen += utf8.RuneCountInString(l.Name) 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. // Check for duplicate vs last stored exemplar for this series.
// NB these are expected, and appending them is a no-op. // NB these are expected, and appending them is a no-op.
if ce.exemplars[idx.newest].exemplar.Equals(e) { if ce.exemplars[idx.newest].exemplar.Equals(e) {

Loading…
Cancel
Save