-
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
[sample data] handle index aliases when installing/uninstalling datasets #122689
[sample data] handle index aliases when installing/uninstalling datasets #122689
Conversation
} from './translate_timestamp'; | ||
import { loadData } from './load_data'; | ||
|
||
export const insertDataIntoIndex = ({ |
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.
This was extracted from src/plugins/home/server/services/sample_data/routes/install.ts
// Failing: See https://github.com/elastic/kibana/issues/121051 | ||
describe.skip('dates', () => { |
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.
Only those 2 tests are flaky so I isolated the skip, as this file is actually the only FTR coverage of the feature.
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 | ||
} |
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.
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
Pinging @elastic/kibana-core (Team:Core) |
@elasticmachine merge upstream |
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.
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) ❤️
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); | ||
} |
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.
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?
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.
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
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
…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)
💔 Some backports could not be created
How to fixRe-run the backport manually:
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…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>
…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
…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>
Summary
Fix #120137
Checklist