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

[Lens] Allow non-numeric metrics for metric vis #169258

Merged
merged 4 commits into from Oct 30, 2023

Conversation

mbondyra
Copy link
Contributor

@mbondyra mbondyra commented Oct 18, 2023

Summary

Fixes #137756
Allows to set non numeric metrics for metric visualization for primary and secondary metric.

Screenshot 2023-10-19 at 13 45 47 Screenshot 2023-10-19 at 13 46 37

Doesn't include coloring by terms.
When primary metric is non-numeric:

  1. when maximum value is empty, we hide maximum value group
  2. when maximum value has a value we set an error message on dimension
  3. we don’t allow to use a palette for coloring
  4. we don’t allow to set a trendline
Screenshot 2023-10-19 at 13 30 16 Screenshot 2023-10-19 at 13 30 22

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Multiple Spaces—unexpected behavior in non-default Kibana Space. Low High Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces.
Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. High Low Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure.
Code should gracefully handle cases when feature X or plugin Y are disabled. Medium High Unit tests will verify that any feature flag or plugin combination still results in our service operational.
See more potential risk examples

For maintainers

@mbondyra mbondyra added release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens v8.12.0 labels Oct 18, 2023
@mbondyra mbondyra force-pushed the lens/non-numerical-metrics branch 6 times, most recently from 5b49775 to 4145f6b Compare October 19, 2023 14:08
@mbondyra mbondyra marked this pull request as ready for review October 19, 2023 14:25
@mbondyra mbondyra requested a review from a team as a code owner October 19, 2023 14:25
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

This looks great! I found some small bugs:

  • When the collapse by is on then I see the coloring options in the metric dimension for non numeric fields
image
  • I have a configuration like this
image I change the metric to last value of @timestamp and my chart is colored blue for some reason, shouldn't this default to the neutral color? image If I remove the dimension it works fine. Also with trendlines it works as expected. The problem is when I have the bars set.

@dej611
Copy link
Contributor

dej611 commented Oct 23, 2023

Maybe this does not strictly belong here, but I would like to raise some awareness about long text fields for Metric:

Screenshot 2023-10-23 at 09 47 48 Screenshot 2023-10-23 at 09 47 08

While the secondary metric can go multiline, the primary metric has a no-wrap policy for the CSS white-space property.
CC @gvnmagni

I've tried to quickly check what would happen without that nowrap thing but it introduces other issues:

Screenshot 2023-10-23 at 09 48 20 Screenshot 2023-10-23 at 09 48 05

@gvnmagni
Copy link

Thank you @dej611, given the nature of the secondary metric it was easier to expect that it could go on multiple lines, it is also way smaller and then way more easy to deal with. At the same time this is an interesting conversation to have because introducing text might make worth to talk about multi-lines for values/strings as well. Thank you for pointing this out!

@mbondyra
Copy link
Contributor Author

@dej611 @gvnmagni I'll create an issue about the pointed out problem, we should definitely find a solution but I think it's out of scope for this PR.

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

Nice! Just did a code review.

@drewdaemon
Copy link
Contributor

If I remove the dimension it works fine. Also with trendlines it works as expected. The problem is when I have the bars set.

Yeah, IIRC when no max is provided, elastic-charts interprets the color property as the background color instead of the bar color.

@mbondyra
Copy link
Contributor Author

When the collapse by is on then I see the coloring options in the metric dimension for non numeric fields

@stratoula this is an extreme edgecase and also not an easy problem to fix (we already have it in datatable). I could create a bug or we could also just ignore it – in the end, seeing these options don't really break anything.

@stratoula
Copy link
Contributor

Well this doesn't look good

image

in datatable also doesn't make sense but feels a bit better

image

I agree that is an edge case but can you explain why is it difficult to hide this in that case?

@stratoula
Copy link
Contributor

I see that the problem is that the last metric column reports that is a number but is wrong. Can we fix it? If we fix it on the aggs level then it will be solved in both places

fixableInEditor: true,
displayLocations: [{ id: 'dimensionButton', dimensionId: state.maxAccessor }],
shortMessage: i18n.translate('xpack.lens.lnsMetric_maxDimensionPanel.nonNumericError', {
defaultMessage: 'Maximum value cannot be defined for non-numeric primary metric.',
Copy link
Contributor

Choose a reason for hiding this comment

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

How about making this text more positive.

Primary metric must be numeric to set a maximum value.

@stratoula
Copy link
Contributor

I see that the problem is that the last metric column reports that is a number but is wrong. Can we fix it? If we fix it on the aggs level then it will be solved in both places

If the fix on the aggs level is difficult you can do it here possibly (I dont think that this will cause any bugs tbh) x-pack/plugins/lens/common/expressions/datatable/utils.ts

We are already doing this for min and max. You can add a check for last value too. If you check the column.meta.params.id the value is string (not numeric) which is the correct type. So you could extend it possibly for other types.

// min and max aggs are reporting as number but are actually dates - work around this by checking for the date formatter until this is fixed at the source

const isNumeric = column?.meta.type === 'number' && column?.meta.params?.id !== 'date';

@mbondyra
Copy link
Contributor Author

mbondyra commented Oct 26, 2023

@stratoula all the bugs were fixed (by rebasing off the aggs PR)
@gchaps copy replaced with your suggestion, thank you!
@drewdaemon I will start working on replacing the test file with RTL, but I will submit it in the separate PR to not make this one bulky and dependant on my speed.

Please recheck 🙏🏼 😊

mbondyra added a commit that referenced this pull request Oct 26, 2023
…metrics (#169834)

## Summary

When checking my PR here #169258
@stratoula noticed that the `column.meta.type` is not set properly for
last value aggregation (it always defaults to 'number', same with all
the filtered metrics too!). When I dug deeper, I noticed that happens
because we calculate it as:
```
   type:
              column.aggConfig.type.valueType
              column.aggConfig.params.field?.type ||
              'number',
```

and some of the `AggConfigs` don't have the static `valueType` property
nor field, specifically the one with nested aggregations, like top_hits,
top_metrics and filtered_metric. instead of a static `valueType`, I've
decided to change it to a method `getValueType` where we can pass
AggConfigs and get the type from different places internally. This way
`top_hits`, `top_metrics` and `filtered_metric` get the type of the
field from `customMetric`.
I also changed the values for `min` and `max` aggregation - they were
set on `number`, but they can also be a `date`.
@mbondyra mbondyra removed the request for review from a team October 26, 2023 14:22
@gchaps
Copy link
Contributor

gchaps commented Oct 26, 2023

The text re: the primary metric LGTM.

What does this message mean: At least one color range contains the wrong value or color

@mbondyra
Copy link
Contributor Author

@gchaps this doesn't come from this PR, but I am happy to revisit. This error appears when the input value for the color ranges is not correct (see the screenshot attached to Stratoula's message)

@stratoula
Copy link
Contributor

Ok we are very close!

  • If you set a collapse by on a numerc field and then change the metric to last value of a keyword the color remains. Let's default to the default one
image

@mbondyra
Copy link
Contributor Author

Fixed!

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Async chunks

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

id before after diff
expressionMetricVis 4.6KB 4.9KB +283.0B
lens 1.4MB 1.4MB +1.2KB
total +1.5KB

History

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

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

Tested the broken color cases! Thank you!

bryce-b pushed a commit to bryce-b/kibana that referenced this pull request Oct 30, 2023
…metrics (elastic#169834)

## Summary

When checking my PR here elastic#169258
@stratoula noticed that the `column.meta.type` is not set properly for
last value aggregation (it always defaults to 'number', same with all
the filtered metrics too!). When I dug deeper, I noticed that happens
because we calculate it as:
```
   type:
              column.aggConfig.type.valueType
              column.aggConfig.params.field?.type ||
              'number',
```

and some of the `AggConfigs` don't have the static `valueType` property
nor field, specifically the one with nested aggregations, like top_hits,
top_metrics and filtered_metric. instead of a static `valueType`, I've
decided to change it to a method `getValueType` where we can pass
AggConfigs and get the type from different places internally. This way
`top_hits`, `top_metrics` and `filtered_metric` get the type of the
field from `customMetric`.
I also changed the values for `min` and `max` aggregation - they were
set on `number`, but they can also be a `date`.
@mbondyra mbondyra merged commit c7e7853 into elastic:main Oct 30, 2023
27 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Oct 30, 2023
@mbondyra mbondyra deleted the lens/non-numerical-metrics branch October 30, 2023 19:52
awahab07 pushed a commit to awahab07/kibana that referenced this pull request Oct 31, 2023
…metrics (elastic#169834)

## Summary

When checking my PR here elastic#169258
@stratoula noticed that the `column.meta.type` is not set properly for
last value aggregation (it always defaults to 'number', same with all
the filtered metrics too!). When I dug deeper, I noticed that happens
because we calculate it as:
```
   type:
              column.aggConfig.type.valueType
              column.aggConfig.params.field?.type ||
              'number',
```

and some of the `AggConfigs` don't have the static `valueType` property
nor field, specifically the one with nested aggregations, like top_hits,
top_metrics and filtered_metric. instead of a static `valueType`, I've
decided to change it to a method `getValueType` where we can pass
AggConfigs and get the type from different places internally. This way
`top_hits`, `top_metrics` and `filtered_metric` get the type of the
field from `customMetric`.
I also changed the values for `min` and `max` aggregation - they were
set on `number`, but they can also be a `date`.
awahab07 pushed a commit to awahab07/kibana that referenced this pull request Oct 31, 2023
## Summary

Fixes elastic#137756 
Allows to set non numeric metrics for metric visualization for primary
and secondary metric.

<img width="369" alt="Screenshot 2023-10-19 at 13 45 47"
src="https://github.com/elastic/kibana/assets/4283304/d6f00cd1-3be8-4c07-abe0-5bd15e2e9813">
<img width="350" alt="Screenshot 2023-10-19 at 13 46 37"
src="https://github.com/elastic/kibana/assets/4283304/01978149-ca40-44c2-ba73-9698335e819a">


Doesn't include coloring by terms.
When primary metric is non-numeric:
1. when maximum value is empty, we hide maximum value group
2. when maximum value has a value we set an error message on dimension
3. we don’t allow to use a palette for coloring
4. we don’t allow to set a trendline

<img width="681" alt="Screenshot 2023-10-19 at 13 30 16"
src="https://github.com/elastic/kibana/assets/4283304/7464f9cc-c09c-42cd-bd44-f55ffc1dfad9">
<img width="456" alt="Screenshot 2023-10-19 at 13 30 22"
src="https://github.com/elastic/kibana/assets/4283304/e5726ab9-a748-4417-9b66-5bf4d708d833">



### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
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:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure ui-copy Review of UI copy with docs team is recommended v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Allow non-numeric metrics for metric vis
9 participants