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

[SAVED_OBJECTS] [AGGS] Step I to add aggregations in the find of saved objects #64002

Closed
wants to merge 38 commits into from

Conversation

XavierM
Copy link
Contributor

@XavierM XavierM commented Apr 20, 2020

Summary

This is a baby step to add aggregations in the find of saved objects, as we know find is a get, therefore, there is some limitation. I am hoping that I will be able to create a later PR to remove some limitations of this PR by having a post for find.

Anyway, the idea in this PR is that engineers who will need to add new aggregation types in src/core/server/saved_objects/service/lib/saved_object_aggs_types/*. I am using io-ts to validate the schema since io-ts allow recursive type and aggregations are recursive like the doc can show.

Dev Docs

SavedObjectsClient.find now supports aggregations, with the caveat that your field from the aggregation will have the attribute from your type saved object, it should look like this: savedObjectType.attributes.field. However, If you use a direct attribute of a saved object like updatedAt, you will have to define your filter like this: savedObjectType.updatedAt.

savedObjectsClient.find({
      type: 'savedObjectType',
      sortField: '@timestamp',
      sortOrder: 'desc',
      search: '',
      searchFields:'',
      fields: ['id', 'name', '@created', '@timestamp'],
      aggs: '{"aggName":{"aggType":{"field":"savedObjectType.attributes.field"}}}',
    });

Checklist

For maintainers

@XavierM XavierM added Feature:Saved Objects review Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc labels Apr 20, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

Some architectural questions:

@jinmu03 jinmu03 mentioned this pull request Apr 21, 2020
15 tasks
Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

I think the io-ts types are "scalable" enough to be able to construct a whitelist for excluding aggregation scripts.

However, we need a scalable solution to prevent aggregations on invalid fields (fields from other saved object types). So I think the next step should be to add the adjacency matrix bucket aggregation and find a way to prevent invalid aggregation fields that wouldn't result in a lot of complexity once we cover the entire aggregation API surface. We can use the alternative aggregation syntax #64002 (comment)

src/core/server/saved_objects/service/lib/repository.ts Outdated Show resolved Hide resolved
src/core/server/saved_objects/service/lib/aggs_utils.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

Along with the feedback in #64137 I'm happy with this approach 👍

@XavierM XavierM requested a review from a team as a code owner April 27, 2020 16:29
Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

Left some initial comments but will take a deeper look later

src/core/server/saved_objects/types.ts Outdated Show resolved Hide resolved
docs/api/saved-objects/find.asciidoc Outdated Show resolved Hide resolved
src/core/server/saved_objects/service/lib/repository.ts Outdated Show resolved Hide resolved
test/api_integration/apis/index.js Outdated Show resolved Hide resolved
test/api_integration/apis/saved_objects/index.js Outdated Show resolved Hide resolved
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Distributable file count

id before after diff
default 43025 43030 +5
oss 22550 22753 +203

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
core 547.9KB 548.0KB +93.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

We are getting very close! Got a few questions (most significant one being #64002 (comment)) and some NITs:

src/core/server/saved_objects/routes/find.ts Show resolved Hide resolved
src/core/server/saved_objects/types.ts Show resolved Hide resolved
console.log('body', JSON.stringify(resp.body));
expect(resp.body).to.eql({
error: 'Bad Request',
message: 'This type dashboard is not allowed: Bad Request',
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: slightly misleading message. I would rather have something like cannot perform aggregation on dashboard type as it was not included in the search or something if possible.

@LeeDr
Copy link

LeeDr commented Jan 7, 2021

Since we're past 7.11.0 FF, and this isn't a bug fix, should probably bump to 7.12.0.

@pgayvallet
Copy link
Contributor

Thanks @XavierM for this amazing work. I took the liberty to fork your PR to finish the last remaining bits.

Closing in favor of #96292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Saved Objects release_note:enhancement review Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants