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))
| 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. |
| 121 | func (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. |