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

[data.search.aggs] Remove service getters from agg types #61069

Merged
merged 14 commits into from
Mar 27, 2020

Conversation

alexwizp
Copy link
Contributor

@alexwizp alexwizp commented Mar 24, 2020

Closes: #60333

Summary

When aggs were migrated to the new platform data.search service, each of the runtime dependencies in the individual agg types were retrieved using service getters/setters (e.g. getUiSettings or getFieldFormats in src/plugins/data/public/services)

Done for

  • search/aggs/buckets
  • search/aggs/metrics

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@alexwizp alexwizp added v7.7.0 v8.0.0 Feature:NP Migration Feature:Aggregations Aggregation infrastructure (AggConfig, esaggs, ...) Team:AppArch labels Mar 24, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@alexwizp alexwizp self-assigned this Mar 24, 2020
@alexwizp alexwizp added the release_note:skip Skip the PR/issue when compiling release notes label Mar 24, 2020
@elastic elastic deleted a comment from kibanamachine Mar 24, 2020
Comment on lines 80 to 87
getDateHistogramBucketAgg(deps),
getHistogramBucketAgg(deps),
rangeBucketAgg,
getDateRangeBucketAgg(deps),
ipRangeBucketAgg,
termsBucketAgg,
filterBucketAgg,
getFiltersBucketAgg(deps),
Copy link
Member

Choose a reason for hiding this comment

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

I think we should pass only the required dependencies to each agg type, rather than AggTypesDependencies, which includes all of core and all of the query service. (Similar to how getFiltersBucketAgg was previously implemented)

Each of these agg types only uses a tiny fraction of each of these services -- for the sake of maintainability I would much rather be explicit about which service dependencies an agg type actually has... that way we don't have to go opening up every single agg type file in the future if we want to find out what the dependencies are.

Another reason for doing this is that we are eventually going to need to support aggs on the server, which makes it even more important that we aren't coupling these to the public CoreSetup, as this is already going to be different from the server CoreSetup.

So my suggestion would be:

  • Only pass the required services into getAggTypes
  • Only pass the required services into each individual agg (this should be a subset of what's provided to getAggTypes

Comment on lines 69 to 72
export const createMockedAggTypesDependencies = (): AggTypesDependencies => ({
core: coreMock.createSetup(),
query: queryServiceMock.createSetupContract(),
});
Copy link
Member

Choose a reason for hiding this comment

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

If we go the route of only passing in the required deps as I described above, then we wouldn't need a test helper -- each individual agg could import only the mocks they need for their tests.

@@ -410,7 +403,6 @@ export const npStart = {
search: {
aggs: {
calculateAutoTimeExpression: sinon.fake(),
createAggConfigs: sinon.fake(),
Copy link
Member

Choose a reason for hiding this comment

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

good catch, this was my bad 😄

@lukeelmers lukeelmers added v7.8.0 and removed v7.7.0 labels Mar 24, 2020
@alexwizp
Copy link
Contributor Author

@elasticmachine merge upstream

@elastic elastic deleted a comment from kibanamachine Mar 26, 2020
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

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

@alexwizp alexwizp marked this pull request as ready for review March 26, 2020 19:46
@alexwizp alexwizp requested a review from a team as a code owner March 26, 2020 19:46
Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

LGTM! Tested and everything seems to be functioning as expected. Thanks @alexwizp!

Comment on lines +36 to +39
return new Promise((resolve, reject) => {
if (!this.vis.type || !this.vis.type.visConfig || !this.vis.type.visConfig.component) {
reject('Missing component for ReactVisType');
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: this might be more succinct:

const Component = this.vis.type?.visConfig?.component;
if (!Component) {
  reject('Missing component for ReactVisType');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lukeelmers Have not idea why but ?. is not working with karma tests =(

@alexwizp alexwizp merged commit 37c4fd4 into elastic:master Mar 27, 2020
alexwizp added a commit to alexwizp/kibana that referenced this pull request Mar 27, 2020
* [data.search.aggs] Remove service getters from agg types

Part of elastic#60333

* fix JEST

* fix karma:unit

* fix PR commnets

* fix PR comments

* try to fix ci

* fix CI

* fix karma:unit

Co-authored-by: Elastic Machine <[email protected]>
alexwizp added a commit that referenced this pull request Mar 27, 2020
…1582)

* [data.search.aggs] Remove service getters from agg types

Part of #60333

* fix JEST

* fix karma:unit

* fix PR commnets

* fix PR comments

* try to fix ci

* fix CI

* fix karma:unit

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Aggregations Aggregation infrastructure (AggConfig, esaggs, ...) Feature:NP Migration release_note:skip Skip the PR/issue when compiling release notes v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data.search.aggs] Remove service getters from agg types
4 participants