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

Add integration test tracking changes performed on all SO types migration metadata #142306

Merged
merged 18 commits into from
Oct 6, 2022

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Sep 30, 2022

Summary

Fix #104100

  • Add an integration test detecting when migration-related properties are updated on any SO type
  • Add internal docs describing what and how we should check when pinged for such reviews.

@pgayvallet pgayvallet added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes v8.6.0 labels Sep 30, 2022
Comment on lines +41 to +48
name: soType.name,
namespaceType: soType.namespaceType,
convertToAliasScript: soType.convertToAliasScript,
convertToMultiNamespaceTypeVersion: soType.convertToMultiNamespaceTypeVersion,
migrationVersions,
schemaVersions,
mappings: getFlattenedObject(soType.mappings ?? {}),
hasExcludeOnUpgrade: !!soType.excludeOnUpgrade,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the fields used for the hashing.

Ideally we would use the 'content' of functions like excludeOnUpgrade or the registered migration functions, but functions can't safely be serialized because of the transpiler (also depends on the nodejs version), so we will have to do without it.

Copy link
Member

Choose a reason for hiding this comment

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

functions can't safely be serialized because of the transpiler

Yeah that's too bad -- we already pin to specific TS & Node versions and could theoretically update these hashes whenever we perform an upgrade, however I think Babel would be the main issue (we don't pin to a specific Babel version AFAIK).

We're probably fine having this be the one hole in our test... We've seen people do things like mess with already-shipped migration functions before, and it would be good to catch that, but at this point seems impractical to hold up this PR in an attempt to solve for that. This PR will still cover the vast majority of SO-related upgrade problems we've seen in the past.

Comment on lines +20 to +30
const hashParts = [
migInfo.name,
migInfo.namespaceType,
migInfo.convertToAliasScript ?? 'none',
migInfo.hasExcludeOnUpgrade,
migInfo.convertToMultiNamespaceTypeVersion ?? 'none',
migInfo.migrationVersions.join(','),
migInfo.schemaVersions.join(','),
JSON.stringify(migInfo.mappings, Object.keys(migInfo.mappings).sort()),
];
const hashFeed = hashParts.join('-');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And this is the hashing logic.

Comment on lines +52 to +59
expect(hashMap).toMatchInlineSnapshot(`
Object {
"action": "7858e6d5a9f231bf23f6f2e57328eb0095b26735",
"action_task_params": "bbd38cbfd74bf6713586fe078e3fa92db2234299",
"alert": "48461f3375d9ba22882ea23a318b62a5b0921a9b",
"api_key_pending_invalidation": "9b4bc1235337da9a87ef05a1d1f4858b2a3b77c6",
"apm-indices": "ceb0870f3a74e2ffc3a1cd3a3c73af76baca0999",
"apm-server-schema": "2bfd2998d3873872e1366458ce553def85418f91",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, we can't use dynamic snapshot easily to have one snapshot per type, at least not if we want to keep the snapshot inline (and even with non-inline, looping has its flaws)

So I had two options here:

  1. use a single snapshot for all types
  2. not use snapshot at all, and have a manually maintained map in the test field.

2. would have helped to have a more explicit error message (we could throw something like the comment at the top of the test), however the main upside I see with 1. is that we can eventually, as a follow-up, run this test with -u as a pre-run CI task (like it's already done for linting or codeowners file update). If we achieve this, it would avoid the PR author to do anything manually. CI would simply run the test with -u, update the snapshot, push the change, which would trigger our review.

This is for this reason (even if not implemented in current PR, we will have a follow-up for that) that I went with the 'big single snapshot' approach.

Comment on lines 10 to 13
# Reviewing SavedObject PRs

## How do SO type automatic review assignment works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Input / comments / addition very welcome for this document.

@pgayvallet pgayvallet marked this pull request as ready for review September 30, 2022 13:04
@pgayvallet pgayvallet requested a review from a team as a code owner September 30, 2022 13:04
@elasticmachine
Copy link
Contributor

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

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.

Added a handful of nits/ideas for the docs. Feel free to take whichever ones you think are useful, and leave out the rest.

Otherwise the test itself LGTM and I think the approach is straightforward and should work well. It's a bummer we can't count on consistent hashes for serialized function bodies, but I don't think that would be an easy problem to solve, and doesn't feel like something we should delay this PR over.

Comment on lines +41 to +48
name: soType.name,
namespaceType: soType.namespaceType,
convertToAliasScript: soType.convertToAliasScript,
convertToMultiNamespaceTypeVersion: soType.convertToMultiNamespaceTypeVersion,
migrationVersions,
schemaVersions,
mappings: getFlattenedObject(soType.mappings ?? {}),
hasExcludeOnUpgrade: !!soType.excludeOnUpgrade,
Copy link
Member

Choose a reason for hiding this comment

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

functions can't safely be serialized because of the transpiler

Yeah that's too bad -- we already pin to specific TS & Node versions and could theoretically update these hashes whenever we perform an upgrade, however I think Babel would be the main issue (we don't pin to a specific Babel version AFAIK).

We're probably fine having this be the one hole in our test... We've seen people do things like mess with already-shipped migration functions before, and it would be good to catch that, but at this point seems impractical to hold up this PR in an attempt to solve for that. This PR will still cover the vast majority of SO-related upgrade problems we've seen in the past.

@pgayvallet pgayvallet enabled auto-merge (squash) October 6, 2022 09:18
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/core-test-helpers-so-type-serializer - 12 +12
Unknown metric groups

API count

id before after diff
@kbn/core-test-helpers-so-type-serializer - 13 +13

History

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

@pgayvallet pgayvallet merged commit def43c4 into elastic:main Oct 6, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Oct 6, 2022
WafaaNasr pushed a commit to WafaaNasr/kibana that referenced this pull request Oct 11, 2022
…tion metadata (elastic#142306)

* create empty test helper package

* create extractor

* create hash extraction logic

* fix pkg names

* actually create the test

* updating README

* [CI] Auto-commit changed files from 'node scripts/generate codeowners'

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* documentation draft

* add more fields and update snapshot

* update review doc

* update review documentation

* more feedback

* updating snapshot

Co-authored-by: kibanamachine <[email protected]>
WafaaNasr pushed a commit to WafaaNasr/kibana that referenced this pull request Oct 14, 2022
…tion metadata (elastic#142306)

* create empty test helper package

* create extractor

* create hash extraction logic

* fix pkg names

* actually create the test

* updating README

* [CI] Auto-commit changed files from 'node scripts/generate codeowners'

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* documentation draft

* add more fields and update snapshot

* update review doc

* update review documentation

* more feedback

* updating snapshot

Co-authored-by: kibanamachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting 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 v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SO Migration] write an integration test tracking all registered SO types' migrations, mappings, schemas
6 participants