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.
()
| 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. |
| 156 | func (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. |
| 183 | func (s *Store) StartGcLoop(ctx context.Context, duration time.Duration) { |