Improve logging and naming
This commit is contained in:
@@ -422,12 +422,11 @@ func (db *Database) dumpTo(ctx context.Context, w io.Writer) error { //nolint:un
|
||||
return enc.Encode(conns)
|
||||
}
|
||||
|
||||
// PurgeOldHistory deletes history data outside of the (per-app) retention time frame.
|
||||
func (db *Database) PurgeOldHistory(ctx context.Context) error {
|
||||
// CleanupHistory deletes history data outside of the (per-app) retention time frame.
|
||||
func (db *Database) CleanupHistory(ctx context.Context) error {
|
||||
// Setup tracer for the clean up process.
|
||||
ctx, tracer := log.AddTracer(ctx)
|
||||
defer tracer.Submit()
|
||||
defer tracer.Info("history: deleted connections outside of retention from %d profiles")
|
||||
|
||||
// Get list of profiles in history.
|
||||
query := "SELECT DISTINCT profile FROM history.connections"
|
||||
@@ -485,12 +484,15 @@ func (db *Database) PurgeOldHistory(ctx context.Context) error {
|
||||
tracer.Debugf(
|
||||
"history: deleted connections older than %d days (before %s) of %s",
|
||||
retentionDays,
|
||||
threshold,
|
||||
threshold.Format(time.RFC822),
|
||||
profileName,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Log summary.
|
||||
tracer.Infof("history: deleted connections outside of retention from %d profiles", profileCnt)
|
||||
|
||||
return merr.ErrorOrNil()
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ type (
|
||||
// the bandwidth data to the history database.
|
||||
UpdateBandwidth(ctx context.Context, enableHistory bool, processKey string, connID string, bytesReceived uint64, bytesSent uint64) error
|
||||
|
||||
// PurgeOldHistory deletes data outside of the retention time frame from the history database.
|
||||
PurgeOldHistory(ctx context.Context) error
|
||||
// CleanupHistory deletes data outside of the retention time frame from the history database.
|
||||
CleanupHistory(ctx context.Context) error
|
||||
|
||||
// Close closes the connection store. It must not be used afterwards.
|
||||
Close() error
|
||||
|
||||
@@ -161,7 +161,7 @@ func (m *module) prepare() error {
|
||||
Write: api.PermitUser,
|
||||
BelongsTo: m.Module,
|
||||
ActionFunc: func(ar *api.Request) (msg string, err error) {
|
||||
if err := m.Store.PurgeOldHistory(ar.Context()); err != nil {
|
||||
if err := m.Store.CleanupHistory(ar.Context()); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "Deleted outdated connections.", nil
|
||||
@@ -228,7 +228,7 @@ func (m *module) start() error {
|
||||
})
|
||||
|
||||
m.NewTask("network history cleaner", func(ctx context.Context, _ *modules.Task) error {
|
||||
return m.Store.PurgeOldHistory(ctx)
|
||||
return m.Store.CleanupHistory(ctx)
|
||||
}).Repeat(time.Hour).Schedule(time.Now().Add(10 * time.Minute))
|
||||
|
||||
// For debugging, provide a simple direct SQL query interface using
|
||||
|
||||
Reference in New Issue
Block a user