Skip to content

Commit

Permalink
Initial client-side support for sharing saved-objects phase 1.5 (#69399)
Browse files Browse the repository at this point in the history
  • Loading branch information
jportner authored Aug 19, 2020
1 parent d17201f commit f3e0687
Show file tree
Hide file tree
Showing 168 changed files with 6,881 additions and 1,864 deletions.
7 changes: 6 additions & 1 deletion docs/api/saved-objects/find.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ experimental[] Retrieve a paginated set of {kib} saved objects by various condit
(Optional, array|string) The fields to return in the `attributes` key of the response.

`sort_field`::
(Optional, string) The field that sorts the response.
(Optional, string) The field that sorts the response. There are two kinds of fields: "root" fields that exist for all saved objects (such
as "updated_at"), and "type" fields that are specific to a given object type (e.g. those fields that are returned in the `attributes` key
of the response).
* If a single type is defined in the `type` parameter, both "type" fields and "root" fields are allowed, and validity checks are made in
that order.
* If multiple types are defined in the `type` parameter, only "root" fields are allowed.

`has_reference`::
(Optional, object) Filters to objects that have a relationship with the type and ID combination.
Expand Down
94 changes: 80 additions & 14 deletions docs/api/saved-objects/import.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ The request body must include the multipart/form-data type.

`errors`::
(array) Indicates the import was unsuccessful and specifies the objects that failed to import.
+
NOTE: One object may result in multiple errors which require separate steps to resolve (for instance, a `missing_references` error and a
`conflict` error).

`successResults`::
(array) Indicates the objects that were imported successfully, with any metadata if applicable.
+
NOTE: No objects are actually created until all resolvable errors have been addressed! This includes conflict errors and missing references
errors. See the <<saved-objects-api-resolve-import-errors,Resolve import errors API>> documentation for more information.
errors. See the examples below for how to resolve these errors.

[[saved-objects-api-import-codes]]
==== Response code
Expand Down Expand Up @@ -100,12 +103,20 @@ The API returns the following:
{
"id": "my-pattern",
"type": "index-pattern",
"destinationId": "4aba3770-0d04-45e1-9e34-4cf0fd2165ae"
"destinationId": "4aba3770-0d04-45e1-9e34-4cf0fd2165ae",
"meta": {
"icon": "indexPatternApp",
"title": "my-pattern-*"
}
},
{
"id": "my-dashboard",
"type": "dashboard",
"destinationId": "c31d1eca-9bc0-4a81-b5f9-30c442824c48"
"destinationId": "c31d1eca-9bc0-4a81-b5f9-30c442824c48",
"meta": {
"icon": "dashboardApp",
"title": "Look at my dashboard"
}
}
]
}
Expand Down Expand Up @@ -143,11 +154,19 @@ The API returns the following:
"successResults": [
{
"id": "my-pattern",
"type": "index-pattern"
"type": "index-pattern",
"meta": {
"icon": "indexPatternApp",
"title": "my-pattern-*"
}
},
{
"id": "my-dashboard",
"type": "dashboard"
"type": "dashboard",
"meta": {
"icon": "dashboardApp",
"title": "Look at my dashboard"
}
}
]
}
Expand Down Expand Up @@ -190,6 +209,10 @@ The API returns the following:
"title": "my-pattern-*",
"error": {
"type": "conflict"
},
"meta": {
"icon": "indexPatternApp",
"title": "my-pattern-*"
}
},
{
Expand All @@ -199,6 +222,10 @@ The API returns the following:
"error": {
"type": "conflict",
"destinationId": "another-vis"
},
"meta": {
"icon": "visualizeApp",
"title": "Look at my visualization"
}
},
{
Expand All @@ -219,13 +246,21 @@ The API returns the following:
"updatedAt": "2020-07-05T12:29:54.849Z"
}
]
},
"meta": {
"icon": "canvasApp",
"title": "Look at my canvas"
}
}
],
"successResults": [
{
"id": "my-dashboard",
"type": "dashboard"
"type": "dashboard",
"meta": {
"icon": "dashboardApp",
"title": "Look at my dashboard"
}
}
]
}
Expand Down Expand Up @@ -267,15 +302,17 @@ The `file.ndjson` file contains the following:
[source,sh]
--------------------------------------------------
{"type":"visualization","id":"my-vis","attributes":{"title":"Look at my visualization"},"references":[{"name":"ref_0","type":"index-pattern","id":"my-pattern-*"}]}
{"type":"dashboard","id":"my-dashboard","attributes":{"title":"Look at my dashboard"},"references":[{"name":"ref_0","type":"visualization","id":"my-vis"}]}
{"type":"search","id":"my-search","attributes":{"title":"Look at my search"},"references":[{"name":"ref_0","type":"index-pattern","id":"another-pattern-*"}]}
{"type":"dashboard","id":"my-dashboard","attributes":{"title":"Look at my dashboard"},"references":[{"name":"ref_0","type":"visualization","id":"my-vis"},{"name":"ref_1","type":"search","id":"my-search"}]}
--------------------------------------------------

The API returns the following:

[source,sh]
--------------------------------------------------
{
"success": false,
"successCount": 0,
"successCount": 1,
"errors": [
{
"id": "my-vis",
Expand All @@ -288,17 +325,46 @@ The API returns the following:
"type": "index-pattern",
"id": "my-pattern-*"
}
],
"blocking": [
]
},
"meta": {
"icon": "visualizeApp",
"title": "Look at my visualization"
}
},
{
"id": "my-search",
"type": "search",
"title": "Look at my search",
"error": {
"type": "missing_references",
"references": [
{
"type": "dashboard",
"id": "my-dashboard"
"type": "index-pattern",
"id": "another-pattern-*"
}
]
},
"meta": {
"icon": "searchApp",
"title": "Look at my search"
}
}
],
"successResults": [
{
"id": "my-dashboard",
"type": "dashboard",
"meta": {
"icon": "dashboardApp",
"title": "Look at my dashboard"
}
}
]
}
--------------------------------------------------

This result indicates that the import was not successful because the visualization resulted in a missing references error. No objects will
be imported until this error is resolved using the <<saved-objects-api-resolve-import-errors-example-2,Resolve import errors API>>.
This result indicates that the import was not successful because the visualization and search each resulted in a missing references error.

No objects will be imported until these errors are resolved using the <<saved-objects-api-resolve-import-errors-example-2,Resolve import
errors API>>.
63 changes: 51 additions & 12 deletions docs/api/saved-objects/resolve_import_errors.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ The request body must include the multipart/form-data type.
(Optional, string) Specifies which destination ID the imported object should have (if different from the current ID).
`replaceReferences`:::
(Optional, array) A list of `type`, `from`, and `to` used to change the object references.
`ignoreMissingReferences`:::
(Optional, boolean) When set to `true`, any missing references errors are ignored. When set to `false`, this does nothing.
=====

[[saved-objects-api-resolve-import-errors-response-body]]
Expand All @@ -73,6 +75,9 @@ The request body must include the multipart/form-data type.

`errors`::
(Optional, array) Specifies the objects that failed to resolve.
+
NOTE: One object may result in multiple errors which require separate steps to resolve (for instance, a `missing_references` error and a
`conflict` error).

`successResults`::
(Optional, array) Indicates the objects that were imported successfully, with any metadata if applicable.
Expand Down Expand Up @@ -122,21 +127,37 @@ The API returns the following:
"successResults": [
{
"id": "my-pattern",
"type": "index-pattern"
"type": "index-pattern",
"meta": {
"icon": "indexPatternApp",
"title": "my-pattern-*"
}
},
{
"id": "my-vis",
"type": "visualization",
"destinationId": "another-vis"
"destinationId": "another-vis",
"meta": {
"icon": "visualizeApp",
"title": "Look at my visualization"
}
},
{
"id": "my-canvas",
"type": "canvas-workpad",
"destinationId": "yet-another-canvas"
"destinationId": "yet-another-canvas",
"meta": {
"icon": "canvasApp",
"title": "Look at my canvas"
}
},
{
"id": "my-dashboard",
"type": "dashboard"
"type": "dashboard",
"meta": {
"icon": "dashboardApp",
"title": "Look at my dashboard"
}
}
]
}
Expand All @@ -152,11 +173,12 @@ that were returned in the `successResults` array. In this example, we retried im

This example builds upon the <<saved-objects-api-import-example-4,Import objects API example with missing reference errors>>.

Resolve a missing reference error for a visualization by replacing the index pattern with another:
Resolve a missing reference error for a visualization by replacing the index pattern with another, and resolve a missing reference error for
a search by ignoring it:

[source,sh]
--------------------------------------------------
$ curl -X POST api/saved_objects/_resolve_import_errors -H "kbn-xsrf: true" --form [email protected] --form retries='[{"type":"visualization","id":"my-vis","replaceReferences":[{"type":"index-pattern","from":"my-pattern-*","to":"existing-pattern"}]},{"type":"dashboard","id":"my-dashboard"}]'
$ curl -X POST api/saved_objects/_resolve_import_errors -H "kbn-xsrf: true" --form [email protected] --form retries='[{"type":"visualization","id":"my-vis","replaceReferences":[{"type":"index-pattern","from":"my-pattern-*","to":"existing-pattern"}]},{"type":"search","id":"my-search","ignoreMissingReferences":true},{"type":"dashboard","id":"my-dashboard"}]'
--------------------------------------------------
// KIBANA

Expand All @@ -165,6 +187,7 @@ The `file.ndjson` file contains the following:
[source,sh]
--------------------------------------------------
{"type":"visualization","id":"my-vis","attributes":{"title":"Look at my visualization"},"references":[{"name":"ref_0","type":"index-pattern","id":"my-pattern-*"}]}
{"type":"search","id":"my-search","attributes":{"title":"Look at my search"},"references":[{"name":"ref_0","type":"index-pattern","id":"another-pattern-*"}]}
{"type":"dashboard","id":"my-dashboard","attributes":{"title":"Look at my dashboard"},"references":[{"name":"ref_0","type":"visualization","id":"my-vis"}]}
--------------------------------------------------

Expand All @@ -174,21 +197,37 @@ The API returns the following:
--------------------------------------------------
{
"success": true,
"successCount": 2,
"successCount": 3,
"successResults": [
{
"id": "my-pattern",
"type": "index-pattern"
"id": "my-vis",
"type": "visualization",
"meta": {
"icon": "visualizeApp",
"title": "Look at my visualization"
}
},
{
"id": "my-search",
"type": "search",
"meta": {
"icon": "searchApp",
"title": "Look at my search"
}
},
{
"id": "my-dashboard",
"type": "dashboard"
"type": "dashboard",
"meta": {
"icon": "dashboardApp",
"title": "Look at my dashboard"
}
}
]
}
--------------------------------------------------

This result indicates that the import was successful, and both objects were created.
This result indicates that the import was successful, and all three objects were created.

TIP: If a prior import attempt resulted in resolvable errors, you must include a retry for each object you want to import, including any
that were described in the missing error object's `blocked` array. In this example, we retried importing the dashboard accordingly.
that were returned in the `successResults` array. In this example, we retried importing the dashboard accordingly.
Loading

0 comments on commit f3e0687

Please sign in to comment.