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

Remove data <--> expressions circular dependencies. #82685

Merged
merged 6 commits into from
Nov 9, 2020

Conversation

lukeelmers
Copy link
Member

@lukeelmers lukeelmers commented Nov 5, 2020

Closes #80510

As part of the work to migrate to TS project references in preparation for the new build toolchain, we needed to remove some circular dependencies that exist between the data and expressions plugins.

As explained in the original issue, there were a few areas that were causing problems:

data definitely needs the runtime dependency on expressions, so the question is what items from data is expressions using? Here's the list of what I could find:

  1. toPromise -- helper for AbortHandler
    • Used in the executor... I can't even find where it is used in data
  2. uniqFilters -- helper for deduping filters
    • Used in kibana_context
  3. Query Filter and TimeRange interfaces
    • Used in the ExpressionLoader's ExecutionContextSearch
    • Used in kibana_context

This PR addresses these issues by doing the following:

  1. Moves AbortSignal helpers toPromise, AbortError, and getCombinedSignal from data to kibana_utils, as these were used in multiple plugins.
    • Renames to abortSignalToPromise and getCombinedAbortSignal for clarity
  2. Moves kibana and kibana_context expression functions to the data plugin, and registers them from there instead.
  3. Also moves the kibana_context expression type to data.
  4. Updates the expression plugin's ExecutionContext to take an additional generic type parameter for ExecutionContextSearch, and defaults to SerializableState. Also updates a few places where this was used to pass in the correct param.
  5. Updates a few other places in expressions that used ExecutionContextSearch and replaced with SerializableState, as the search typings should really be determined by data anyway.
  6. Removes data from the expressions plugin's requiredBundles.

@lukeelmers lukeelmers added Feature:Search Querying infrastructure in Kibana Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Team:AppArch NeededFor:Core labels Nov 5, 2020
@lukeelmers lukeelmers self-assigned this Nov 5, 2020
* Takes a function spec and passes in default args,
* overriding with any provided args.
*/
export const functionWrapper = (spec: AnyExpressionFunctionDefinition) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was just copied from expressions. It's simple enough that doesn't feel worth exporting from there, especially as it is only a testing utility.

@@ -77,7 +81,7 @@ type StrategyMap = Record<string, ISearchStrategy<any, any>>;

/** @internal */
export interface SearchServiceSetupDependencies {
registerFunction: AggsSetupDependencies['registerFunction'];
expressions: ExpressionsServerSetup;
Copy link
Member Author

Choose a reason for hiding this comment

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

Updated setup dependencies for consistency with the public search service, and also as we need registerType from the expressions contract now.

export interface ExecutionContext<InspectorAdapters extends Adapters = Adapters> {
export interface ExecutionContext<
InspectorAdapters extends Adapters = Adapters,
ExecutionContextSearch extends SerializableState = SerializableState
Copy link
Member Author

Choose a reason for hiding this comment

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

I still called this ExecutionContextSearch, but at this point expressions only knows that it's something serializable. This means less type safety out of the box (unless you remember to pass the generic type param), however it helps us get rid of a circular type dependency and makes for clearer separation of concerns between the plugins.

@@ -59,7 +58,7 @@ export interface TimelionSuccessResponse {
sheet: Sheet[];
stats: Stats;
visType: string;
type: KIBANA_CONTEXT_NAME;
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the only place in Kibana this type was used, and you can derive it from KibanaContext already -- so rather than keeping it in the data plugin contract, I removed it and updated accordingly.

@@ -51,7 +47,7 @@ export type VegaExpressionFunctionDefinition = ExpressionFunctionDefinition<
Input,
Arguments,
Output,
ExecutionContext<VegaInspectorAdapters>
ExecutionContext<VegaInspectorAdapters, ExecutionContextSearch>
Copy link
Member Author

Choose a reason for hiding this comment

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

For plugins registering expression functions which rely on the search execution context and want to maintain the same level of type safety as we had previously, this is how they can go about achieving it.

For this PR I did not comb through every registered expression function to make this change; rather, I only looked for places where a specific ExecutionContext was already being included.

@lukeelmers lukeelmers added release_note:skip Skip the PR/issue when compiling release notes v7.11.0 v8.0.0 labels Nov 5, 2020
@lukeelmers lukeelmers force-pushed the fix/data-circular-deps branch 3 times, most recently from 5dc0bf1 to aa011ac Compare November 5, 2020 15:45
@lukeelmers
Copy link
Member Author

@elasticmachine merge upstream

@lukeelmers lukeelmers marked this pull request as ready for review November 5, 2020 23:44
@lukeelmers lukeelmers requested a review from a team as a code owner November 5, 2020 23:44
@lukeelmers lukeelmers requested a review from a team November 5, 2020 23:44
@lukeelmers lukeelmers requested review from a team as code owners November 5, 2020 23:44
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@patrykkopycinski patrykkopycinski left a comment

Choose a reason for hiding this comment

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

SIEM/Endpoint LGTM

Copy link
Contributor

@crob611 crob611 left a comment

Choose a reason for hiding this comment

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

Presentation changes are good 👍

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Kibana app changes LGTM, code review only.

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

LGTM in terms of moving things like AbortError, 'toPromiseand such. However I would appreciate someone more involved inexpressionsconfirming that it makes sense to move thekibanaandkibana_contextfunctions into thedata` plugin.

@lukeelmers
Copy link
Member Author

lukeelmers commented Nov 6, 2020

I would appreciate someone more involved in expressions confirming that it makes sense to move the kibana and kibana_context functions into the data plugin.

@ppisljar and I discussed kibana_context based on the ideas I outlined in the original issue & agreed it makes sense for it to live in data, because it's loading saved searches, and also parsing query, filter, and timerange. We did not discuss kibana specifically, however it is virtually the same as kibana_context in that it's providing the query/filter/timerange as inputs to each expression. (It wouldn't really make sense to move one without the other)

@lukeelmers
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
data 584 587 +3
expressions 106 103 -3
kibanaUtils 190 191 +1
total +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
kibanaUtils 123.2KB 123.2KB +1.0B
lens 1.0MB 1.0MB +32.0B
securitySolution 7.8MB 7.8MB +731.0B
total +764.0B

Distributable file count

id before after diff
default 42767 42768 +1
oss 22452 22453 +1

Page load bundle

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

id before after diff
data 955.3KB 962.6KB +7.3KB
dataEnhanced 28.0KB 28.3KB +309.0B
expressions 188.8KB 181.4KB -7.4KB
kibanaUtils 148.0KB 150.2KB +2.3KB
securitySolution 243.3KB 243.6KB +238.0B
total +2.7KB

History

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

@lukeelmers lukeelmers merged commit c6afc47 into elastic:master Nov 9, 2020
@lukeelmers lukeelmers deleted the fix/data-circular-deps branch November 9, 2020 20:01
lukeelmers added a commit to lukeelmers/kibana that referenced this pull request Nov 9, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 10, 2020
* master: (39 commits)
  Fix ilm navigation (elastic#81664)
  [Lens] Distinct icons for XY and pie chart value labels toolbar (elastic#82927)
  [data.search.aggs] Throw an error when trying to create an agg type that doesn't exist. (elastic#81509)
  Index patterns api - load field list on server (elastic#82629)
  New events resolver (elastic#82170)
  [App Search] Misc naming tech debt (elastic#82770)
  load empty_kibana in test to have clean starting point (elastic#82772)
  Remove data <--> expressions circular dependencies. (elastic#82685)
  Update 8.0 breaking change template to gather information on how to programmatically detect it. (elastic#82905)
  Add alerting as codeowners to related documentation folder (elastic#82777)
  Add captions to user and space grid pages (elastic#82713)
  add alternate path for x-pack/Cloud test for Lens (elastic#82634)
  Uses asCurrentUser in getClusterUuid (elastic#82908)
  [Alerting][Connectors] Add new executor subaction to get 3rd party case fields (elastic#82519)
  Fix test import objects (elastic#82767)
  [ML] Add option for anomaly charts for metric detector should plot min, mean or max as appropriate (elastic#81662)
  Update alert type selection layout to rows instead of grid (elastic#73665)
  Prevent Kerberos and PKI providers from initiating a new session for unauthenticated XHR/API requests. (elastic#82817)
  Update grunt and related packages (elastic#79327)
  Allow the repository to search across all namespaces (elastic#82863)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Feature:Search Querying infrastructure in Kibana NeededFor:Core release_note:skip Skip the PR/issue when compiling release notes v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove circular dependency between data & expressions plugins
7 participants