flushMetrics deletes metrics older than maxAge, regardless if they have been pushed to CAPI or not
(ctx context.Context, maxAge time.Duration)
| 140 | |
| 141 | // flushMetrics deletes metrics older than maxAge, regardless if they have been pushed to CAPI or not |
| 142 | func (c *Client) flushMetrics(ctx context.Context, maxAge time.Duration) { |
| 143 | if maxAge == 0 { |
| 144 | maxAge = defaultMetricsMaxAge |
| 145 | } |
| 146 | |
| 147 | c.Log.Debugf("flushing metrics older than %s", maxAge) |
| 148 | |
| 149 | deleted, err := c.Ent.Metric.Delete().Where( |
| 150 | metric.ReceivedAtLTE(time.Now().UTC().Add(-maxAge)), |
| 151 | ).Exec(ctx) |
| 152 | if err != nil { |
| 153 | c.Log.Errorf("while flushing metrics: %s", err) |
| 154 | return |
| 155 | } |
| 156 | |
| 157 | if deleted > 0 { |
| 158 | c.Log.Debugf("flushed %d metrics snapshots", deleted) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | func (c *Client) FlushOrphans(ctx context.Context) { |
| 163 | /* While it has only been linked to some very corner-case bug : https://github.com/crowdsecurity/crowdsec/issues/778 */ |
nothing calls this directly
no test coverage detected