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

Method AssertMaxSeriesPerLabelSet

pkg/ingester/limiter.go:121–140  ·  view source on GitHub ↗

AssertMaxSeriesPerLabelSet limit has not been reached compared to the current number of metrics with metadata in input and returns an error if so.

(userID string, metric labels.Labels, f func(allLimits []validation.LimitsPerLabelSet, limit validation.LimitsPerLabelSet) (int, error))

Source from the content-addressed store, hash-verified

119// AssertMaxSeriesPerLabelSet limit has not been reached compared to the current
120// number of metrics with metadata in input and returns an error if so.
121func (l *Limiter) AssertMaxSeriesPerLabelSet(userID string, metric labels.Labels, f func(allLimits []validation.LimitsPerLabelSet, limit validation.LimitsPerLabelSet) (int, error)) error {
122 limits := l.limits.LimitsPerLabelSet(userID)
123 matchedLimits := validation.LimitsPerLabelSetsForSeries(limits, metric)
124 for _, limit := range matchedLimits {
125 maxSeriesFunc := func(string) int {
126 return limit.Limits.MaxSeries
127 }
128 local := l.maxByLocalAndGlobal(userID, maxSeriesFunc, maxSeriesFunc)
129 if u, err := f(limits, limit); err != nil {
130 return err
131 } else if u >= local {
132 return errMaxSeriesPerLabelSetLimitExceeded{
133 id: limit.Id,
134 actualLocalLimit: local,
135 globalLimit: limit.Limits.MaxSeries,
136 }
137 }
138 }
139 return nil
140}
141
142// FormatError returns the input error enriched with the actual limits for the given user.
143// It acts as pass-through if the input error is unknown.

Calls 3

maxByLocalAndGlobalMethod · 0.95
LimitsPerLabelSetMethod · 0.80

Tested by 1