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

TSVB Filter ratio denominator not handling negative values #150738

Closed
m-wcislo opened this issue Feb 9, 2023 · 13 comments · Fixed by #152053
Closed

TSVB Filter ratio denominator not handling negative values #150738

m-wcislo opened this issue Feb 9, 2023 · 13 comments · Fixed by #152053
Labels
enhancement New value added to drive a business result Feature:TSVB TSVB (Time Series Visual Builder) impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. Team:Visualizations Visualization editors, elastic-charts and infrastructure triage_needed

Comments

@m-wcislo
Copy link

m-wcislo commented Feb 9, 2023

Kibana version:
v 8.4.3
Elasticsearch version:
v 8.4.3
Server OS version:
Rhel7
Browser version:
Firefox 109.0.1
Browser OS version:
Ubuntu 22.04

Describe the bug:
When using TSVB Metric, when adding Filter Ratio aggregation (Sum based) it seems that result is made 0 when the result of underlying sum for denominator is negative.
Steps to reproduce:
1.Data with field test which is runtime field with values both negative, positive and 0.
2.Create TSVB Metric with Filter ratio aggregation based on sum of test
3.Following was observed:

Numerator filter Denominator filter Result
test > 0 test > 0 1
test < 0 test > 0 correct negative value
test < 0 test < 0 0 (should be 1)
test > 0 test < 0 0 (should be correct negative value)

Expected behavior:
Denominator seems to have problems with negative values. So expected is to have 1 when both numerator and denominator filters same documents and counts same value (even when the sum is negative).

@m-wcislo m-wcislo added the bug Fixes for quality problems that affect the customer experience label Feb 9, 2023
@botelastic botelastic bot added the needs-team Issues missing a team label label Feb 9, 2023
@bhavyarm bhavyarm added Feature:Vis Editor Visualization editor issues Feature:TSVB TSVB (Time Series Visual Builder) Team:Visualizations Visualization editors, elastic-charts and infrastructure and removed Feature:Vis Editor Visualization editor issues labels Feb 10, 2023
@elasticmachine
Copy link
Contributor

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

@botelastic botelastic bot removed the needs-team Issues missing a team label label Feb 10, 2023
@stratoula
Copy link
Contributor

This is the script that runs during filter ration function

"params.numerator != null && params.denominator != null && params.denominator > 0 ? params.numerator / params.denominator : 0"

It seems that when the denominator is negative it defaults to 0. This hasn't changed the last many minors so it doesn't see as a bug to me but as a business decision. Unfortunately at this point I dont know how the decision was made. I will change it to enhancement for now, we need to research why this decision was made and either close the issue or change the behavior.

@stratoula stratoula added enhancement New value added to drive a business result triage_needed impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. and removed bug Fixes for quality problems that affect the customer experience labels Feb 11, 2023
@markov00
Copy link
Member

@stratoula you are right, this was the formula that was used since the beginning of TSVB #9725
Probably @simianhacker can chime in to remember why that decision was made.

@stratoula
Copy link
Contributor

stratoula commented Feb 22, 2023

Filter ratio is supported in Lens formulas and it doesn't have this limitation so I am closing this as it is supported in Lens with formulas.

@m-wcislo
Copy link
Author

Do we have any explanation why it doesn't work in TSVB? Is it documented anywhere? The fact that it works in lens is only confirming that it might be bug in tsvb.

@stratoula
Copy link
Contributor

It is how it worked in TSVB since the beginning, @simianhacker can give more information I assume why this has been decided.

@m-wcislo
Copy link
Author

Well the fact that it work the same since it was implemented is nature of every bug. Can't understand why this issue is closed, nothing changed since the first comment. Also, seems it is not documented and works correctly in other parts of the system, which contradicts any business decision that could be made. On top of that it is simply wrong from mathematical perspective giving no warning to the users, until they find out their dashboards have wrong calculations.

@simianhacker
Copy link
Member

simianhacker commented Feb 23, 2023

From a product perspective, we decided to use ZERO since were were talking about a ratios. Maybe it would have been more appropriate to return null.

That being said, I could see an argument for changing the painless script to:

"params.numerator != null && params.denominator != null && params.denominator != 0 ? params.numerator / params.denominator : 0"

Which would support 5 / -3 which would give you a negative ratio of -1.6667.

@simianhacker
Copy link
Member

BTW... I've created a PR for this change: #152053

@m-wcislo
Copy link
Author

Perfect, thanks for fixing this.

@thomasneirynck
Copy link
Contributor

thomasneirynck commented Feb 27, 2023

my2c - this seems to be a bug. The fact it doesn't come up often is, I expect, likely because most users are actually not creating ratios with different signs in nominator/denominator (otherwise, wouldn't they also think it's odd their values come up 0 (?)).

If it's a low effort fix, I'm ok with merging, despite the minor change in behavior (which imho is buggy).

simianhacker added a commit that referenced this issue Feb 28, 2023
## Summary

This PR fixes #150738 by adding support for negative denominators for
TSVB's filter ratios.

### Checklist

- [X] [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

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
@simianhacker
Copy link
Member

@m-wcislo I just merged the PR, the update will be in 8.8

@thomasneirynck & @m-wcislo As far as returning 0 when the denominator is 0, should we change that to null? I don't have a strong opinion one way or another. It's a very small change BUT it will change the results which might be unexpected. The negative ratio was a bug (fixed).

@thomasneirynck
Copy link
Contributor

As far as returning 0 when the denominator is 0, should we change that to null

No big opinion either way fwiw. Maybe just keep as-is and not change the behavior.

bmorelli25 pushed a commit to bmorelli25/kibana that referenced this issue Mar 10, 2023
## Summary

This PR fixes elastic#150738 by adding support for negative denominators for
TSVB's filter ratios.

### Checklist

- [X] [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

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Feature:TSVB TSVB (Time Series Visual Builder) impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. Team:Visualizations Visualization editors, elastic-charts and infrastructure triage_needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants