Skip to content

Commit

Permalink
[ML] Fix check for too many selected buckets in Anomaly Explorer char…
Browse files Browse the repository at this point in the history
…ts (#96771)
  • Loading branch information
peteharverson authored Apr 13, 2021
1 parent ff6d1d7 commit c937fc3
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ export class AnomalyExplorerChartsService {
const halfPoints = Math.ceil(plotPoints / 2);
const bounds = timeFilter.getActiveBounds();
const boundsMin = bounds?.min ? bounds.min.valueOf() : undefined;
const boundsMax = bounds?.max ? bounds.max.valueOf() : undefined;
let chartRange: ChartRange = {
min: boundsMin
? Math.max(midpointMs - halfPoints * minBucketSpanMs, boundsMin)
: midpointMs - halfPoints * minBucketSpanMs,
max: bounds?.max
? Math.min(midpointMs + halfPoints * minBucketSpanMs, bounds.max.valueOf())
max: boundsMax
? Math.min(midpointMs + halfPoints * minBucketSpanMs, boundsMax)
: midpointMs + halfPoints * minBucketSpanMs,
};

Expand Down Expand Up @@ -210,15 +211,21 @@ export class AnomalyExplorerChartsService {
}

// Elasticsearch aggregation returns points at start of bucket,
// so align the min to the length of the longest bucket.
// so align the min to the length of the longest bucket,
// and use the start of the latest selected bucket in the check
// for too many selected buckets, respecting the max bounds set in the view.
chartRange.min = Math.floor(chartRange.min / maxBucketSpanMs) * maxBucketSpanMs;
if (boundsMin !== undefined && chartRange.min < boundsMin) {
chartRange.min = chartRange.min + maxBucketSpanMs;
}

const selectedLatestBucketStart = boundsMax
? Math.floor(Math.min(selectedLatestMs, boundsMax) / maxBucketSpanMs) * maxBucketSpanMs
: Math.floor(selectedLatestMs / maxBucketSpanMs) * maxBucketSpanMs;

if (
(chartRange.min > selectedEarliestMs || chartRange.max < selectedLatestMs) &&
chartRange.max - chartRange.min < selectedLatestMs - selectedEarliestMs
(chartRange.min > selectedEarliestMs || chartRange.max < selectedLatestBucketStart) &&
chartRange.max - chartRange.min < selectedLatestBucketStart - selectedEarliestMs
) {
tooManyBuckets = true;
}
Expand Down

0 comments on commit c937fc3

Please sign in to comment.