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

Adds an API for managing saved objects #11632

Merged
merged 27 commits into from
May 23, 2017

Conversation

tylersmalley
Copy link
Contributor

@tylersmalley tylersmalley commented May 5, 2017

API Overview

For brevity, I have simplified the cURL commands to exclude the necessary headers. You will need to include the following: -H "Content-Type: application/json" -H "kbn-xsrf: true". I would also suggest adding -i to confirm the response headers.

Create

Route: POST /api/saved_objects/{type}

cURL: curl -X POST -d '{ "attributes": { "title": "Test pattern" } }' http://localhost:5601/api/saved_objects/index-pattern

Response:

{
  "type":"index-pattern",
  "id":"AVwXs-2htCUMy4H_zXXl",
  "version":1,
  "attributes":{
    "title":"Test pattern"
  }
}

Read

Route: GET /api/saved_objects/{type}/{id}

cURL: curl "http://localhost:5601/api/saved_objects/index-pattern/AVwXs-2htCUMy4H_zXXl"

Response:

{
  "id":"AVwXs-2htCUMy4H_zXXl",
  "type":"index-pattern",
  "version":1,
  "attributes":{
    "title":"Test pattern"
  }
}

Update

Route: PUT /api/saved_objects/{type}/{id}

cURL: curl -X PUT -d '{ "version": 1, "attributes": { "title": "Updated title" } }' http://localhost:5601/api/saved_objects/index-pattern/AVwXs-2htCUMy4H_zXXl

Response:

{
  "id":"AVwXs-2htCUMy4H_zXXl",
  "type":"index-pattern",
  "version":2,
  "attributes":{
    "title":"Updated title"
  }
}

Delete

Route: DELETE /api/saved_objects/{type}/{id}

cURL: curl -X DELETE http://localhost:5601/api/saved_objects/index-pattern/AVwXs-2htCUMy4H_zXXl

Response: Boolean based on success. We return an error if the document can not be found.

Find

Route: GET /api/saved_objects/{type?}
Query parameters (optional):

  • per_page: defaults to 20
  • page: defaults to 1
  • type: The type in which to limit the results to
  • search: Query passed to simple_query_string
  • searchFields: Fields to search against
  • fields: Fields to return

cURL: curl "http://localhost:5601/api/saved_objects?fields=title&search=tyler"

Response:

{
  "data":[
    {
      "id":"b7aff090-346d-11e7-9d21-53e7c9e02e64",
      "type":"search",
      "version":1,
      "attributes": {
        "title":"s1"
      }
    }
  ],
  "total":1,
  "per_page":20,
  "page":1
}

@tylersmalley tylersmalley added the Team:Operations Team label for Operations Team label May 5, 2017
@simianhacker
Copy link
Member

As soon as this is in I will move #10858 over to it.

@tylersmalley tylersmalley force-pushed the saved-objects-api branch 3 times, most recently from 029aeab to 6d97a1c Compare May 15, 2017 05:44
@tylersmalley tylersmalley changed the title WIP: Adds an API for managing saved objects Adds an API for managing saved objects May 15, 2017
@tylersmalley tylersmalley force-pushed the saved-objects-api branch 3 times, most recently from 8150be5 to c96a91e Compare May 15, 2017 15:17
export { SavedObjectsClient } from './saved_objects_client';
export { SavedObjectRegistryProvider } from './saved_object_registry';
export { SavedObjectsClientProvider } from './saved_objects_client_provider';
export { RedirectWhenMissingProvider } from './redirect_when_missing_provider';
Copy link
Member

Choose a reason for hiding this comment

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

tests are failing on this,

 ERROR in ./src/ui/public/saved_objects/index.js
    Module not found: Error: Cannot resolve 'file' or 'directory' ./redirect_when_missing_provider in /var/lib/jenkins/workspace/elastic+kibana+pull-request+multijob-intake/src/ui/public/saved_objects
     @ ./src/ui/public/saved_objects/index.js 34:38-81


export const createCreateRoute = (prereqs) => {
return {
path: '/api/kibana/saved_objects/{type}/{id?}',
Copy link
Member

Choose a reason for hiding this comment

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

thoughts on removing kibana from the api route? with the goal of eventually opening this api up to all applications

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I like that.

}

delete() {
return this.cient.delete(this.type, this.id);
Copy link
Member

Choose a reason for hiding this comment

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

cient = client

@jbudz
Copy link
Member

jbudz commented May 15, 2017

This could replace the settings API.

@BigFunger BigFunger self-assigned this May 15, 2017
savedObjectsClient._request('GET', '/api/path', params).then(() => {
done('should have thrown');
}).catch(e => {
expect(e.message).to.eql('404 Response');
Copy link
Member

Choose a reason for hiding this comment

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

errors return the underlying query to the browser, thoughts on logging this instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought on eliminating exposing of the ES query entirely? Logging can be done by enabling elaticsearch.logQueries with --verbose. Logging things like 404's without verbose or an elevated log level seems a little noisy.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@jbudz
Copy link
Member

jbudz commented May 15, 2017

With types going away, thoughts on allowing saved_objects/{id?} too?

@tylersmalley
Copy link
Contributor Author

@jbudz, I am all for allowing direct id access to the API but we need to first resolve how we are going to handle the existing conflicts. During the transform, we either need to change the id to be a concatenation of the existing type and id or move everything to UUID's without losing the ability to pull up legacy share URL's

@tylersmalley
Copy link
Contributor Author

@jbudz, we're now handling version correctly. version is returned with the documents and if you pass version it will fail on a miss-match as expected.

@epixa
Copy link
Contributor

epixa commented May 16, 2017

I kind of like the type thing in the URL. Technically id will be unique across types and thus could be used without specifying a type, but what circumstance would that actually be what we want to do when dealing with these specific APIs? The only thing I can think of would be when doing a bulk export of all types or something, but we wouldn't be doing that through these particular APIs anyway.

Tyler Smalley added 7 commits May 16, 2017 09:02
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

This is breaking the functional tests somehow... LGTM once they are passing (and not taking an hour to run)

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
@tylersmalley tylersmalley merged commit d4be917 into elastic:master May 23, 2017
@tylersmalley tylersmalley deleted the saved-objects-api branch May 23, 2017 22:40
tylersmalley added a commit that referenced this pull request May 23, 2017
POST /api/saved_objects/{type}
GET /api/saved_objects/{type}/{id}
PUT /api/saved_objects/{type}/{id}
DELETE /api/saved_objects/{type}/{id}
GET /api/saved_objects/{type?}
@tylersmalley
Copy link
Contributor Author

5.x: d2500c3

@spalger
Copy link
Contributor

spalger commented May 24, 2017

🎉 🎉 🎉 🎉

@epixa
Copy link
Contributor

epixa commented May 24, 2017

Hell yeah!

expect(savedObjectsClient.find.calledOnce).to.be(true);

const options = savedObjectsClient.find.getCall(0).args[0];
expect(options).to.eql({ perPage: 20, page: 1, fields: 'title' });
Copy link
Contributor

Choose a reason for hiding this comment

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

sometimes I see fields and sometimes I see searchFields. Which one is correct? Or can both be used?

Copy link
Contributor Author

@tylersmalley tylersmalley May 30, 2017

Choose a reason for hiding this comment

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

You should use fields if you want to limit the response. For instance, if you are only interested in title, and description.

searchFields is used in conjunction with search. It allows you to define which fields to search against. Omitting searchFields will search against all fields. You can also define weights, like title^5: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html

snide pushed a commit to snide/kibana that referenced this pull request May 30, 2017
POST /api/saved_objects/{type}
GET /api/saved_objects/{type}/{id}
PUT /api/saved_objects/{type}/{id}
DELETE /api/saved_objects/{type}/{id}
GET /api/saved_objects/{type?}
@nh2
Copy link

nh2 commented Dec 5, 2017

I've written an export.json CLI importer tool for Kibana that uses this new API: https://github.com/nh2/kibana-importer

With this and the script from #3709 (comment), I can now deploy Kibana in a fully declarative fashion without having to load anything manually into it.

@sandstrom
Copy link

This issue is also relevant. If you would prefer a method for loading dashboards and indexpatterns from the file-system (for use with Chef, Puppet, Salt, etc) please vouch for it here:

#2310

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.