Skip to content

Commit

Permalink
[APM UI] Fix Latency distribution chart breaks due to transaction dur…
Browse files Browse the repository at this point in the history
…ations of value 0 (elastic#191994)

## Summary
Fixes: elastic#184256

This PR fixes the APM latency distribution chart not being able to
render when we had any duration value as 0, to fix it, we now check if
it's 0 and override it with 1.

|Before|After|
|-|-|

|![image](https://github.com/user-attachments/assets/df224a1d-a669-4ea8-ad0e-9f81a82b904a)|![image](https://github.com/user-attachments/assets/cbf6957c-df6f-4f71-8f96-7985279912fa)|

## Test steps
1. Open the following file
`x-pack/plugins/observability_solution/apm/server/routes/correlations/queries/fetch_duration_histogram_range_steps.ts`
2. Modify L61 and L118 changing the initial two values passed to
`getHistogramRangeSteps` to 0.
Like `getHistogramRangeSteps(0, 0, steps)`.
It doesn't matter the order, if one of the params is at 0 it won't
render anything.
3. Revert the change and check if the chart is being rendered.
  • Loading branch information
rmyz committed Sep 5, 2024
1 parent 9e8244f commit 917473f
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ export const fetchDurationHistogramRangeSteps = async ({
const steps = 100;

if (durationMinOverride && durationMaxOverride) {
// these values should never be 0, so if they are we set them to 1
const durationMin = Math.max(1, durationMinOverride);
const durationMax = Math.max(1, durationMaxOverride);

return {
durationMin: durationMinOverride,
durationMax: durationMaxOverride,
rangeSteps: getHistogramRangeSteps(durationMinOverride, durationMaxOverride, steps),
durationMin,
durationMax,
rangeSteps: getHistogramRangeSteps(durationMin, durationMax, steps),
};
}

Expand Down Expand Up @@ -100,8 +104,9 @@ export const fetchDurationHistogramRangeSteps = async ({
return { rangeSteps: [] };
}

const durationMin = resp.aggregations.duration_min.value;
const durationMax = resp.aggregations.duration_max.value * 2;
// these values should never be 0, so if they are we set them to 1
const durationMin = Math.max(1, resp.aggregations.duration_min.value);
const durationMax = Math.max(1, resp.aggregations.duration_max.value * 2);

return {
durationMin,
Expand Down

0 comments on commit 917473f

Please sign in to comment.