MCPcopy
hub / github.com/crowdsecurity/crowdsec / flushMetrics

Method flushMetrics

pkg/database/flush.go:142–160  ·  view source on GitHub ↗

flushMetrics deletes metrics older than maxAge, regardless if they have been pushed to CAPI or not

(ctx context.Context, maxAge time.Duration)

Source from the content-addressed store, hash-verified

140
141// flushMetrics deletes metrics older than maxAge, regardless if they have been pushed to CAPI or not
142func (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
162func (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 */

Callers

nothing calls this directly

Calls 5

ReceivedAtLTEFunction · 0.92
ExecMethod · 0.45
WhereMethod · 0.45
DeleteMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected