Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[RFC] persistable state service #67931
[RFC] persistable state service #67931
Changes from all commits
5a919ef
db20dde
d725ea7
f353448
79ae5aa
3186dc2
09d361b
0a54e20
6d13266
514e734
a7c1550
08a8e65
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Two questions here about
Partial<PersistableStateDefinition>
:register('myState', { id: 'whatever' });
which I assume is not desired.Partial
will also allow thedefinition
to be an empty object, which is pointless (though perhaps harmless?)Maybe better to do
Migrate | Inject | Extract
so that you are forced to provide at least one of those, andid
is not allowed?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.
How will the service be able to extract and return the
version
string from an arbitrary state? I don't see any delegate method returning this information onPersistableStateDefinition
.Also minor, but return type inconsistency
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.
extract is taking in latest state and should extract references from it (no version involved)
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.
So the consumer is in charge of passing down the associated
SavedObjectReferences
? If I see how this would work with states contained inside a saved objects, It's harder for things that will not be directly coming from SO, such as localStorage?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.
extract and inject (and thus afterLoad and beforeSave) are actually only relevant when using with saved objects. when storing to url or local storage there is no need to extract the references
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.
Why the static import here, can't this be achieved using setup contract instead?
Also:
As it's supposed to be working using the global registry anyway, what about 'prefer one way to do things' ?
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.
using global registry when you know the id of the state you are working with at compile time is not desired as introduces indirect dependencies (you define dependency of persistable state service, but in reality you depend on pluginOwningState, so you should rather work with plugin owning state directly.
wheter the methods are exposed on the contract or staticly is imo implementation detail of plugin exposing them, i think static exports are prefered when possible but i don't think that should be defined here.
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.
The same note on corrupt state also applies to inject & extract though too, right? For cases where you don't know the ID at compile time and are therefore using the registry, you won't get type safety from TS anyway since all we know is that the state must be serializable.
So
state
should not be trusted & should always be validated by the registrant of inject/extract/migrate. Perhaps a more explicit way to word this is "Migrate, extract, and inject functions must never return invalid or malformed state, and are therefore responsible for checking that the provided values are in the expected shape."FWIW I don't think it's worth yet going down the road of a formalized way of doing validation, config-schema or otherwise... for now it feels sufficient to simply make sure folks registering these definitions know it's up to them.
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.
hmm, yeah i guess theoretically that's right. however when loading you should always do:
inject(migrate(state, version), references)
... so inject function doesn't need to do any checkingwhen saving you always do
extract(state)
where your state should already be typechecked at this point, so it should be safe as well.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.
As this is under the registrator's responsibility to handle these 'enhancements' anyway (and not the service/registry), Isn't that a specific implementation from an existing need/structure from our code more than a generic solution that have to be applied everywhere?
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.
i agree, this is not something that should be applied everywhere, but its listed here under the examples as Stacey had questions about how that would work, so i just wanted to demonstrate that this is not an issue for persistable state registry
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.
Put some examples to show what you mean by
stateType
?Not just to avoid clashes with unknown plugins, but so the registrator and the enhancer both know exactly what id to use.
Enhancer knows to register their enhancements with
drilldowns-{EMBEDDABLE_MIGRATOR}
and embeddable knows to look upstate.enhancements[key]-{EMBEDDABLE_MIGRATOR}
.Above enhancements example should be updated to use the key.
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.
++
Do we want to recommend that registrants export these as consts or in an enum or something? This is implied in the examples but not explicitly stated.
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.
i am not sure if the registrator and enhancer need to know about what id to use ?
for example lets take a look into drilldowns:
drilldowns
plugin registers adrilldowns-drilldownState
persistable state definition3rdparty
plugin registers a3rdparty-drilldownState
persistable state definitionthey both add to
dashboardState.enhancements[key]
... when dashboard is doing migration it simply checks persistable state service for thekey
which for our drilldowns will bedrilldowns-drildownState
and for 3rd party drilldown it will be3rdparty-drilldownState
.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.
I'd be curious to see how the conversion from deserialized state to
EmbeddableInput
will go, and whether we can continue to assume users of Embeddables can still access things like:vs
If we were able to have the serialized representation different from the deserialized representation, we could do this more formally.
But the way the types are right now, deserialized and serialized state are the same. Maybe that layer doesn't have to be part of this system, but if not, I'm not sure where it'd go. 🤔
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.
there is no serialization/deserialization happening inside this service
we are only working with Serializable state (which means a state that can be serialized, so no functions, circular references, .....)
this is kind of in between the StateInstance (EmbeddableInput instance) and SerializedState (for example json stored in database, or url string)
i dont know enough about embeddables, but for visualize state this goes something like this:
vis
--> instance of Vis class, represents the state of each visualizationvis.serialize()
--> returns VisSerializablepersistableStateService.beforeSave('visualization', vis.serialize())
--> returns VisSerializable and references array (the actual type of the object should not change, we just extracted the references)savedVisLoader.save(id, persistableStateService.beforeSave('visualization', vis.serialize()))
--> saves to a saved object (i think the save method actually doesn't exist (yet, or in this form))so with embeddable i could see something like EmbeddableInput, SerializableEmbeddableInput (we need some utility to convert between those) and the later is the one PersistableStatePlugin is interested in (and can be later serialized and stored)
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.
I think we should still have an answer for this for Embeddables to make sure the system supports our needs. Maybe @Dosant or @streamich can work through how this would work with Embeddables.
I think we should touch on what to do when your state is extended like
SpecializedState extends BaseState
. We can mention it in a generalized sense. Like the enhancements pattern, I think the state registrator will have to explicitly support this. I mention above, perhaps we could solve this and the enhancements pattern with the same method, using anenhancements
key on the state?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.
@Dosant can you take a look into this ?
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.
Not sure to really follow here. From what I understood, this persistable state service / registry was not directly linked to SO migrations (see
# Server or Client ?
part), and actual migration of the underlying data would only be performed during object access? Why would we need to fetch/migrate everything during SO migration then?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.
if we were to use this for saved object migrations: with saved object migrations we want to know if there is a migration to perform or not. however this is getting harder and harder because of deep dependency trees:
you can see how our state is deeply nested with various plugins owning various parts of it. Its also not showing everything (its oversimplified). so figuring out if there is a migration required for specific version (7.9.1) is a hard problem.
also important to note: this is a hard problem with or without global registry. actually without global registry this becomes even harder problem to solve imo, as we don't have registries for a lot of parts of the above dashboard state.
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.
Going back on the
part here. I guess that's not the case atm (types are not prefixed with the pluginId, are they). How will 'premigration' of the existing persisted data be performed?
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.
very good point, i think we need to allow migrate function to return different state id. so when i would be migrating the current dashboard enhancements (
enhancement.drilldown
) i can return new state id and change that toenhancements.drilldowns_drilldownState