Skip to content

Conversation

Tarun-kishore
Copy link
Contributor

@Tarun-kishore Tarun-kishore commented Oct 10, 2025

Description

This PR fixes a bug in the Snapshot Management (SM) deletion workflow where comma-separated snapshot patterns are incorrectly passed as a single string to the GetSnapshotsRequest API, causing SnapshotMissingException even when matching snapshots exist in the repository.

Problem:
When an SM deletion policy includes a snapshot_pattern field (e.g., "snp*"), the code concatenates it with the policy name pattern (e.g., "policy-name*,snp*") and passes this as a single string element to the API. OpenSearch's GetSnapshots API then treats "policy-name*,snp*" as a literal snapshot name rather than two separate patterns to match.

Solution:
Modified the getSnapshots(name: String, repo: String) function in SMUtils.kt to split comma-separated patterns into separate array elements before passing them to GetSnapshotsRequest.snapshots().

Changes:

  • Updated SMUtils.kt to parse comma-separated snapshot patterns into separate array elements
  • Added comprehensive debug logging throughout the SM deletion workflow to aid in troubleshooting
  • Added logging in DeletingState.kt, DeletionStartState.kt, DeletionConditionMetState.kt, and DeletionFinishedState.kt

Impact:

  • Fixes deletion-only SM policies that use the snapshot_pattern field
  • Enables proper lifecycle management of snapshots created outside the policy
  • Resolves false positive "No snapshots found" warnings when snapshots exist

Before:

.snapshots(arrayOf("policy-name*,snp*"))  // Single element - incorrect

After:

val patterns = name.split(",").map { it.trim() }.toTypedArray()
.snapshots(patterns)  // Multiple elements: ["policy-name*", "snp*"] - correct

Related Issues

Resolves #1502

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@Tarun-kishore
Copy link
Contributor Author

Tarun-kishore commented Oct 10, 2025

@bowenlan-amzn Please review this PR. Tagging you as you have context on feature PR for this.
Thanks

Copy link

codecov bot commented Oct 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.49%. Comparing base (3cf62f0) to head (6157137).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1503      +/-   ##
==========================================
+ Coverage   76.47%   76.49%   +0.01%     
==========================================
  Files         375      375              
  Lines       18835    18836       +1     
  Branches     2401     2401              
==========================================
+ Hits        14405    14409       +4     
- Misses       3182     3186       +4     
+ Partials     1248     1241       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] SM deletion fails to find snapshots when using snapshot_pattern with comma-separated values

1 participant