ReuseTimeseries puts the timeseries back into a sync.Pool for reuse.
(ts *TimeSeries)
| 330 | |
| 331 | // ReuseTimeseries puts the timeseries back into a sync.Pool for reuse. |
| 332 | func ReuseTimeseries(ts *TimeSeries) { |
| 333 | // Name and Value may point into a large gRPC buffer, so clear the reference to allow GC |
| 334 | for i := 0; i < len(ts.Labels); i++ { |
| 335 | ts.Labels[i].Name = "" |
| 336 | ts.Labels[i].Value = "" |
| 337 | } |
| 338 | ts.Labels = ts.Labels[:0] |
| 339 | ts.Samples = ts.Samples[:0] |
| 340 | // Name and Value may point into a large gRPC buffer, so clear the reference in each exemplar to allow GC |
| 341 | for i := range ts.Exemplars { |
| 342 | for j := range ts.Exemplars[i].Labels { |
| 343 | ts.Exemplars[i].Labels[j].Name = "" |
| 344 | ts.Exemplars[i].Labels[j].Value = "" |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | for i := range ts.Histograms { |
| 349 | ts.Histograms[i].Reset() |
| 350 | } |
| 351 | |
| 352 | ts.Exemplars = ts.Exemplars[:0] |
| 353 | ts.Histograms = ts.Histograms[:0] |
| 354 | timeSeriesPool.Put(ts) |
| 355 | } |