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

Move CCR out of legacy #62890

Merged
merged 22 commits into from
Apr 22, 2020
Merged

Conversation

cjcenizal
Copy link
Contributor

@cjcenizal cjcenizal commented Apr 8, 2020

Other changes

Reviewing

Reviewing each commit individually might be easier than reviewing the end result. I tried to make each one as atomic as possible, but there may be some slight overlap as I ended up catching and fixing some errors in the later commits.

Testing

Setup

You can run a local cluster and simulate a remote cluster within a single Kibana directory.

  1. Run yarn es snapshot --license=trial and kill the process once the snapshot has been installed.
  2. Duplicate the ES installation by running cp -aR .es/8.0.0 .es/8.0.0-2.
  3. Start your "local" cluster by running .es/8.0.0/bin/elasticsearch and starting Kibana.
  4. Start your "remote" cluster by running .es/8.0.0-2/bin/elasticsearch -E cluster.name=europe -E transport.port=9400.
  5. Index a document into your remote cluster by running curl -X PUT http://elastic:changeme@localhost:9201/my-leader-index --data '{"settings":{"number_of_shards":1,"soft_deletes.enabled":true}}' --header "Content-Type: application/json". Note that these settings are required for testing auto-follow pattern conflicts errors (see below).

Now you can create follower indices and auto-follow patterns to replicate the my-leader-index index on the remote cluster that's available at 127.0.0.1:9400.

Settings

xpack.ccr.ui.enabled: false

With the above setting, verify that CCR isn't visible in the UI and you can't see a "Follower" badge next to follower indices in Index Management.

xpack.remote_clusters.ui.enabled

With the above setting, verify the same effect.

xpack.index_management.enabled

With the above setting, verify the same effect.

xpack.ccr.enabled: false

With the above setting, verify the same effect.

License

  • Verify that an expired license hides CCR in the navigation.
  • Verify that a basic license hides CCR in the navigation.

Permissions

Create a user with just a kibana_user role and verify that a permission error callout is shown (per #27273).

image

Security

Disable security by setting xpack.security.enabled: false in the elastiscearch.yml file of your local cluster and ensure you can still access CCR (per #35333).

Actions

  • Create, edit, pause, resume, view the detail panel, and delete a single auto-follow pattern.
  • Bulk pause, resume, and delete multiple auto-follow patterns.
  • Create, edit, pause, resume, view the detail panel, and unfollow a single follower index
  • Bulk pause, resume, and unfollow multiple follower indices.

Auto-follow pattern conflict errors

  • Create two auto-follow patterns with overlapping patterns (e.g. my* and my-*) that will both capture the my-leader-index index on your remote cluster.
  • Run the curl command to create my-leader-index2 on your remote cluster, since auto-follow patterns don't replicate existing indices.
  • Open the details flyout of one of the auto-follow patterns and verify there is a list of recent errors.

image

Partial errors

  • Create two follower indices.
  • Open Index Management in another tab and delete one of them.
  • In the first tab, try to perform a bulk action on both of the (pause, resume, or unfollow).
  • A danger toast should appear notifying you there was an error with the one you deleted.

Missing entities

  • Navigate to a nonexistent auto-follow pattern and verify the UI shows an error callout.
  • Navigate to a nonexistent follower index and verify the UI shows an error callout.
  • Open a detail flyout of an auto-follow pattern and then edit the URL so that it loads one that doesn't exist. Verify it shows a "not found" message (screenshot below).
  • Open a detail flyout of a follower index and then edit the URL so that it loads one that doesn't exist. Verify it shows a "not found" message (screenshot below).

image

image

@cjcenizal cjcenizal added chore Feature:CCR and Remote Clusters Feature:New Platform Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.8.0 v8.0.0 labels Apr 8, 2020
@elasticmachine
Copy link
Contributor

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

@cjcenizal cjcenizal added the release_note:skip Skip the PR/issue when compiling release notes label Apr 8, 2020
@elastic elastic deleted a comment from kibanamachine Apr 10, 2020
@cjcenizal cjcenizal changed the title Move CCR out of legacy [skip-ci] Move CCR out of legacy Apr 10, 2020
@cjcenizal cjcenizal force-pushed the np/ccr-out-of-legacy branch 5 times, most recently from 6313a9c to 12a3bb5 Compare April 14, 2020 05:01
@cjcenizal cjcenizal force-pushed the np/ccr-out-of-legacy branch 2 times, most recently from be75026 to 77ffce5 Compare April 15, 2020 21:01
@cjcenizal cjcenizal force-pushed the np/ccr-out-of-legacy branch 3 times, most recently from c0f8311 to e53aa4f Compare April 16, 2020 04:24
- Remove deserializeAutoFollowPattern behavior that returned an empty object if the pattern was undefined.
- Localize mocks with the component integration tests.
- Remove security dependency.
- Render timestamp for autofollow errors.
- Fix license check so that CCR won't render if the license is invalid.
- Fix server security check to be more precise by checking if ES has security disabled.
@cjcenizal
Copy link
Contributor Author

@elasticmachine merge upstream

@sebelga
Copy link
Contributor

sebelga commented Apr 20, 2020

Just a note: I don't think the test plan in Testrail has all the usecases mentioned in this PR description.
It might be a good idea to add a link inside the Testrail CCR plan description that points to this PR.

Back to our conversation from last week, we should have a matrix of what can and what cannot be automated. The "Security" part will have to be manual for sure. But almost all the rest could/should be automated.

e.g.

  1. Component integration test: Test that the expected request URL and method is called
  2. Component integration test: Fake the HTTP response with a 404 status and have a test that verifies that there is a callout in the UI
  3. API integration test: call the same URL + method and expect a 404

We just automated the "Missing entities" part of the testing.
This also implies that we have a single source of truth to declare our API endpoints. See cjcenizal#24

cc @cuff-links

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 @cjcenizal , thanks for cleaning up the server side code!

Most of my comments do not need to be blocked on, however;

  • I would highly recommend make the setup functions synchronous however, this is something we will have to do in the future at any rate.
  • Would you mind answering my q's below before I approve?

Running through your tests I noted the following:

Auto-follow patterns

Open the details flyout of one of the auto-follow patterns and verify there is a list of recent errors.

I was not able to see the recent errors you mentioned here 👆🏻. Probably a user error on my part. I did create a follower index before testing this, would that have affected it? Would appreciate you confirming this

Partial errors

...danger toast should appear notifying you there was an error with the one you deleted.

I saw a success notification after performing the bulk update here (not the error notification I expected)

DOC_LINK_VERSION: string;
}): Promise<UnmountCallback> {
// Initialize additional services.
initBreadcrumbs(setBreadcrumbs);
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency across our plugins, could we move these init calls to the plugin.setup function?

Copy link
Contributor Author

@cjcenizal cjcenizal Apr 21, 2020

Choose a reason for hiding this comment

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

I moved them here based on guidance in #62487 (comment). The gist that I got was that we should try to exclude as many imports from the main bundle as possible, to reduce its size. I'll add a comment to the code to clarify this.

Copy link
Contributor

@jloleysens jloleysens Apr 22, 2020

Choose a reason for hiding this comment

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

Hm, I see what you're saying. I think the merit (in KB) of importing here vs. plugin is very small. But we can leave as is for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed! It's negligible. But it's also a negligible effort on my part, and the difference in readability isn't worth a debate IMO. :)

initUiMetric(usageCollection);
initNotification(toasts, fatalErrors);

management.sections.getSection('elasticsearch')!.registerApp({
Copy link
Contributor

Choose a reason for hiding this comment

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

We should keep all registration functionality synchronous. See x-pack/plugins/watcher/public/plugin.ts for an instance of using license but keeping registration sync.

},
});

// The UI is also dependent upon the Remote Clusters UI.
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 I follow this comment, I'm guessing we needed to add Remote Clusters UI config setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The remote_clusters.ui.enabled config setting is what drives the value remoteClusters.isUiEnabled. It sounds like that's not clear? My intention for this comment was to explain that we care about this setting's value because the actual CCR UI cross-links to the Remote Clusters UI, so it won't function without it. I will add these details to the comment but let me know if there's anything else that isn't clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, sorry, I understand now - user error :)

{ licensing, indexManagement, remoteClusters }: Dependencies
): Promise<void> {
const router = http.createRouter();
const config = await this.config$.pipe(first()).toPromise();
Copy link
Contributor

Choose a reason for hiding this comment

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

We can update this to this.config$.pipe(first()).toPromise().then(() => /* do the things */) to keep setup synchronous

const mockRouteContext = ({
crossClusterReplication: {
client: {
callAsCurrentUser: jest
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit; this seems like a pattern that would benefit from being slightly more terse by creating a helper for creating the route context.

},
},
license.guardApiRoute(async (context, request, response) => {
const { id } = request.params as typeof paramsSchema.type;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit; the license guardApiRoute is missing the <P, Q, B> type annotation. See x-pack/plugins/painless_lab/server/services/license.ts. Then we can remove all of the as typeof declarations.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit 2: I personally think it is easier to read like this. I agree there are a few more chars (as typeof), but the overall handler is easier to parse for me at least.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I think there are a few issues with using the as keyword (verbosity is one of them, another being taking on the work of the type system - which can lead to unintended side effects). I would really recommend not using unless necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you both for your input here. I think the connection between request.params and paramsSchema is not too hard to make, considering we define params: paramsSchema in the validation config a few lines above. So I'm going to go ahead and apply JL's suggestion.

export interface RouteDependencies {
router: IRouter;
license: License;
lib: {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

I don't see the index.scss being imported anywhere. Maybe the styles aren't all that necessary? Or you need to import it inside plugin.ts

@cjcenizal
Copy link
Contributor Author

@elasticmachine merge upstream

elasticmachine and others added 5 commits April 21, 2020 13:49
- Import and use History type.
- Make public and server plugin setup functions synchronous.
- Add comments to explain role of remote_clusters.ui.enabled setting and purpose for initializing services inside of the app mount function.
@cjcenizal
Copy link
Contributor Author

@cchaos @jloleysens I've addressed your feedback. Could you please take another look? Caroline, I ended up removing the styles.

@cjcenizal
Copy link
Contributor Author

cjcenizal commented Apr 21, 2020

@jloleysens

Auto-follow patterns

Sorry, I should have clarified in the instructions that you need to index the document in the remote cluster after setting up the auto-follow patterns, since they won't capture existing documents. I just tested locally and verified. I also updated the instructions.

Partial errors

Can you confirm that you were attempting to delete a non-existing follower index? I.e., one that you had already deleted via Index Management or Console? Also, there is a 30 second refresh interval which you might be racing against. If this interval triggers a refresh, the list will refresh and it might appear as if there was no error.

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

👍 Awesome. Deletions are always good :)

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

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.

Thanks for the updates to the PR description (as Seb mentioned, definitely a good source of testing information when we review our current automated vs. manual testing).

I trust you have tested the two points I had questions about, and am happy this contribution to be merged.

DOC_LINK_VERSION: string;
}): Promise<UnmountCallback> {
// Initialize additional services.
initBreadcrumbs(setBreadcrumbs);
Copy link
Contributor

@jloleysens jloleysens Apr 22, 2020

Choose a reason for hiding this comment

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

Hm, I see what you're saying. I think the merit (in KB) of importing here vs. plugin is very small. But we can leave as is for now

},
});

// The UI is also dependent upon the Remote Clusters UI.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, sorry, I understand now - user error :)

@cjcenizal
Copy link
Contributor Author

as Seb mentioned, definitely a good source of testing information when we review our current automated vs. manual testing

Totally! I've shared this PR with @cuff-links and he'll update TestRail with the testing information.

@cjcenizal cjcenizal merged commit 91f7911 into elastic:master Apr 22, 2020
@cjcenizal cjcenizal deleted the np/ccr-out-of-legacy branch April 22, 2020 14:15
cjcenizal added a commit to cjcenizal/kibana that referenced this pull request Apr 22, 2020
* Convert common/services and server/lib to TypeScript. Update Jest tests.
  - Remove deserializeAutoFollowPattern behavior that returned an empty object if the pattern was undefined.
* Localize mocks with the component integration tests.
* Update API unit tests to use NP mocks.
  - Break up test files.
  - Use inline mocked ES response instead of fixture files.
  - Move remaining fixture files into client integration tests directory.
* Make API route validation more strict.
* Publish isUiDisabled as part of Remote Clusters contract.
* Default trackUiMetric service to be a no-op.
* Remove security dependency.
  - Fix license check so that CCR won't render if the license is invalid.
  - Fix server security check to be more precise by checking if ES has security disabled.
* Render timestamp for autofollow errors.
cjcenizal added a commit that referenced this pull request Apr 22, 2020
* Convert common/services and server/lib to TypeScript. Update Jest tests.
  - Remove deserializeAutoFollowPattern behavior that returned an empty object if the pattern was undefined.
* Localize mocks with the component integration tests.
* Update API unit tests to use NP mocks.
  - Break up test files.
  - Use inline mocked ES response instead of fixture files.
  - Move remaining fixture files into client integration tests directory.
* Make API route validation more strict.
* Publish isUiDisabled as part of Remote Clusters contract.
* Default trackUiMetric service to be a no-op.
* Remove security dependency.
  - Fix license check so that CCR won't render if the license is invalid.
  - Fix server security check to be more precise by checking if ES has security disabled.
* Render timestamp for autofollow errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Feature:CCR and Remote Clusters 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.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants