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

[Saved Objects] Add a root level managed property to all saved object documents #154515

Merged
merged 23 commits into from
Apr 20, 2023

Conversation

TinaHeiligers
Copy link
Contributor

@TinaHeiligers TinaHeiligers commented Apr 6, 2023

Summary

Part of #140364

ATM, fleet uses a custom tag to identify saved objects installed during package installation. The current implementation has a few disadvantages, such as needing different tag ids per space, making it complex to determine if a saved object is really managed.

As mentioned in #140364 (comment), a better solution would be if there were some sort of property on a document that indicated if it was managed or not, which can then be read from the UI and the behavior toggled accordingly.

The property would default to false and allows the fleet plugin to set it to true on importing objects during package installation.

This PR:

  1. adds an optional managed root-level property to all saved object documents
  2. backfills/migrates managed on existing objects using a core transform
  3. manually migrates sample data (sample data's already on 8.8.0).

I'll add the option to set managed to the import typescript API in a follow-up PR. The option will only be available to plugins and won't have a specific API.

PR deployed on Cloud here

How to test this:

  • run the PR locally or using the cloud deployment
  • Install a sample dataset
  • Navigate to Saved Objects Management and inspect any saved object (except a dataview, the inspect action renders in the Data View App). A simple SO such as Global Settings [8.8.0] is easier.
  • Ensure that the saved object has a managed property that is false (the default).
  • You can repeat the inspect action for the other saved objects too and ensure they all have the default for managed set.
  • Changing managed to true will be implemented in a follow-up PR where we limit being able to set this to Fleet alone, on package install.

Checklist

Note:

Kibana needs to run through a migration to 8.8.0 to add managed. If already on 8.8.0 (dev and, potentially, the Observability clusters that periodically pull from main) the transform won't run. If it turns out to be an issue, we either have to wait for 8.9 to backfill existing SO’s (assuming we'll allow that), work around it by diverging the core version from the kibana version, or come up with another plan.

@TinaHeiligers TinaHeiligers added Feature:Saved Objects release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting v8.8.0 Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc labels Apr 6, 2023
@TinaHeiligers TinaHeiligers marked this pull request as ready for review April 6, 2023 11:24
@TinaHeiligers TinaHeiligers requested review from a team as code owners April 6, 2023 11:24
@elasticmachine
Copy link
Contributor

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

@joshdover joshdover requested a review from a team April 6, 2023 13:45
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.

I tested this by running locally and LGTM! Great work @TinaHeiligers !

I just had a q about needing to do the backfill. IMO could be nice to skip if we don't need to do it?

export const transformSetManagedDefault = (
doc: SavedObjectUnsanitizedDoc<unknown> | undefined
) => ({
transformedDoc: { ...doc!, managed: doc!.managed ?? false },
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: is it necessary to backfill the managed field? Could we assume false and only accept doc.managed === true (i.e., when it is explicitly set)?

Copy link
Contributor Author

@TinaHeiligers TinaHeiligers Apr 6, 2023

Choose a reason for hiding this comment

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

Good question! As it stands, the UI will need to implement the logic to handle different functionality based on if managed is true or not (or undefined).
However, we only really need the flag for fleet right now and don't intend to allow setting managed for any other plugin, otherwise, we'd need to build in a managed_by option too. Is it worth the extra effort based on the fact that we don't need that right now?

The other reason and the main one discussed with @rudolf is dev exp. If managed isn't defined, then everywhere we want to read the value we'd first need to check if it's defined.

We considered using the Serializer to do a sort of "runtime" migration but we'd be checking every doc indefinately.

Copy link
Contributor

Choose a reason for hiding this comment

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

We're also already migrating all documents in 8.8.0 so this would not introduce additional downtime. But if there was a downside to doing it I agree it could have been left out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jloleysens are you ok with keeping the migration for now?

@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@TinaHeiligers
Copy link
Contributor Author

@joshdover could you please encourage the @elastic/fleet team to review?

@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

@TinaHeiligers TinaHeiligers marked this pull request as ready for review April 19, 2023 00:12
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 @TinaHeiligers , thanks for adding the thorough test coverage.

I have a few points I wanted to raise before approving:

  • We only allow setting managed at SO creation time, not as part of an update. I am guessing this is the intended design?
  • I left a comment about the setManaged utility I'd like to get your thoughts on (not a blocker)
  • I think we can simplify a few things about the current tests

Let me know what you think!

attributes: { title: 'Test One' },
references: [{ name: 'ref_0', type: 'test', id: '1' }],
};
const result = await bulkCreateSuccess(client, repository, [objWithoutManaged, obj2]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to another comment, WDYT about setting obj2 to managed: true for these tests? That way this test checks that we are not incorrectly setting true to false

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

Overall looking good!

A few remarks in addition to the ones from @jloleysens

@TinaHeiligers TinaHeiligers dismissed rudolf’s stale review April 20, 2023 17:16

The changes requested have been made.

@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

@TinaHeiligers TinaHeiligers enabled auto-merge (squash) April 20, 2023 18:22
@TinaHeiligers TinaHeiligers merged commit 45449ac into elastic:main Apr 20, 2023
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

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-saved-objects-server 99 100 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
core 352.9KB 353.0KB +91.0B

Saved Objects .kibana field count

Every field in each saved object type adds overhead to Elasticsearch. Kibana needs to keep the total field count below Elasticsearch's default limit of 1000 fields. Only specify field mappings for the fields you wish to search on or query. See https://www.elastic.co/guide/en/kibana/master/saved-objects-service.html#_mappings

id before after diff
managed - 1 +1
Unknown metric groups

API count

id before after diff
@kbn/core-saved-objects-api-browser 109 111 +2
@kbn/core-saved-objects-api-server 347 351 +4
@kbn/core-saved-objects-server 494 496 +2
total +8

ESLint disabled line counts

id before after diff
securitySolution 394 397 +3

References to deprecated APIs

id before after diff
@kbn/core-saved-objects-api-browser 60 64 +4
@kbn/core-saved-objects-api-server-internal 8 10 +2
@kbn/core-saved-objects-browser-internal 251 255 +4
total +10

Total ESLint disabled count

id before after diff
securitySolution 474 477 +3

History

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

@TinaHeiligers TinaHeiligers deleted the saved-objects-add-managed branch April 20, 2023 20:01
nikitaindik pushed a commit to nikitaindik/kibana that referenced this pull request Apr 25, 2023
… documents (elastic#154515)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@rudolf
Copy link
Contributor

rudolf commented May 5, 2023

closes #154642

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 Feature:Saved Objects 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.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants