AddSeries adds the batch of input series and returns an error if the limit is reached.
(series ...[]cortexpb.LabelAdapter)
| 67 | |
| 68 | // AddSeries adds the batch of input series and returns an error if the limit is reached. |
| 69 | func (ql *QueryLimiter) AddSeries(series ...[]cortexpb.LabelAdapter) error { |
| 70 | // If the max series is unlimited just return without managing map |
| 71 | if ql.maxSeriesPerQuery == 0 { |
| 72 | return nil |
| 73 | } |
| 74 | fps := make([]model.Fingerprint, 0, len(series)) |
| 75 | for _, s := range series { |
| 76 | fps = append(fps, client.FastFingerprint(s)) |
| 77 | } |
| 78 | |
| 79 | ql.uniqueSeriesMx.Lock() |
| 80 | defer ql.uniqueSeriesMx.Unlock() |
| 81 | for _, fp := range fps { |
| 82 | ql.uniqueSeries[fp] = struct{}{} |
| 83 | } |
| 84 | |
| 85 | if len(ql.uniqueSeries) > ql.maxSeriesPerQuery { |
| 86 | // Format error with max limit |
| 87 | return fmt.Errorf(ErrMaxSeriesHit, ql.maxSeriesPerQuery) |
| 88 | } |
| 89 | return nil |
| 90 | } |
| 91 | |
| 92 | // uniqueSeriesCount returns the count of unique series seen by this query limiter. |
| 93 | func (ql *QueryLimiter) uniqueSeriesCount() int { |