Skip to content

Commit

Permalink
[ML] APM Correlations: Round duration values to be used in range aggr…
Browse files Browse the repository at this point in the history
…egations. (elastic#114833)

A change in the ES range agg no longer accepts numbers with decimals if the underlying field is typed as long. This fixes the issue by rounding the values we pass on to the range agg.
  • Loading branch information
walterra authored and kibanamachine committed Oct 14, 2021
1 parent a2b42d2 commit f1b1c38
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ describe('query_histogram_range_steps', () => {
);

expect(resp.length).toEqual(100);
expect(resp[0]).toEqual(9.260965422132594);
expect(resp[99]).toEqual(18521.930844265193);
expect(resp[0]).toEqual(9);
expect(resp[99]).toEqual(18522);
expect(esClientSearchMock).toHaveBeenCalledTimes(1);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import { getRequestBase } from './get_request_base';

const getHistogramRangeSteps = (min: number, max: number, steps: number) => {
// A d3 based scale function as a helper to get equally distributed bins on a log scale.
// We round the final values because the ES range agg we use won't accept numbers with decimals for `transaction.duration.us`.
const logFn = scaleLog().domain([min, max]).range([1, steps]);
return [...Array(steps).keys()]
.map(logFn.invert)
.map((d) => (isNaN(d) ? 0 : d));
.map((d) => (isNaN(d) ? 0 : Math.round(d)));
};

export const getHistogramIntervalRequest = (
Expand Down

0 comments on commit f1b1c38

Please sign in to comment.