-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[APM] Fix ML expected bounds missing data in chart, option showing when not neccessary #132975
Conversation
] | ||
// Sorting series so that area type series are before line series | ||
// This is a workaround so that the legendSort works correctly | ||
.sort( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a workaround this issue elastic/elastic-charts#1685
Pinging @elastic/ml-ui (:ml) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested (using 2 day long data set) and LGTM
Pinging @elastic/apm-ui (Team:apm) |
x-pack/plugins/apm/server/lib/anomaly_detection/get_anomaly_timeseries.ts
Show resolved
Hide resolved
const max = Math.max( | ||
...xValues, | ||
// If the last data point of timeseries ends before (picked end time + bucket_span) | ||
// we need to extend the x max domain to the last available data point for the expected bounds | ||
// for the area chart to show up correctly | ||
// See https://github.com/elastic/elastic-charts/issues/1685 | ||
isComparingExpectedBounds | ||
? anomalyChartTimeseries?.boundaries[0]?.data?.slice(-1)[0]?.x ?? 0 | ||
: -Infinity | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really related to the sorting as the linked issue implies?
I don't understand why we need to extend the x-axis range. That should stay true to the time range selected by the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sqren This is an unfortunate side effect of elastic-charts. We need to extend the x-axis range here because if not the last portion of the band area will not show up.
So let's say we have an ML expected bound available from 10:30 to 10:45. But if the latest data point of the time series chart is 10:31, as such the x-domain max will be 10:31. If that's the case, the area band will not show up at all for the 10:30 to 10:45 bucket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So let's say we have an ML expected bound available from 10:30 to 10:45. But if the latest data point of the time series chart is 10:31, as such the x-domain max will be 10:31. If that's the case, the area band will not show up at all for the 10:30 to 10:45 bucket.
Can you perhaps add a unit or api test to show how the data looks in this case? I sounds like we have a data point at 10:45 which elastic-charts ignores because it's outside the range. On that case the fix sounds like we should move the data point from 10:45 to 10:31 instead of extending the range.
const rangeFrom = start - minBucketSize * 1000; // ms | ||
const rangeTo = end + minBucketSize * 1000; // ms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the original naming of start
/end
but make it clear what the difference is:
const rangeFrom = start - minBucketSize * 1000; // ms | |
const rangeTo = end + minBucketSize * 1000; // ms | |
const extendedStart = start - minBucketSize * 1000; // ms | |
const extendedEnd = end + minBucketSize * 1000; // ms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here 2821627
? anomalyChartTimeseries?.boundaries[0]?.data?.slice(-1)[0]?.x ?? 0 | ||
: -Infinity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of -Infinity
can we use 0
as fallback value like on the line above?
Lodash has a last
method. That feels fitting here:
? anomalyChartTimeseries?.boundaries[0]?.data?.slice(-1)[0]?.x ?? 0 | |
: -Infinity | |
? last(anomalyChartTimeseries?.boundaries[0]?.data)?.x ?? 0 | |
: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this part completely now since we moved the logic to server side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to find max of the whole x expected bounds here 62e0dcd
// for the area chart to show up correctly | ||
// See https://github.com/elastic/elastic-charts/issues/1685 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link goes to an issue about legend order, but the problem here seems to be whether the area charts shows up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw. in which case does the expected bounds go over the max x domain? I thought we trimmed it server side to stay within the selected time range?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const max = Math.max( | ||
...xValues, | ||
// If the last data point of timeseries ends before (picked end time + bucket_span) | ||
// we need to extend the x max domain to the last available data point for the expected bounds | ||
// for the area chart to show up correctly | ||
// See https://github.com/elastic/elastic-charts/issues/1685 | ||
isComparingExpectedBounds | ||
? anomalyChartTimeseries?.boundaries[0]?.data?.slice(-1)[0]?.x ?? 0 | ||
: -Infinity | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So let's say we have an ML expected bound available from 10:30 to 10:45. But if the latest data point of the time series chart is 10:31, as such the x-domain max will be 10:31. If that's the case, the area band will not show up at all for the 10:30 to 10:45 bucket.
Can you perhaps add a unit or api test to show how the data looks in this case? I sounds like we have a data point at 10:45 which elastic-charts ignores because it's outside the range. On that case the fix sounds like we should move the data point from 10:45 to 10:31 instead of extending the range.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. I think we should merge this now, so it can go into the BC today (if possible)
I'm going to do some more manual testing specifically wrt getBoundedX
and whether we really don't need to add the extra data point but I don't want to block this PR any longer.
@elasticmachine merge upstream |
💛 Build succeeded, but was flakyFailed CI StepsMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @qn895 |
💔 All backports failed
Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
…en not neccessary (elastic#132975) * Only show expected bounds option in Overview/Transactions subpage of Services * Bucket span * Fix bucket span didn't show up in chart * Change fixed interval to 60s, add elastic-charts ref * ui settings remembering * Address comments * Address comments * Fix linting * Move data point down instead of extending range * Change to last, add test * Fix to use xValuesExpectedBounds * Revert change to to add extra point as es ml already handled it Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 017c8e1)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…en not neccessary (elastic#132975) * Only show expected bounds option in Overview/Transactions subpage of Services * Bucket span * Fix bucket span didn't show up in chart * Change fixed interval to 60s, add elastic-charts ref * ui settings remembering * Address comments * Address comments * Fix linting * Move data point down instead of extending range * Change to last, add test * Fix to use xValuesExpectedBounds * Revert change to to add extra point as es ml already handled it Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 017c8e1)
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
…en not neccessary (elastic#132975) * Only show expected bounds option in Overview/Transactions subpage of Services * Bucket span * Fix bucket span didn't show up in chart * Change fixed interval to 60s, add elastic-charts ref * ui settings remembering * Address comments * Address comments * Fix linting * Move data point down instead of extending range * Change to last, add test * Fix to use xValuesExpectedBounds * Revert change to to add extra point as es ml already handled it Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 017c8e1)
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
…ontrols (#132456) | [APM] Fix ML expected bounds missing data in chart, option showing when not neccessary (#132975) (#133826) * [APM] Add ML expected model bounds as an option to Comparison controls (#132456) * [ML] Add bounds options * [ML] Renable anomalyChartTimeseries boundaries * [ML] Make it into string * [ML] Make it into string * Match colors * [ML] Add comparisonEnabledRt * [ML] Fix types, tests * [ML] Revert json bucket span change * [ML] Add bounds options * [ML] Renable anomalyChartTimeseries boundaries * [ML] Make it into string * [ML] Make it into string * Match colors * [ML] Add comparisonEnabledRt * [ML] Fix types, tests * [ML] Revert json bucket span change * Refactor to use offset with TimeRangeComparisonEnum.ExpectedBounds * Change comparisonColor to be part of anomalySeries * Fix i18n * Add Comparison text to replace 'Previous period' * Fix expected bounds legend default to first * Hide values that are N/A in the tooltips * Fix i18n, color, and null values in tooltips * Refactor to use preferredEnvironment * Don't disable expected bounds by default * Match color of expected bounds with time comparison color * Fix tests * Use bucket_span as minBucketSize for anomaly results * Fix previousPeriodColor undefined for latency chart * Remove 'Comparison:' in legend * Change anomalyTimeseriesColor to use currentPeriod to match stuff * Fix type error * Fix lower model bounds * Add comments * Remove fit * Remove comparisonEnabledRt * Change text Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit c1d0ec5) * [APM] Fix ML expected bounds missing data in chart, option showing when not neccessary (#132975) * Only show expected bounds option in Overview/Transactions subpage of Services * Bucket span * Fix bucket span didn't show up in chart * Change fixed interval to 60s, add elastic-charts ref * ui settings remembering * Address comments * Address comments * Fix linting * Move data point down instead of extending range * Change to last, add test * Fix to use xValuesExpectedBounds * Revert change to to add extra point as es ml already handled it Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 017c8e1) Co-authored-by: Quynh Nguyen <43350163+qn895@users.noreply.github.com> Co-authored-by: Dario Gieselaar <dario.gieselaar@elastic.co> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Summary
Previously, the
Comparison
control will showExpected bounds
option on all the pages. This PR fixes so that it will only show in theOverview
andTransactions
tab within the Services area.Since ML model bounds/expected bounds are stored in intervals of the predefined bucket_span, previously, querying the bounds by simply the start and end time will miss the bucket before or after the end time. This PR fixes the query that fetches the ML model bounds. It also fixes TimeSeriesChart's x domain which previously didn't account for the two ends of the expected bounds.
Previously, the legend will show
Expected bounds - upper
andExpected bounds - lower
beforeAverage
, which is inconsistent with how the other charts are show. This PR fixes so that theExpected bounds
legends are shown last.Before
After
date_histogram
in thecomposite
agg from90s
to60s
.Please note that this PR does not attempt to consolidate the
- upper
and- lower
legends into one. This is currently not possible. The issue to track that feature is here.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:
For maintainers