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.

@drewdaemon drewdaemon added the ui-copy Review of UI copy with docs team is recommended label Oct 23, 2023
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 force-pushed the lens/non-numerical-metrics branch from e149826 to 088ff3e Compare October 26, 2023 14:21
@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 mbondyra force-pushed the lens/non-numerical-metrics branch from 088ff3e to d06095e Compare October 27, 2023 19:32
@mbondyra
Copy link
Contributor Author

Fixed!

@mbondyra mbondyra force-pushed the lens/non-numerical-metrics branch from 43a43db to d06095e Compare October 27, 2023 19:43
@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

  • 💚 Build #171225 succeeded 088ff3ecbe66fa362d6f6212950c21d785616391
  • 💔 Build #171182 failed 8b4738eb01bea12b5f77b02e1b2dc2f250014271
  • 💔 Build #170366 failed 5690aaaf99f6a27bff24d46990e5091a26d3b778
  • 💛 Build #169798 was flaky baad6067678598b8d05decc18b7c903f2714be07
  • 💛 Build #169651 was flaky 0e495acd2ddd40b6ef9cb9164e5e01400f4e8d61
  • 💔 Build #169490 failed 7c86ba35bdfafcc271489308fbe6b484e5c3b755

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!

@mbondyra mbondyra merged commit c7e7853 into elastic:main Oct 30, 2023
@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
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