Implement the following plan: Add CLI Flag: -cleanup-checkpoints Context Checkpoint…
- User
Implement the following plan:
Add CLI Flag:
-cleanup-checkpointsContext
Checkpoint cleanup currently only runs as a background worker during server operation (interval =
RetentionInMemory). There's no way to trigger it manually — useful for maintenance, disk space recovery, or running cleanup without starting the full server.Approach
Add a
-cleanup-checkpointsflag that runsmetricstore.CleanupCheckpoints()on the checkpoint directory and exits. It needs the metricstore config (forKeys.Checkpoints.RootDir,Keys.Cleanup,Keys.NumWorkers) but does not need the fullInit(no checkpoint loading, no background goroutines, no in-memory store).Changes
1.
cmd/cc-backend/cli.go— add flagAdd
flagCleanupCheckpoints boolto the var block and register it:goflag.BoolVar(&flagCleanupCheckpoints, "cleanup-checkpoints", false, "Clean up old checkpoint files (delete or archive) based on retention settings, then exit")2.
cmd/cc-backend/main.go— handle flagInsert after
initSubsystems()(which initializes the archive needed for config), before theflagServercheck. The handler:- Loads the metricstore config from
ccconf.GetPackageConfig("metric-store")and decodes it intometricstore.Keys - Sets
NumWorkersdefault if not configured - Computes the
fromtimestamp fromKeys.RetentionInMemory - Calls
metricstore.CleanupCheckpoints() - Logs result and exits
go - Loads the metricstore config from
Assistant
Let me start by reading the files I need to modify.
Assistant
Now let me check the metricstore types I need.
Assistant
Good, I have everything I need. Now let me make the changes.
Assistant
Now add the handler in
main.go. I need to add"runtime"to imports and the handler block afterinitSubsystems().Assistant
There's a conflict —
runtimeclashes with the already-importedgithub.com/ClusterCockpit/cc-lib/v2/runtime. I need to alias the standard library import.Assistant
Let me verify the build compiles:
Assistant
Build succeeds. Let me also run vet:
Assistant
Both build and vet pass. Here's a summary of what was changed:
cmd/cc-backend/cli.go: AddedflagCleanupCheckpointsbool variable and registered it as-cleanup-checkpointsflag.cmd/cc-backend/main.go:- Added
goruntime "runtime"import (aliased to avoid conflict withcc-lib/v2/runtime) - Added handler block after
initSubsystems()that decodes the metric-store config, computes the retention cutoff timestamp, and callsmetricstore.CleanupCheckpoints(), then exits with a summary message
- Added