Skip to content

Commit a952b94

Browse files
perhammanton.voskresensky
andauthored
fix: fix snapshots alerts
Co-authored-by: anton.voskresensky <anton.voskresensky@flant.com>
1 parent 86a8cf8 commit a952b94

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

commands/snapshots.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ func runSnapshot(cmd *cobra.Command, args []string) error {
236236
}
237237

238238
for _, group := range snapshotGroups {
239+
if state, ok, err := utils.CheckSnapshotStateInRepo(client, cfg.SnapshotRepo, group.SnapshotName); err == nil && ok {
240+
if state == "SUCCESS" {
241+
logger.Info(fmt.Sprintf("Valid snapshot already exists snapshot=%s", group.SnapshotName))
242+
continue
243+
}
244+
if state == "IN_PROGRESS" {
245+
logger.Info(fmt.Sprintf("Snapshot is currently IN_PROGRESS snapshot=%s repo=%s", group.SnapshotName, cfg.SnapshotRepo))
246+
continue
247+
}
248+
}
249+
239250
exists, err := utils.CheckAndCleanSnapshot(group.SnapshotName, strings.Join(group.Indices, ","), allSnapshots, client, cfg.SnapshotRepo, logger)
240251
if err != nil {
241252
logger.Error(fmt.Sprintf("Failed to check/clean snapshot snapshot=%s error=%v", group.SnapshotName, err))
@@ -271,6 +282,16 @@ func runSnapshot(cmd *cobra.Command, args []string) error {
271282
continue
272283
}
273284
for _, g := range groups {
285+
if state, ok, err := utils.CheckSnapshotStateInRepo(client, repo, g.SnapshotName); err == nil && ok {
286+
if state == "SUCCESS" {
287+
logger.Info(fmt.Sprintf("Valid snapshot already exists repo=%s snapshot=%s", repo, g.SnapshotName))
288+
continue
289+
}
290+
if state == "IN_PROGRESS" {
291+
logger.Info(fmt.Sprintf("Snapshot is currently IN_PROGRESS repo=%s snapshot=%s", repo, g.SnapshotName))
292+
continue
293+
}
294+
}
274295
exists, err := utils.CheckAndCleanSnapshot(g.SnapshotName, strings.Join(g.Indices, ","), existing, client, repo, logger)
275296
if err != nil {
276297
logger.Error(fmt.Sprintf("Failed to check/clean snapshot repo=%s snapshot=%s error=%v", repo, g.SnapshotName, err))

pkg/utils/snapshots.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ func CreateSnapshotWithRetry(client *opensearch.Client, snapshotName, indexName,
229229
time.Sleep(time.Duration(attempt) * time.Second)
230230
continue
231231
}
232+
logger.Error(fmt.Sprintf("Snapshot creation failed after all retries snapshot=%s maxRetries=%d", snapshotName, maxRetries))
233+
SendSnapshotFailureAlert(snapshotName, indexName, madisonClient, logger)
232234
return err
233235
}
234236

0 commit comments

Comments
 (0)