Skip to content

Commit

Permalink
[APM] Fix incorrect Y-axis and hover values in log rate chart on serv…
Browse files Browse the repository at this point in the history
…ice overview (elastic#201361)

## Summary

Closes elastic#201106

> [!NOTE]
> Some other additions happened in this PR. Context can be found in
elastic#201361 (comment).

The data being fed to the Log Rate chart was incorrect because it was
dividing the number of documents found at a given point in time on the
X-axis by the total number of documents found across the entire time
range.

The chart should display the total number of documents at the point in
time on the X-axis without considering the total range.

|Interval|Before|After|
|-|-|-|
|30m|![Screenshot 2024-11-22 at 12 43
28](https://github.com/user-attachments/assets/17e1521b-ffd8-463b-8bff-5ebf3acd6f6d)|![Screenshot
2024-11-22 at 12 44
28](https://github.com/user-attachments/assets/e287d3e7-9e7f-467b-b144-989791c74c71)|
|24h|![Screenshot 2024-11-22 at 12 32
32](https://github.com/user-attachments/assets/bd21f387-7388-4fd0-b527-db933c7b9bd9)|![Screenshot
2024-11-22 at 12 36
14](https://github.com/user-attachments/assets/5aa0d3dd-4419-4e59-a821-02bffb107355)|
  • Loading branch information
iblancof authored Nov 26, 2024
1 parent 2850f68 commit 936b883
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useApmParams } from '../../../../hooks/use_apm_params';
import { useFetcher } from '../../../../hooks/use_fetcher';
import { useTimeRange } from '../../../../hooks/use_time_range';
import { APIReturnType } from '../../../../services/rest/create_call_apm_api';
import { asInteger } from '../../../../../common/utils/formatters';
import { asDecimalOrInteger } from '../../../../../common/utils/formatters';
import { TooltipContent } from './tooltip_content';
import { Popover } from './popover';
import { mergeKueries, toKueryFilterFormat } from '../../../../../common/utils/kuery_utils';
Expand Down Expand Up @@ -146,7 +146,7 @@ export function LogErrorRateChart({ height }: { height: number }) {
showAnnotations={false}
fetchStatus={status}
timeseries={timeseries}
yLabelFormat={asInteger}
yLabelFormat={asDecimalOrInteger}
/>
</EuiPanel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useApmParams } from '../../../../hooks/use_apm_params';
import { useFetcher } from '../../../../hooks/use_fetcher';
import { useTimeRange } from '../../../../hooks/use_time_range';
import { APIReturnType } from '../../../../services/rest/create_call_apm_api';
import { asInteger } from '../../../../../common/utils/formatters';
import { asDecimalOrInteger } from '../../../../../common/utils/formatters';
import { TooltipContent } from './tooltip_content';
import { Popover } from './popover';
import { ChartType, getTimeSeriesColor } from '../helper/get_timeseries_color';
Expand Down Expand Up @@ -129,7 +129,7 @@ export function LogRateChart({ height }: { height: number }) {
showAnnotations={false}
fetchStatus={status}
timeseries={timeseries}
yLabelFormat={asInteger}
yLabelFormat={asDecimalOrInteger}
/>
</EuiPanel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function createGetLogErrorRateTimeseries() {
const totalErrorsCount = logErrorCount + errorLogLevelErrorsCount;
return {
x: timeseriesBucket.key,
y: totalErrorsCount,
y: totalErrorsCount / (intervalString / 60),
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,10 @@ export function createGetLogsRateTimeseries() {

return buckets
? buckets.reduce<LogsRateTimeseriesReturnType>((acc, bucket) => {
const totalCount = bucket.doc_count;

const timeseries = bucket.timeseries.buckets.map((timeseriesBucket) => {
return {
x: timeseriesBucket.key,
y: timeseriesBucket.doc_count / totalCount,
y: timeseriesBucket.doc_count / (intervalString / 60),
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
it('returns log rate timeseries', async () => {
const response = await getLogsRateTimeseries();
expect(response.status).to.be(200);
expect(
response.body.currentPeriod[serviceName].every(({ y }) => y === 0.06666666666666667)
).to.be(true);
expect(response.body.currentPeriod[serviceName].every(({ y }) => y === 1)).to.be(true);
});

it('handles environment filter', async () => {
Expand All @@ -168,10 +166,8 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
});

expect(response.status).to.be(200);
expect(first(response.body.currentPeriod?.['my-service'])?.y).to.be(
0.18181818181818182
);
expect(last(response.body.currentPeriod?.['my-service'])?.y).to.be(0.09090909090909091);
expect(first(response.body.currentPeriod?.['my-service'])?.y).to.be(2);
expect(last(response.body.currentPeriod?.['my-service'])?.y).to.be(1);
});
});
});
Expand Down

0 comments on commit 936b883

Please sign in to comment.