From 2b3ee4ecc838543d647d3a0eba98f6c0c44ef3e2 Mon Sep 17 00:00:00 2001 From: almostinf Date: Mon, 6 May 2024 15:39:56 +0300 Subject: [PATCH 1/3] add cleanup-pattern-metrics key --- cmd/cli/main.go | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index f6a01fb9e..a278407d8 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -46,14 +46,15 @@ var plotting = flag.Bool("plotting", false, "enable images in all notifications" var removeSubscriptions = flag.String("remove-subscriptions", "", "Remove given subscriptions separated by semicolons.") var ( - cleanupUsers = flag.Bool("cleanup-users", false, "Disable/delete contacts and subscriptions of missing users") - cleanupLastChecks = flag.Bool("cleanup-last-checks", false, "Delete abandoned triggers last checks.") - cleanupTags = flag.Bool("cleanup-tags", false, "Delete abandoned tags.") - cleanupMetrics = flag.Bool("cleanup-metrics", false, "Delete outdated metrics.") - cleanupRetentions = flag.Bool("cleanup-retentions", false, "Delete abandoned retentions.") - userDel = flag.String("user-del", "", "Delete all contacts and subscriptions for a user") - fromUser = flag.String("from-user", "", "Transfer subscriptions and contacts from user.") - toUser = flag.String("to-user", "", "Transfer subscriptions and contacts to user.") + cleanupUsers = flag.Bool("cleanup-users", false, "Disable/delete contacts and subscriptions of missing users") + cleanupLastChecks = flag.Bool("cleanup-last-checks", false, "Delete abandoned triggers last checks.") + cleanupTags = flag.Bool("cleanup-tags", false, "Delete abandoned tags.") + cleanupMetrics = flag.Bool("cleanup-metrics", false, "Delete outdated metrics.") + cleanupPatternMetrics = flag.Bool("cleanup-pattern-metrics", false, "Delete outdated pattern metrics.") + cleanupRetentions = flag.Bool("cleanup-retentions", false, "Delete abandoned retentions.") + userDel = flag.String("user-del", "", "Delete all contacts and subscriptions for a user") + fromUser = flag.String("from-user", "", "Transfer subscriptions and contacts from user.") + toUser = flag.String("to-user", "", "Transfer subscriptions and contacts to user.") ) var ( @@ -231,13 +232,21 @@ func main() { //nolint log := logger.String(moira.LogFieldNameContext, "cleanup-metrics") log.Info().Msg("Cleanup of outdated metrics started") - err := handleCleanUpOutdatedMetrics(confCleanup, database) - if err != nil { + + if err := handleCleanUpOutdatedMetrics(confCleanup, database); err != nil { log.Error(). Error(err). Msg("Failed to cleanup outdated metrics") } + log.Info().Msg("Cleanup of outdated metrics finished") + } + + if *cleanupPatternMetrics { + log := logger.String(moira.LogFieldNameContext, "cleanup-pattern-metrics") + + log.Info().Msg("Cleanup of outdated pattern metrics started") + count, err := handleCleanUpOutdatedPatternMetrics(database) if err != nil { log.Error(). @@ -249,7 +258,7 @@ func main() { //nolint Int64("deleted_pattern_metrics", count). Msg("Cleaned up outdated pattern metrics") - log.Info().Msg("Cleanup of outdated metrics finished") + log.Info().Msg("Cleanup of outdated pattern metrics finished") } if *cleanupLastChecks { @@ -432,7 +441,7 @@ func openFile(filePath string, mode int) (*os.File, error) { if filePath == "" { return nil, fmt.Errorf("file is not specified") } - file, err := os.OpenFile(filePath, mode, 0666) //nolint:gofumpt,gomnd + file, err := os.OpenFile(filePath, mode, 0o666) //nolint:gofumpt,gomnd if err != nil { return nil, fmt.Errorf("cannot open file: %w", err) } From ebf577d9474681db8a9c340ba2bbec8f5764e07f Mon Sep 17 00:00:00 2001 From: almostinf Date: Mon, 6 May 2024 15:43:32 +0300 Subject: [PATCH 2/3] fix linter fix --- cmd/cli/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index a278407d8..8e424b2ea 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -441,7 +441,7 @@ func openFile(filePath string, mode int) (*os.File, error) { if filePath == "" { return nil, fmt.Errorf("file is not specified") } - file, err := os.OpenFile(filePath, mode, 0o666) //nolint:gofumpt,gomnd + file, err := os.OpenFile(filePath, mode, 0666) //nolint:gofumpt,gomnd if err != nil { return nil, fmt.Errorf("cannot open file: %w", err) } From 9c685e956e6ca7852ea9de39cf9580bcd5f4ae75 Mon Sep 17 00:00:00 2001 From: almostinf Date: Mon, 20 May 2024 16:56:09 +0300 Subject: [PATCH 3/3] fix linter changes --- cmd/cli/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index bd60c21ae..87b63cbad 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -456,7 +456,7 @@ func openFile(filePath string, mode int) (*os.File, error) { if filePath == "" { return nil, fmt.Errorf("file is not specified") } - file, err := os.OpenFile(filePath, mode, 0o666) //nolint:gofumpt,gomnd + file, err := os.OpenFile(filePath, mode, 0666) //nolint:gofumpt,gomnd if err != nil { return nil, fmt.Errorf("cannot open file: %w", err) }