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

[Graph] Make Graph saved object share-capable #111404

Merged
merged 8 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion x-pack/plugins/graph/server/saved_objects/graph_workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { graphMigrations } from './migrations';

export const graphWorkspace: SavedObjectsType = {
name: 'graph-workspace',
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
Comment on lines +13 to +14
Copy link
Contributor

Choose a reason for hiding this comment

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

@jportner we don't need to adapt any call to use resolve instead of get for this specific SO type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done separately in this PR: #109617

hidden: false,
management: {
icon: 'graphApp',
Expand Down
24 changes: 24 additions & 0 deletions x-pack/plugins/graph/server/saved_objects/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,28 @@ describe('graph-workspace', () => {
expect(migratedDoc).toBe(doc);
});
});
describe('8.0.0', () => {
const migration = graphMigrations['8.0.0'];
test('no op migration', () => {
const doc = {
id: '1',
type: 'graph-workspace',
attributes: {
wsState: JSON.stringify(
JSON.stringify({ foo: true, indexPatternRefName: 'indexPattern_0' })
),
bar: true,
},
references: [
{
id: 'pattern*',
name: 'indexPattern_0',
type: 'index-pattern',
},
],
};
const migratedDoc = migration(doc);
expect(migratedDoc).toBe(doc);
});
});
});
1 change: 1 addition & 0 deletions x-pack/plugins/graph/server/saved_objects/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ export const graphMigrations = {
doc.references = [];
return doc;
},
'8.0.0': (doc: SavedObjectUnsanitizedDoc<any>) => doc, // no-op, bump migration version to satisfy integration tests after adding convertToMultiNamespaceTypeVersion to graph_workspace SO
Copy link
Contributor

Choose a reason for hiding this comment

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

This bit shouldn't be necessary, and I don't think it will fix the integration tests.

Sorry I should have probably clarified, specifying convertToMultiNamespaceTypeVersion causes Core to add a special migration under the hood, so any Graph objects created will automatically have a migrationVersion of 8.0.0.
I think the problem in this case is the test data is actually malformed, it happened to work before but now it does not, so the test data needs to be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this locally and it did fix the test... I'll try to see what you mean by malformed data. Btw I based this PR on https://github.com/elastic/kibana/pull/110386/files, how come it is helpful there and not here?

Copy link
Contributor

@jportner jportner Sep 8, 2021

Choose a reason for hiding this comment

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

I tried this locally and it did fix the test... I'll try to see what you mean by malformed data.

Sorry, I got this PR for Graph confused with the other one for Lens #111403 (review)
So ignore what I said about malformed data!

Btw I based this PR on https://github.com/elastic/kibana/pull/110386/files, how come it is helpful there and not here?

That PR is for Alerting, which uses encrypted saved objects. They need a no-op migration function that will decrypt and re-encrypt the object (Step 5 of the Sharing Saved Objects dev guide). We had to do it that way because of the way encryption is handled in a plugin, not in Core.

Anyway, you adding a no-op migration here doesn't hurt anything, but it shouldn't be needed to pass CI. If it is needed, that might be indicative of a Core bug that I need to fix.
What exactly was the test failure?

Copy link
Contributor Author

@mbondyra mbondyra Sep 8, 2021

Choose a reason for hiding this comment

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

Here's the build failure: https://kibana-ci.elastic.co/job/elastic+kibana+pipeline-pull-request/151533/testReport/junit/Jest%20Integration%20Tests/src_core_server_saved_objects_migrationsv2_integration_tests/Kibana_Pipeline___general___migration_v2_migrating_from_the_same_Kibana_version_that_used_v1_migrations_migrates_the_documents_to_the_highest_version/

It's reproducible locally. Without my changes in migrations file the version for graph_workspace stays on the last explicit migration (7.11).

The actual version is equal 8.0.0 (correct) and the expectedVersion is wrong. That's because the expected one is read for all saved objects here: https://github.com/elastic/kibana/blob/master/src/core/server/saved_objects/migrationsv2/integration_tests/migration_from_v1.test.ts#L116 from type.migrations property.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh, okay, thanks for clarifying.
So yeah, I think in this case the core integration test needs to be changed, you shouldn't have to add this no-op to pass the test 😄

If you can wait a day or two, I'd be happy to add the Core changes and test them out locally. We can merge them in this PR if you're OK with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, it can wait till 8.0.0! 😀

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, it appears to be after working hours for you so I took the liberty of just pushing the changes to this branch to get CI started, I hope you don't mind 🙂

};