-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Snapshot Restore] Fix logic for finding last successful managed snapshot #159324
[Snapshot Restore] Fix logic for finding last successful managed snapshot #159324
Conversation
@elasticmachine merge upstream |
Pinging @elastic/platform-deployment-management (Team:Deployment Management) |
@ElenaStoeva I think you can imitate a managed snapshot following these instructions: #93609 (comment). That said, it's been awhile and I didn't test to confirm 😬 If this works, would you mind updating the plugin README as well with these instructions so we have it documented somewhere? Thanks! |
Thanks @alisonelizabeth, these instructions worked! In this case, I'll update the PR description and will see if we can use this to add some tests.
Sure, I'll update the README. |
@elasticmachine merge upstream |
@@ -41,6 +41,9 @@ export const SnapshotList: React.FunctionComponent<RouteComponentProps<MatchPara | |||
location: { search }, | |||
history, | |||
}) => { | |||
const unfilteredSnapshotsResponse = useLoadSnapshots(DEFAULT_SNAPSHOT_LIST_PARAMS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this bug was introduced when we implemented pagination in #110266.
That PR was merged into v7.16 and so I pulled v7.15 locally to test and it seems the bug is present there as well. 🤔
I'm a little concerned that we are now making 2 requests to get snapshots. Here, and also on L58. Is it possible to avoid this?
Yes, I agree that having 2 requests to Es is not great in terms of performance. The main reason behind this approach is that, based on my understanding, the current implementation filters the snapshots by sending a search request to Es with a query. However, in this way, we cannot get the list of all existing snapshots and so we can't find the correct last successful snapshot since it might not be amongst the filtered ones. That's why I added the second request - without the query - so that we get all existing snapshots and find the last successful one from this list.
The other approach that I had in mind was to send one request without any query and obtain all existing snapshots. Then we can add a function to filter the list based on the filters typed in the search bar. However, at the end this computation might be slower than making a search request to Es with a query. On the other hand, the computation would be performed only when the user adds a filter in the search bar.
What do you think @alisonelizabeth? I'm open to any other ideas or suggestions for improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation @ElenaStoeva!
The other approach that I had in mind was to send one request without any query and obtain all existing snapshots.
I don't think we should pursue this, as users can potentially have a large number of snapshots (the reasoning why we implemented pagination in #110266).
Did you look into if it's possible to fetch only the latest managed snapshot? I think you could leverage the size
and order
parameters (ES docs). However, you would also need the managed repository name and I don't recall if you can specify that you want only successful snapshots returned.
cc @yuliacech as I think she has more familiarity with the pagination work and might have some thoughts too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you look into if it's possible to fetch only the latest managed snapshot? I think you could leverage the
size
andorder
parameters (ES docs). However, you would also need the managed repository name and I don't recall if you can specify that you want only successful snapshots returned.
No, I haven't thought about this, but I think this is a great idea. I don't see a query parameter for filtering by state, but since the returned snapshots can be sorted by start time we would just need to return the first successful one (worst case scenario would be having many unsuccessful snapshots). I see the repository name can be returned in the response, so for each returned snapshot we would have to check if its repository is managed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @alisonelizabeth, I added the implementation that we discussed - fetching the last successful managed snapshot only instead of all unfiltered snapshots. If this implementation makes sense, I will add tests for the new function.
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @ElenaStoeva |
@yuliacech and I discussed this issue over Zoom and here are some of the conclusions that we reached:
This will always return either the last successful managed snapshot or nothing, so it will not cause performance issues. Also, we found another Snapshot and Restore enhancement request (#137432 ) that requires adding a state parameter, so I plan to reach out to the team that works on the Snapshot APIs and ask if they could add this parameter.
|
Thanks for the investigation and summary, Elena!
++ let me know if you need help reaching out to the team. I agree that we should aim for parity between the UI and ES API. I think we had a discussion about this when it was initially implemented and the decision was made to enforce at the UI only at the time, but it's probably worth revisiting. I don't recall the exact reasoning 😅
This might be a good middle approach |
Fixes #158548
Fixes #153107
Summary
This PR changes the logic for finding the last successful managed snapshot by searching amongst all snapshots rather than searching only from the filtered snapshots. This way, the last successful managed snapshot will always be the same, no matter whether the list is filtered or not.
The plugin README is updated with instructions on how to imitate a cloud-managed repository in order to create a managed snapshot.
Also, functional tests are added for checking the logic around last successful snapshots and filtering (the test suite successfully catches the incorrect behaviour when the fix from this PR is not present).
How to test:
We need to mock the cloud environment in order to have a managed repository, policy, and snapshots. Also, we add two different repo paths because we will create two repositories - one managed and one unmanaged so that we test a scenario with a list of managed and unmanaged snapshots.
yarn es snapshot --license trial -E path.repo='/tmp/es-backups','/tmp/snap'
and Kibana withyarn start
cluster.metadata.managed_repository
andcluster.metadata.managed_policies
settings via Console:found-snapshots
) and with location/tmp/es-backups
unmanaged-repo
and with location/tmp/snap
managed-policy
) that uses the managed repository created in step 5.Screen.Recording.2023-06-29.at.18.19.48.mov