Replies: 4 comments 3 replies
-
I like it, the only question I have is if the Core team wants to expose such an endpoint, if they don't maybe we can create |
Beta Was this translation helpful? Give feedback.
-
I like this idea a lot! It is definitely helpful to be able to throw a few different saved objects at a migration in a cheap fashion. I think the current file structure requires at least one more level of namespacing which is currently in the file name ( |
Beta Was this translation helpful? Give feedback.
-
Thanks for creating this Anton, I'm glad to see some brainstorming! I think it's a cool idea, and does make writing the snapshot migration tests very easy, but I think there are some limitations with this approach. It's hard to know what the migrated snapshot test should actually look like, and developers tend to just It also relies on the author of the persistable state to know which saved object to test. Disclaimer: braindump ahead... it may not make much sense...I wonder if there is a way to not rely on manual inspection of the snapshot file. I've been thinking lately if we should require every persistable state implementation to implement a data schema validation function, maybe leveraging kbn-schema. If we did, we could perhaps use that instead of manual inspection. However, that would require the saved object author to write one as well, and to make sure that they called their nested persistable state validation schemas. But I'm not sure how the Dashboard Saved Object would validate its
And lets say we required
In this This is reminiscent of the global persistable state registry however, that we talked about awhile ago and decided to not pursue, but maybe because we know more now, we can think about it again. But the thought is, if we could leverage this data schema validation, instead of requiring a developer to manually inspect a .json snapshot file, I think that would be a big improvement. |
Beta Was this translation helpful? Give feedback.
-
I've been thinking about this topic as well as I've been working on adding some documentation around how to test migrations. It's worth nothing that for simple migrations that don't depend on other plugins or registries, this is definitely overkill and unit tests are much more likely to be effective. For all other migrations, integration tests are a must and the only way to do that properly is to test against a real instance of Kibana. Functional test runner is one way to do this, another would be with the jest_integration suite, which is what I explored in this PR: #106116 One primary advantage to the jest_integration approach is that it requires a simpler set of tools (it's just Jest), however one downside in the current implementation is the development speed. You can't easily start ES and leave it running while you develop, so it will be set up on each suite run. This could be worked around with some sort of development flag that performs this setup conditionally for development only. Though having two separate CLI tools is actually pretty nice since it makes it very explicit that the ES server is still running to avoid any 'dangling process' problems. We'd also need to be sure that however this is turned on and off cannot be checked into the repository unintentionally. I do agree with @stacey-gammon's concerns around using snapshot testing for this area of coverage. It's critical we get these tests correct and I fear it's too easy to update the snapshot without understanding what or why things changed. OTOH, snapshots make it very easy to see how it changed and track those changes across time. Maybe with the right combination of CODEOWNERS assignments to these snapshots we can be sure that nothing changes without enough people on the team being aware. |
Beta Was this translation helpful? Give feedback.
-
What is a persistable state?
Recently, we had a bunch of issues around migrating saved objects with persistable state-owned by other plugins. One area for improvement that we identified is better functional testing. We are working on adding more specific function tests: #102667 and we plan to document steps on how to create such tests that use old saved objects with old states.
In addition to functional tests like in #102667, I want to suggest a low-level migrations testing system where it would be cheaper/faster to add new migrations tests:
saved_object/_migrate
API which gets an old saved object and returns a new saved_object. We would like it to be an integration test, as it is hard to mock all the registries which are used when migrating a saved object with a persistable state.3.1. Create a new
JSON
file with a saved object in an older format3.2 Run a test suite once so that a snapshot is created. Review the snapshot.
3.3. Commit both input and a snapshot.
The assumption is, that having such a system in place, more tests would be created, as it would be faster to add and easier to maintain than such UI tests. Such tests don't remove a need for UI tests, we would still have some UI tests that test migrations, but we won't be focused on those that much.
POC that implements such: #102745
jest-snapshot
package for snapshot feature.So in that POC, to add a new migration test, all a developer needs to do:
test/api_integration/apis/migrations/tests/7_12_0/dashboard_by_value.json
Questions
I think the main general question, for now, is:
Do you think testing migration on this level: running Kibana / making an API call / asserting serialized saved object makes sense?
If yes, we can discuss and work on implementation separately, maybe, inside the pr: #102745
Beta Was this translation helpful? Give feedback.
All reactions