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 metric_vis_renderer #57694

Merged
merged 5 commits into from
Aug 20, 2020
Merged

adds metric_vis_renderer #57694

merged 5 commits into from
Aug 20, 2020

Conversation

ppisljar
Copy link
Member

@ppisljar ppisljar commented Feb 14, 2020

Summary

adds renderer for metric_vis (so it doesn't need to use visualization renderer anymore)

  • VisualizationContainer component was added to visualizations plugin which should be used to wrap any visualization.
  • visualizations should use VisualizationNoResults component when it wants to show a no-result message
  • metric vis toAST() function to produce expression out of vis configuration

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@ppisljar ppisljar added release_note:skip Skip the PR/issue when compiling release notes v8.0.0 labels Feb 14, 2020
@ppisljar ppisljar requested a review from a team as a code owner February 14, 2020 15:54
@elasticmachine
Copy link
Contributor

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

@ppisljar ppisljar changed the title [PoC] adds metric_vis_renderer adds metric_vis_renderer Feb 15, 2020
@ppisljar ppisljar changed the title adds metric_vis_renderer [PoC] adds metric_vis_renderer Feb 15, 2020
@lukeelmers
Copy link
Member

lukeelmers commented Mar 5, 2020

Finally got around to looking through this....

we could provide utility functions to make it easier for visualizations to implement the above behavior in consistent way.

error handling could be moved to render() function on expression service.

I think these ideas make the most sense for the unanswered items. One thing I'm not sure about is how/if to deal with non-React scenarios. We could provide helpers or HOCs to decorate React components, but that doesn't help folks using other rendering technologies.

I wonder if there'd be a way to consolidate all of this into some sort of render function wrapper -- where you could give us your visData/visConfig, domNode, and render function, and we conditionally render it based on the status.

visualizationRenderWrapper(
  domNode: HTMLElement;
  config: { visData, visConfig };
  renderFn: (domNode) => render(<MyApp />, domNode);
);

Then in visualizationRenderWrapper:

  • we call the provided render fn if everything seems to be okay
  • if there's an error/no-data/loading situation, we could skip calling the fn and hijack the domNode to render our own thing into it instead.
  • we could also potentially add the visualization class to the domNode itself, and then pass it back to the provided render function.

This is mostly a brain dump - I haven't thought too much about the details on this, so there's likely something I'm overlooking.

Edit: Come to think of it, I'm not sure the wrapper idea works entirely. Because we don't always know the shape of the data that a given visualization function provides to a renderer. hmm

@spalger spalger added v7.7.1 and removed v7.7.0 labels May 14, 2020
@lukeelmers lukeelmers added the WIP Work in progress label Jul 7, 2020
@ppisljar ppisljar added v7.11.0 and removed v7.7.1 labels Jul 21, 2020
@ppisljar ppisljar requested a review from a team July 29, 2020 14:04
@ppisljar ppisljar removed the WIP Work in progress label Jul 29, 2020
@ppisljar ppisljar changed the title [PoC] adds metric_vis_renderer adds metric_vis_renderer Jul 30, 2020
@ppisljar
Copy link
Member Author

@elasticmachine merge upstream

@streamich streamich mentioned this pull request Aug 11, 2020
13 tasks
@ppisljar ppisljar force-pushed the metricRenderer branch 4 times, most recently from 745b52d to 035cf70 Compare August 13, 2020 09:22
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.

Wondering if as a part of this we should also be adding a toExpression function on the metric vis and removing the metric vis function from build_pipeline? That would help validate that this works and demonstrate the whole workflow for creating a vis.

Edit: Also I just realized that build_pipeline is calling toExpression whereas the vis object has toAST defined... I'm guessing that's a bug we hadn't noticed yet?

@@ -54,7 +54,7 @@ export class BaseVisType {
stage: 'experimental' | 'beta' | 'production';
isExperimental: boolean;
options: Record<string, any>;
visualization: VisualizationControllerConstructor;
visualization: VisualizationControllerConstructor | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

nit: Maybe you could do visualization?: VisualizationControllerConstructor; instead of adding undefined?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah i tried that, but it gets into some ts errors so i went with this

src/plugins/vis_type_metric/public/metric_vis_renderer.tsx Outdated Show resolved Hide resolved
@ppisljar
Copy link
Member Author

@elasticmachine merge upstream

@botelastic botelastic bot added the Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) label Aug 17, 2020
@ppisljar
Copy link
Member Author

@elasticmachine merge upstream

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.

This LGTM now, added a few final comments which are mostly nits.

// request handler
if (vis.type.requestHandler === 'courier') {
pipeline += `esaggs
if (vis.type.toAST) {
Copy link
Member

Choose a reason for hiding this comment

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

I always forget what naming convention we decided on for these. toAST? toExpression? toExpressionAst?

I think it's all over the place now, but might be good to choose something we are okay with applying everywhere before all of the vis renderers get written.

Copy link
Member Author

@ppisljar ppisljar Aug 19, 2020

Choose a reason for hiding this comment

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

i agree, you are using toExpressionAst ?

Copy link
Member

Choose a reason for hiding this comment

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

aggs are using toExpressionAst

src/plugins/vis_type_metric/public/to_ast.ts Outdated Show resolved Hide resolved
src/plugins/vis_type_metric/public/to_ast.ts Outdated Show resolved Hide resolved
}

// @ts-ignore
const metricVis = buildExpressionFunction<MetricVisExpressionFunctionDefinition>('metricVis', {
Copy link
Member

Choose a reason for hiding this comment

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

curious, what does TS not like about the usage with buildExpressionFunction here? wondering if it's something fixable in the function builder

Copy link
Member Author

Choose a reason for hiding this comment

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

we need to cleanup the types i think, we need a separation between argumnent types (arguments user is providing) and argument types (arguments as received inside fn function .... with defaults injected) which we currently don't have.

Copy link
Member

Choose a reason for hiding this comment

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

ah, yeah so right now this is a tradeoff between losing type safety when using the expression builder, or having a worse DX when writing the expression function.

you wouldn't need to ignore this if the typings for metric_vis_fn args reflected the actual function definition configuration (that is, args which are optional are typed as optional, args which are required are typed as required).

in that case this would work, but it would mean inside the function implementation itself you would need to assert that you know something exists:

colorRange: args.colorRange!,
percentageMode: args.percentageMode!,
...etc

i think there are a couple ways to solve this which we could discuss -- for now i've pushed an update to this PR to switch out the ts-ignore with ts-expect-error so that we remember to remove it later when we fix this

src/plugins/vis_type_metric/public/to_ast.ts Outdated Show resolved Hide resolved
src/plugins/vis_type_metric/public/metric_vis_renderer.tsx Outdated Show resolved Hide resolved
@ppisljar ppisljar force-pushed the metricRenderer branch 2 times, most recently from 679240c to f907fb5 Compare August 19, 2020 07:42
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. We should sort out the issue with expression definition typings and how they are used in the function builder, but can discuss that separately as it's orthogonal to this effort.

@ppisljar
Copy link
Member Author

@elasticmachine merge upstream

@ppisljar
Copy link
Member Author

@elasticmachine merge upstream

@ppisljar
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
visTypeMetric 260 +2 258
visualizations 135 +1 134
total +3

page load bundle size

id value diff baseline
expressions 348.9KB +65.0B 348.9KB
visTypeMetric 581.1KB +4.8KB 576.3KB
visualizations 408.5KB -541.0B 409.0KB
total +4.3KB

History

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

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Tested locally on Chrome, for a quick sanity check of the functionality of metric vis.
Kibana App code LGTM!

@ppisljar ppisljar merged commit 28df926 into elastic:master Aug 20, 2020
ppisljar added a commit to ppisljar/kibana that referenced this pull request Aug 20, 2020
ppisljar added a commit that referenced this pull request Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) 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.

6 participants