feat(unified-storage): prune history table based on limits (#101970)

This commit is contained in:
Jean-Philippe Quéméner
2025-03-17 11:36:38 +01:00
committed by GitHub
parent cacdf00067
commit 1700a8aa9f
15 changed files with 282 additions and 8 deletions

View File

@ -44,6 +44,7 @@ var (
sqlResourceHistoryPoll = mustTemplate("resource_history_poll.sql")
sqlResourceHistoryGet = mustTemplate("resource_history_get.sql")
sqlResourceHistoryDelete = mustTemplate("resource_history_delete.sql")
sqlResourceHistoryPrune = mustTemplate("resource_history_prune.sql")
sqlResourceInsertFromHistory = mustTemplate("resource_insert_from_history.sql")
// sqlResourceLabelsInsert = mustTemplate("resource_labels_insert.sql")
@ -252,6 +253,32 @@ func (r sqlGetHistoryRequest) Validate() error {
return nil // TODO
}
// prune resource history
type sqlPruneHistoryRequest struct {
sqltemplate.SQLTemplate
Key *resource.ResourceKey
HistoryLimit int64
}
func (r *sqlPruneHistoryRequest) Validate() error {
if r.HistoryLimit <= 0 {
return fmt.Errorf("history limit must be greater than zero")
}
if r.Key == nil {
return fmt.Errorf("missing key")
}
if r.Key.Namespace == "" {
return fmt.Errorf("missing namespace")
}
if r.Key.Group == "" {
return fmt.Errorf("missing group")
}
if r.Key.Resource == "" {
return fmt.Errorf("missing resource")
}
return nil
}
// update resource history
type sqlResourceHistoryUpdateRequest struct {