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

[sample data] handle index aliases when installing/uninstalling datasets #122689

Merged
merged 9 commits into from
Jan 17, 2022

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Jan 11, 2022

Summary

Fix #120137

  • Refactor the install and uninstall sample data routes
  • Add some unit test coverage
  • Handle the case where the sample data indices have been reindexed using UA and are now aliases

Checklist

@pgayvallet pgayvallet added v7.17.0 v8.0.0 v8.1.0 Feature:Home Kibana home application Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc bug Fixes for quality problems that affect the customer experience release_note:skip Skip the PR/issue when compiling release notes labels Jan 12, 2022
} from './translate_timestamp';
import { loadData } from './load_data';

export const insertDataIntoIndex = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was extracted from src/plugins/home/server/services/sample_data/routes/install.ts

Comment on lines +65 to +66
// Failing: See https://github.com/elastic/kibana/issues/121051
describe.skip('dates', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only those 2 tests are flaky so I isolated the skip, as this file is actually the only FTR coverage of the feature.

Comment on lines +118 to +137
try {
// if the sample data was reindexed using UA, the index name is actually an alias pointing to the reindexed
// index. In that case, we need to get rid of the alias and to delete the underlying index
const { body: response } = await this.esClient.asCurrentUser.indices.getAlias({
name: index,
});
const aliasName = index;
index = Object.keys(response)[0];
await this.esClient.asCurrentUser.indices.deleteAlias({ name: aliasName, index });
} catch (err) {
// ignore errors from missing alias
}

try {
await this.esClient.asCurrentUser.indices.delete({
index,
});
} catch (err) {
// ignore delete errors
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual fix, and the only functional change of the PR. We're now checking if there's an alias matching the index name, and if there is, we delete both the alias and the underlying index

@pgayvallet pgayvallet marked this pull request as ready for review January 12, 2022 12:37
@pgayvallet pgayvallet requested a review from a team as a code owner January 12, 2022 12:37
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@lukeelmers
Copy link
Member

@elasticmachine merge upstream

@lukeelmers lukeelmers self-requested a review January 13, 2022 18:18
Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

Ah, I was going to test this manually with a Cloud CI image, but then realized I'd need to test against the backport since I'd need a 7.17 build to compare.

The code & refactor here LGTM (thanks for taking the time to do the additional cleanup) ❤️

Comment on lines +152 to +158
try {
await installer.install('unknown_data_set');
expect('should have returned an error').toEqual('but it did not');
} catch (e) {
expect(e).toBeInstanceOf(SampleDataInstallError);
expect((e as SampleDataInstallError).httpCode).toEqual(404);
}
Copy link
Member

Choose a reason for hiding this comment

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

nit/optional: What's the benefit of using try/catch vs toThrowError?

      expect(async () => {
        await installer.install('unknown_data_set');
      }).rejects.toThrowError(new SampleDataInstallError(...)); 

If for some reason it fails to throw, the jest error message from toThrowError might be clearer than expected 'should have returned an error' to equal 'but it did not'.

Same question applies to other error tests in this file - are you just aiming to have more granular assertions for each aspect of the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless I'm wrong, .rejects.toThrowError(new SampleDataInstallError(...)) will assert against the error's msg too, so I would like to recreate a SampleDataInstallError with the same message we're throwing in the actual code, which I wanted to avoid

@pgayvallet
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
home 25 26 +1

Total ESLint disabled count

id before after diff
home 26 27 +1

History

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

@pgayvallet pgayvallet added the auto-backport Deprecated - use backport:version if exact versions are needed label Jan 17, 2022
@pgayvallet pgayvallet merged commit 683ab10 into elastic:main Jan 17, 2022
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 17, 2022
…ets (elastic#122689)

* refactor install/uninstall routes

* only skip failing tests

* check for aliases when uninstalling sample datasets

* fix return value

* add unit tests

* factorize installer creation

* add tests for the alias scenario

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 683ab10)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.0
7.17 Backport failed because of merge conflicts

How to fix

Re-run the backport manually:

node scripts/backport --pr 122689

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 17, 2022
…ets (#122689) (#123121)

* refactor install/uninstall routes

* only skip failing tests

* check for aliases when uninstalling sample datasets

* fix return value

* add unit tests

* factorize installer creation

* add tests for the alias scenario

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 683ab10)

Co-authored-by: Pierre Gayvallet <pierre.gayvallet@elastic.co>
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Jan 17, 2022
…ets (elastic#122689)

* refactor install/uninstall routes

* only skip failing tests

* check for aliases when uninstalling sample datasets

* fix return value

* add unit tests

* factorize installer creation

* add tests for the alias scenario

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 683ab10)

# Conflicts:
#	src/plugins/home/server/services/sample_data/routes/install.ts
#	src/plugins/home/server/services/sample_data/routes/uninstall.ts
#	src/plugins/home/server/services/sample_data/routes/utils.ts
#	test/api_integration/apis/home/sample_data.ts
pgayvallet added a commit that referenced this pull request Jan 18, 2022
…g datasets (#122689) (#123147)

* [sample data] handle index aliases when installing/uninstalling datasets (#122689)

* refactor install/uninstall routes

* only skip failing tests

* check for aliases when uninstalling sample datasets

* fix return value

* add unit tests

* factorize installer creation

* add tests for the alias scenario

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 683ab10)

# Conflicts:
#	src/plugins/home/server/services/sample_data/routes/install.ts
#	src/plugins/home/server/services/sample_data/routes/uninstall.ts
#	src/plugins/home/server/services/sample_data/routes/utils.ts
#	test/api_integration/apis/home/sample_data.ts

* backport missing lib file

* fix again

* backporting more changes

* remove logger from unmodified route

* revert changes on FTR tests

* adapt installer for 7.x

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@tylersmalley tylersmalley added ci:cloud-deploy Create or update a Cloud deployment and removed ci:deploy-cloud labels Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed bug Fixes for quality problems that affect the customer experience ci:cloud-deploy Create or update a Cloud deployment Feature:Home Kibana home application release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.17.0 v8.0.0 v8.1.0
Projects
None yet
6 participants