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

Move Lens attribute builder to a package #163422

Merged

Conversation

crespocarlos
Copy link
Contributor

@crespocarlos crespocarlos commented Aug 8, 2023

closes #163491

Summary

This PR creates a new package that contains a utility API that helps to generate the JSON with the attributes required to render a Lens chart with the EmbeddableComponent.

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@crespocarlos crespocarlos force-pushed the move-attribute-builder-to-package branch from 911a950 to a6c664b Compare August 8, 2023 15:00
@crespocarlos crespocarlos added Team:Visualizations Visualization editors, elastic-charts and infrastructure Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting v8.10.0 Feature:Lens labels Aug 9, 2023
@crespocarlos
Copy link
Contributor Author

@elasticmachine merge upstream

@crespocarlos crespocarlos marked this pull request as ready for review August 9, 2023 13:33
@crespocarlos crespocarlos requested a review from a team as a code owner August 9, 2023 13:33
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations @elastic/kibana-visualizations-external (Team:Visualizations)

@elasticmachine
Copy link
Contributor

Pinging @elastic/infra-monitoring-ui (Team:Infra Monitoring UI)

@crespocarlos crespocarlos requested review from a team and dgieselaar August 9, 2023 13:33
@crespocarlos crespocarlos marked this pull request as draft August 9, 2023 13:34
@crespocarlos crespocarlos marked this pull request as ready for review August 9, 2023 13:42
Copy link
Member

@dgieselaar dgieselaar left a comment

Choose a reason for hiding this comment

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

Thanks a ton!

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

Had a quick look at the API described in the Readme.md for both chart and attributes builder, and I was wondering whether it make sense to move the formulaAPI to the main level, instead of the layer level:

const metricChart = new MetricChart({
  layers: new MetricLayer({
    data: {
      label: 'Disk Read Throughput',
      value: "counter_rate(max(system.diskio.read.count), kql='system.diskio.read.count: *')",
      format: {
        id: 'bytes',
        params: {
          decimals: 1,
        },
      },
    },
  }),
  formulaAPI,
  dataView,
});

or

const builder = new LensAttributesBuilder({
  visualization: new MetricChart({
    layers: new MetricLayer({
      data: {
        label: 'Disk Read Throughput',
        value: "counter_rate(max(system.diskio.read.count), kql='system.diskio.read.count: *')",
        format: {
          id: 'bytes',
          params: {
            decimals: 1,
          },
        },
      },
    }),
    dataView,
  }),
  formulaAPI,
});

const lensAttributes = builder.build();

<EmbeddableComponent
  attributes={lensAttributes}
  viewMode={ViewMode.VIEW}
  ...
/>

that would make the layer API a little bit less verbose and handles the "formula" complexity internally without have the consumer to think about what type of column it has passed and which dependency it might require.

@jennypavlova jennypavlova self-requested a review August 10, 2023 15:32
Copy link
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

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

LGTM 💯 (Infra changes)

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

I would propose few changes here before proceed.
Not too many, and I've already a branch with all of them implemented as reference if helpful:

  • Add a note at the beginning of the README to make it clear that it's still a work in progress and only XY and Metric charts are (partially) covered.
  • for any *Layer configuration object I would add a type prop, which contains the type of dimension operation. Currently it will only accept "formula".
  • Make the default date_histogram for XY become optional and add a new buckets property to the XYLayerOptions type which will support all 4 bucketed column types in Lens.
    • the XY layer series color wasn't working for me, but it should
    • the Metric series color wasn't working for me, but I think it should and backgroundColor could be removed instead
    • the FormulaConfig['format'] property should not be mandatory

--- end of required changes ---

Some nice to have (but not blocking changes):

  • each layer can have a dataView prop to override the "chart" one
  • both buckets and breakdown configurations could accept (optional) params as defined by its respective Lens column definition (useful to tweak some configuration) and getHistogramColumn and getTopValuesColumn should handle that.
  • not sure why line has been chosen as default XY series type (in Lens is the bar_stacked) here. Is there a strong argument to change it?
  • why the LensAttributesBuilder accepts an object with only a single visualization prop in it? Is it designed to support more arguments there?

I've implemented 90% of both lists in this branch already if you want to use as reference: https://github.com/crespocarlos/kibana/compare/move-attribute-builder-to-package...dej611:kibana:review/163422?expand=1
I've tested this PR against the Lens embeddable example and with these changes it could replace most of custom code there.

@crespocarlos
Copy link
Contributor Author

Thanks for your review @dej611 and for the changes made in your branch - it will save a lot of time

  • Add a note at the beginning of the README to make it clear that it's still a work in progress and only XY and Metric charts are (partially) covered.

OK!

  • for any *Layer configuration object I would add a type prop, which contains the type of dimension operation. Currently it will only accept "formula".

Could you please elaborate? Can a layer be anything other than a formula?

  • Make the default date_histogram for XY become optional and add a new buckets property to the XYLayerOptions type which will support all 4 bucketed column types in Lens.

    • the Metric series color wasn't working for me, but I think it should and backgroundColor could be removed instead
    • the FormulaConfig['format'] property should not be mandatory

Will check the above.

--- end of required changes ---

  • each layer can have a dataView prop to override the "chart" one
  • both buckets and breakdown configurations could accept (optional) params as defined by its respective Lens column definition (useful to tweak some configuration) and getHistogramColumn and getTopValuesColumn should handle that.

Should we concern about number of available configuration options that params provides?

  • not sure why line has been chosen as default XY series type (in Lens is the bar_stacked) here. Is there a strong argument to change it?

That's because it's what we're using in infra-ui. No strong reasons.

  • why the LensAttributesBuilder accepts an object with only a single visualization prop in it? Is it designed to support more arguments there?

I had other ideas of parameters for the LensAttributesBuilder. It ended up being a single prop. It can be changed.

@dej611
Copy link
Contributor

dej611 commented Aug 11, 2023

  • for any *Layer configuration object I would add a type prop, which contains the type of dimension operation. Currently it will only accept "formula".

Could you please elaborate? Can a layer be anything other than a formula?

It can, but in the current implementation only Formula metrics are supported. Adding a tagged prop type: 'formula' to it will make it easier to extend it to support for other operations, like other Quick function such Count, Unique count, Last value, etc... in the future without breaking existing configurations.

To be clear I'm talking about this:

new MetricLayer({
    data: {
      type: 'formula', // <= this tagged property here
      label: 'Disk Read Throughput',
      value: "counter_rate(max(system.diskio.read.count), kql='system.diskio.read.count: *')",
      format: {
        id: 'bytes',
        params: {
          decimals: 1,
        },
      },
    },
  }),

why the LensAttributesBuilder accepts an object with only a single visualization prop in it? Is it designed to support more arguments there?

I had other ideas of parameters for the LensAttributesBuilder. It ended up being a single prop. It can be changed.

I'm not necessarily against that, instead quite open to ideas here.

Both buckets and breakdown configurations could accept (optional) params as defined by its respective Lens column definition (useful to tweak some configuration) and getHistogramColumn and getTopValuesColumn should handle that.

Should we concern about number of available configuration options that params provides?

I would say no as usually the params object contains dedicated configuration options for the column definition rather than implementation/private one. I think let the user have full control of that at will can be quite powerful. Perhaps we could gather some feedback in v.1 here and decide for something else for v.2 .

@dgieselaar
Copy link
Member

@crespocarlos @dej611 My 2 cents: let's keep it opinionated. If Marco doesn't feel comfortable with this API we can also clearly mark it as an infra/Observability thing. I think we should specifically avoid making this generic, it defeats the purpose.

@crespocarlos crespocarlos requested a review from dej611 August 11, 2023 20:29
@stratoula
Copy link
Contributor

As this is important to be merged today as it is blocking other PR to be merged before the FF let's do the following and merge:

  • dont make the changes that Marco proposes
  • move the ownership to infra/Observability
  • make it explicit in the Readme that this is only used for infra/Observability

We are going to work on our own generic api in a next minor

@crespocarlos
Copy link
Contributor Author

@crespocarlos @dej611 My 2 cents: let's keep it opinionated. If Marco doesn't feel comfortable with this API we can also clearly mark it as an infra/Observability thing. I think we should specifically avoid making this generic, it defeats the purpose.

Agree with it being somewhat opinionated. There are many different parameters that can be used and I would be ok with the API making some decisions. It does still leave the door open for customizations.

As this is important to be merged today as it is blocking other PR to be merged before the FF let's do the following and merge:

I have already implemented the changes. The only thing that needs to be reverted is the example app. I'll update the readme.

@crespocarlos
Copy link
Contributor Author

@stratoula, qq:

We are going to work on our own generic API in a next minor

Is it possible that when your solution is done, it can replace this one? In the end, I think it's beneficial that we all use a single solution to solve this problem.

@stratoula
Copy link
Contributor

@crespocarlos this is the goal yes! We are just not sure at this point if the same api can be used, we might create a new one (at the same package), move the ownership to us, and change the consumers of the existing api to use the new one.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
infra 1391 1393 +2

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/lens-embeddable-utils - 147 +147

Async chunks

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

id before after diff
infra 2.0MB 2.0MB +1.9KB
Unknown metric groups

API count

id before after diff
@kbn/lens-embeddable-utils - 147 +147

History

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

@crespocarlos crespocarlos merged commit 281cc22 into elastic:main Aug 14, 2023
@crespocarlos crespocarlos deleted the move-attribute-builder-to-package branch August 14, 2023 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move LensAttributeBuilder to separate a package
9 participants