Skip to content
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] NP migration #59109

Merged
merged 49 commits into from
Mar 5, 2020

Conversation

sebelga
Copy link
Contributor

@sebelga sebelga commented Mar 3, 2020

This PR migrates the Snapshot & Restore app to the NP "plugins" folder.

How to test

Add a repository

Local file system

In order to test the snapshot feature locally we will need to have a folder to store the snapshots.

mkdir /tmp/es-backups

We can then launch ES and define this path as a known repository

// Launch ES
yarn es snapshot --license trial -E path.repo=/tmp/es-backups

// Launch Kibana
yarn start
  • Navigate to the Snapshot and Restore app, and to the "Repositories" tab.
  • Register a new repository
  • Give it a name, chose "Shared file system", click "Next"
  • In the "Location" field add "/tmp/es-backups"
  • Click "Register"

Create an index

We won't be able to restore system indices that are not closed so let's create an index for our snapshot. Go to Console and create an index

PUT my-index

Add a policy

Back to the Snapshot and restore app:

  • Create a new policy
  • Give it a name (eg. "my-daily-policy") and also to the snapshot (eg. "<my-snapshot-{now/d}>")
  • Check that the "Repository" field is selected on the repository we created above
  • Click "Next" and under "Snapshot settings" disable "All indices" and only select the index you just created in Console
  • Click "Next". Define in you wish a retention
  • Create the policy

Create a snapshot

  • In the policy list table, click the "Run policy" (play icon) button in the table actions column
  • Navigate to the "Snapshots" tab, you should see the snapshot that has been created
  • Click on it to see the detail

Restore from snapshot

In order to restore the snapshot we need to close the index we created above.

  • Navigate to the Index management app and close the "my-index" index
  • Go back to Snapshot and Restore and under the "Snapshots" tab, click the "Restore" button on the snapshot that has been created
  • Once the restore is finished, you should be taken to the "Restore Status" tab with the detail of the restore. You can click on the "expand" down arrow to see the detail of the restore

Disable the app

  • Shut down the Kibana server
  • Add xpack.snapshot_restore.enabled: false in your kibana.dev.yml file
  • Start Kibana
  • The app should not appear under "Management / Elasticsearch"

Disable Snapshot Lifecycle Management

  • Shut down the Kibana server
  • Comment out the xpack.snapshot_restore.enabled: false we just added in the kibana.dev.yml
  • Add xpack.snapshot_restore.slmUi.enabled: false in your kibana.dev.yml file
  • Start Kibana
  • Navigate to Snapshot and Restore app: the "Policies" tab should not be present

Now re-enable SLM

  • Shut down the Kibana server
  • Comment out the xpack.snapshot_restore.slmUi.enabled: false we just added
  • Start Kibana

Security

A user needs to have the following roles in order to access the Snapshot and Restore app

  • cluster: "cluster:admin/snapshot", "cluster:admin/repository"
  • index: "monitor"

Additionally, a user needs to have the

  • cluster: "cluster:manage_slm" AND "cluster:monitor/state" (this last one is new, I just discovered it when testing) privilege to access the "Policies" tab, even when it is enabled in Kibana config

Let's create a role that does not have the minimum privileges to access the app

  • Navigate to "Management/security/roles" and Create a new role "test-sr-security"
  • Under "Elasticsearch" cluster privileges add the "monitor" privilege
  • Under "Kibana" add "All" privileges
  • Save the role
  • Create a user "test-sr-security", give it a password and attach the role you just created
  • Log out of Kibana and log in with that user
  • Navigate to the app and you should have a "Missing cluster privileges" message.
  • Log out of Kibana and back with the "elastic" username
  • Edit the role we previously created and add MANUALLY (does not appear in the dropdown)
    • "cluster:admin/snapshot" & "cluster:admin/repository" cluster privilege
    • AND the "monitor" privilege to all indices (using the wildcard "*")
  • Log out and in with the "test-sr-security" user. You should now be able to access the app. But if you navigate to the "Policies" tab you should get a warning about missing privileges.
  • Log out of Kibana and back with the "elastic" username
  • Edit the role we previously created and add the "manage_slm" privilege to Elasticsearch
  • Log out and in with the "test-sr-security" user. The "Policies" tab should be visible.

Disable security

  • Shut down Kibana
  • Add xpack.security.enabled: false in the kibana.dev.yml file
  • Start Kibana
  • Without any user, the app and "Policies" tab should be visible

Add a plugin repository

AWS S3

  • Shut down Elasticsearch
  • cd .es/8.0.0
  • Install the s3 plugin
bin/elasticsearch-plugin install https://snapshots.elastic.co/downloads/elasticsearch-plugins/repository-s3/repository-s3-8.0.0-SNAPSHOT.zip
  • Go to the AWS S3 management and create a bucket
  • Create an IAM user in AWS and give it access to S3 (Permissions "AmazonS3FullAccess")
  • Copy the "Access key" for the user and add it to the keystore
bin/elasticsearch-keystore add s3.client.default.access_key
  • Copy the "Secret key" for the user and add it to the keystore
bin/elasticsearch-keystore add s3.client.default.secret_key
  • Start Elasticsearch with the "bin" command (not yarn es snapshot!)
bin/elasticsearch -E path.repo=/tmp/es-backups
  • In Kibana you should be able to create a repository and select "S3" type. Set the bucket name you created and register the new repo.
  • Edit the policy created earlier and chose the S3 repository, then save the policy.
  • Create a Snapshot from the policy. You should see it created in your S3 bucket.
  • Restore from Snapshot should work as well.

@sebelga sebelga requested a review from a team as a code owner March 3, 2020 07:07
[key: string]: React.ReactNode;
}>({});

// On sorting and pagination change
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-wrote this component as there was an infinite re-render due to a state being update inside a useEffect and with the new eslint rule the state being updated had to be put in the array of dependencies.

@sebelga sebelga added Feature:NP Migration Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.7.0 v8.0.0 labels Mar 3, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

@sebelga sebelga added the release_note:skip Skip the PR/issue when compiling release notes label Mar 3, 2020
@sebelga sebelga force-pushed the np-migration/snapshot-restore branch from 6088592 to 0bfe09a Compare March 4, 2020 04:03
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

export const setUiMetricServiceRestore = (_uiMetricService: UiMetricService) => {
uiMetricService = _uiMetricService;
};
// End hack
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 🖐🏻 🎤

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @sebelga ! I did not find any merge blockers but left some comments for discussion.

this.license = new License();
}

public async setup(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure when, but async setup is going to be deprecated in the future and it will become sync code only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Let's wait and see. I guess we'll all have to go and update all our plugins then.

isCloudEnabled: cloud !== undefined && cloud.isCloudEnabled,
isSlmEnabled: pluginConfig.slmUi.enabled,
},
lib: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite cool a cool idea! I hadn't thought of putting commonly used lib (pure) functions in here like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also find it very useful. If there is a need for another lib, add it to the dependency object and it is available on all routes without needing to add imports. Or if we change the route handler file path, no need to worry to update its imports.

@@ -0,0 +1,113 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can get something like this available from core for all tests like this.

It would also be cool to test validation in something like this, there is a similar kind of hackery going on elsewhere (like in upgrade assistant), but I think this iteration is quite clean 👍. Perhaps something we can open an issue for (if there is not one already).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let see first if more apps need this mock. I had to find a solution for SR as the app had so many written unit tests (and no API integration tests). 👍

@sebelga
Copy link
Contributor Author

sebelga commented Mar 5, 2020

Thanks for the review @jloleysens !
I will merge this as the only design change are .scss files that have moved. @elastic/kibana-design let me know if there is anything I overlooked and I will add it in a separate PR 👍

@sebelga sebelga merged commit a05c321 into elastic:master Mar 5, 2020
@sebelga sebelga deleted the np-migration/snapshot-restore branch March 5, 2020 09:37
jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 5, 2020
…re/files-and-filetree

* 'master' of github.com:elastic/kibana: (254 commits)
  Convert discover_page to ts, remove redundunt methods (elastic#59312)
  [Fix for Vis Editor] Revert setting time field to empty string when it's undefined (elastic#58873)
  Delete legacy search endpoint (elastic#59341)
  [Uptime] Improve duration chart (elastic#58404)
  [Snapshot & Restore] NP migration (elastic#59109)
  [ML] Add support for date_nanos time field in anomaly job wizard (elastic#59017)
  Revert "Makes alerting and actions optional properties for interface RequestH… (elastic#59264)"
  Change remote_clusters ID to remoteClusters (elastic#59246)
  Makes alerting and actions optional properties for interface RequestH… (elastic#59264)
  Clean up date histogram agg type. (elastic#58805)
  [ML] Management: fix license unsubscribe (elastic#59365)
  Remove documentation for server.cors settings (elastic#59096)
  Edit alert flyout (elastic#58964)
  [SIEM] Fix rule delete/duplicate actions (elastic#59306)
  move mouse to close obstructing tooltip (elastic#59214)
  Reset page after deleting (elastic#59310)
  Make sure phrases input filter triggers autosuggestons (elastic#59299)
  Add loading count source for http requests (elastic#59245)
  Revert "[ML] Transforms: Deprecate custom KibanaContext. (elastic#59133)"
  Expose metrics service to public API (elastic#59294)
  ...

# Conflicts:
#	src/plugins/console/public/application/containers/editor/legacy/console_editor/editor.tsx
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 6, 2020
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:NP Migration release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants