MCPcopy
hub / github.com/google/mtail / Gc

Method Gc

internal/metrics/store.go:156–180  ·  view source on GitHub ↗

Gc iterates through the Store looking for metrics that can be tidied up, if they are passed their expiry or sized greater than their limit.

()

Source from the content-addressed store, hash-verified

154// Gc iterates through the Store looking for metrics that can be tidied up,
155// if they are passed their expiry or sized greater than their limit.
156func (s *Store) Gc() error {
157 glog.Info("Running Store.Expire()")
158 now := time.Now()
159 return s.Range(func(m *Metric) error {
160 if m.Limit > 0 && len(m.LabelValues) >= m.Limit {
161 for i := len(m.LabelValues); i > m.Limit; i-- {
162 m.RemoveOldestDatum()
163 }
164 }
165 for i := 0; i < len(m.LabelValues); i++ {
166 lv := m.LabelValues[i]
167 if lv.Expiry <= 0 {
168 continue
169 }
170 if now.Sub(lv.Value.TimeUTC()) > lv.Expiry {
171 err := m.RemoveDatum(lv.Labels...)
172 if err != nil {
173 return err
174 }
175 i--
176 }
177 }
178 return nil
179 })
180}
181
182// StartGcLoop runs a permanent goroutine to expire metrics every duration.
183func (s *Store) StartGcLoop(ctx context.Context, duration time.Duration) {

Callers 5

StartGcLoopMethod · 0.95
TestExpireOldDatumFunction · 0.95
TestExpireOversizeDatumFunction · 0.95
TestExpireManyMetricsFunction · 0.95
BenchmarkStoreFunction · 0.95

Calls 4

RangeMethod · 0.95
RemoveOldestDatumMethod · 0.80
RemoveDatumMethod · 0.80
TimeUTCMethod · 0.65

Tested by 4

TestExpireOldDatumFunction · 0.76
TestExpireOversizeDatumFunction · 0.76
TestExpireManyMetricsFunction · 0.76
BenchmarkStoreFunction · 0.76