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

[Aggs] Force return 0 on empty buckets on count if null flag is disabled #207308

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Jan 21, 2025

Summary

Fixes #206555

This PR is an attempt to address the null bucket issue with count in Lens formula via the emptyAsNull flag.

Checklist

Risks

This PR introduces potentially some breaking changes, as count null values, in particular coming from shifted computations, as now converted to 0 if the flag has been enabled.
This change is not news in the code base as other aggs like distinct_count or value_count already implements it, but not count.
Apparently no test failed with this change, I've also added new unit ones to freeze the current behaviour and detect future changes.

@dej611 dej611 added release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) labels Jan 21, 2025
@dej611
Copy link
Contributor Author

dej611 commented Jan 21, 2025

/ci

@dej611 dej611 marked this pull request as ready for review January 21, 2025 15:33
@dej611 dej611 requested review from a team as code owners January 21, 2025 15:33
@elasticmachine
Copy link
Contributor

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

@dej611 dej611 requested a review from ppisljar January 22, 2025 08:26
Copy link
Member

@lukasolson lukasolson left a comment

Choose a reason for hiding this comment

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

Code & functionality LGTM

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

This doesn't fully solve what was requested in the original issue.
null/zero is one thing, but the fact that count with timeshift doesn't use the extended_bounds is not addressed by the PR.
Actually not just count but also other metrics doesn't include the extended_bounds when using timeshift.
This results is missing buckets at the beginning and end of the table if they are empty/zero.

@markov00
Copy link
Member

If I'm not wrong the current concept of emptyAsNull means: that if we find a bucket with a zero value, we will display it as null/missing.

 if (value === 0 && agg.params.emptyAsNull) {
        return null;
      }

But in this PR we are also doing the opposite: we are saying that null buckets can be shown as "empty" (actually zero) even if this wasn't requested in the issue and even not expressed by the parameter emptyAsNull.

@dej611
Copy link
Contributor Author

dej611 commented Jan 29, 2025

This doesn't fully solve what was requested in the original issue. null/zero is one thing, but the fact that count with timeshift doesn't use the extended_bounds is not addressed by the PR. Actually not just count but also other metrics doesn't include the extended_bounds when using timeshift. This results is missing buckets at the beginning and end of the table if they are empty/zero.

I do not think the problem is related with the extended_bounds.
All the aggs can return null values when there's no data, with few exceptions which are count, distinct_count, values_count and sum, who expose a specific flag emptyAsNull to enforce this behaviour: now this null behaviour has a side effect within a Lens formula context which is to wipe out other results within a bucket. To resolve this the defaults Lens formula function has been introduced.
Now, back to the exceptions, the 4 functions above, in the scenario where count was using a time_shift was not honouring the opposite case: return 0 by default when the flag was not enabled.
This PR addresses this specific case, which will solve the issue with count and time_shift.

If we want to extends this behaviour to other aggs as well I think we'll need to rethink the agg model and how they work.

@dej611
Copy link
Contributor Author

dej611 commented Jan 30, 2025

Discussed offline with @markov00 this PR.
The linked issue #206555 has a wider scope, which is about forcing ES to return all the buckets in any scenario when using a time shift.
That issue can lead to some wrong results in some cases OR partial results where values should be 0 in others.
This PR provides a solution for specific scenario where the count with shift is used together with another metric in a Lens formula, which resolves the "wrong results" part in the issue above. Not the partial result section tho.

For the partial result we've tested a PoC who seems to work, but needs to be validated in a follow up PR.

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

elasticmachine commented Jan 30, 2025

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #21 / FileDeleteButton isIcon clicking delete button opens the confirmation modal
  • [job] [logs] Jest Tests #21 / TableSearch renders with empty value correctly

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 420.2KB 420.3KB +36.0B

History

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) Feature:Lens release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Time shift prevents from returning all the buckets in the time range
5 participants