MCPcopy Create free account
hub / github.com/cortexproject/cortex / ValidateExemplar

Function ValidateExemplar

pkg/util/validation/validate.go:244–277  ·  view source on GitHub ↗

ValidateExemplar returns an error if the exemplar is invalid. The returned error may retain the provided series labels.

(validateMetrics *ValidateMetrics, userID string, ls []cortexpb.LabelAdapter, e cortexpb.Exemplar)

Source from the content-addressed store, hash-verified

242// ValidateExemplar returns an error if the exemplar is invalid.
243// The returned error may retain the provided series labels.
244func ValidateExemplar(validateMetrics *ValidateMetrics, userID string, ls []cortexpb.LabelAdapter, e cortexpb.Exemplar) ValidationError {
245 if len(e.Labels) <= 0 {
246 validateMetrics.DiscardedExemplars.WithLabelValues(exemplarLabelsMissing, userID).Inc()
247 return newExemplarEmtpyLabelsError(ls, []cortexpb.LabelAdapter{}, e.TimestampMs)
248 }
249
250 if e.TimestampMs == 0 {
251 validateMetrics.DiscardedExemplars.WithLabelValues(exemplarTimestampInvalid, userID).Inc()
252 return newExemplarMissingTimestampError(
253 ls,
254 e.Labels,
255 e.TimestampMs,
256 )
257 }
258
259 // Exemplar label length does not include chars involved in text
260 // rendering such as quotes, commas, etc. See spec and const definition.
261 labelSetLen := 0
262 for _, l := range e.Labels {
263 labelSetLen += utf8.RuneCountInString(l.Name)
264 labelSetLen += utf8.RuneCountInString(l.Value)
265 }
266
267 if labelSetLen > ExemplarMaxLabelSetLength {
268 validateMetrics.DiscardedExemplars.WithLabelValues(exemplarLabelsTooLong, userID).Inc()
269 return newExemplarLabelLengthError(
270 ls,
271 e.Labels,
272 e.TimestampMs,
273 )
274 }
275
276 return nil
277}
278
279// ValidateMetricName checks that ls has a valid non-empty metric name when limits.EnforceMetricName is true.
280// It returns (nil, "") when valid, or (error, discardReason) when invalid.

Callers 2

validateSeriesMethod · 0.92
TestValidateExemplarsFunction · 0.85

Calls 4

IncMethod · 0.45

Tested by 1

TestValidateExemplarsFunction · 0.68