From 936b883c285819963320ee18f29c623504f405cc Mon Sep 17 00:00:00 2001 From: Irene Blanco Date: Tue, 26 Nov 2024 14:39:45 +0100 Subject: [PATCH] [APM] Fix incorrect Y-axis and hover values in log rate chart on service overview (#201361) ## Summary Closes https://github.com/elastic/kibana/issues/201106 > [!NOTE] > Some other additions happened in this PR. Context can be found in https://github.com/elastic/kibana/pull/201361#issuecomment-2500366316. 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)| --- .../shared/charts/log_rates/log_error_rate_chart.tsx | 4 ++-- .../shared/charts/log_rates/log_rate_chart.tsx | 4 ++-- .../get_logs_error_rate_timeseries.ts | 2 +- .../get_logs_rate_timeseries.ts | 4 +--- .../apm/entities/service_logs_rate_timeseries.spec.ts | 10 +++------- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/observability_solution/apm/public/components/shared/charts/log_rates/log_error_rate_chart.tsx b/x-pack/plugins/observability_solution/apm/public/components/shared/charts/log_rates/log_error_rate_chart.tsx index f75f9f08cc31c..6cbd3e188720b 100644 --- a/x-pack/plugins/observability_solution/apm/public/components/shared/charts/log_rates/log_error_rate_chart.tsx +++ b/x-pack/plugins/observability_solution/apm/public/components/shared/charts/log_rates/log_error_rate_chart.tsx @@ -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'; @@ -146,7 +146,7 @@ export function LogErrorRateChart({ height }: { height: number }) { showAnnotations={false} fetchStatus={status} timeseries={timeseries} - yLabelFormat={asInteger} + yLabelFormat={asDecimalOrInteger} /> ); diff --git a/x-pack/plugins/observability_solution/apm/public/components/shared/charts/log_rates/log_rate_chart.tsx b/x-pack/plugins/observability_solution/apm/public/components/shared/charts/log_rates/log_rate_chart.tsx index f4d5981da38ef..8025a628067e7 100644 --- a/x-pack/plugins/observability_solution/apm/public/components/shared/charts/log_rates/log_rate_chart.tsx +++ b/x-pack/plugins/observability_solution/apm/public/components/shared/charts/log_rates/log_rate_chart.tsx @@ -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'; @@ -129,7 +129,7 @@ export function LogRateChart({ height }: { height: number }) { showAnnotations={false} fetchStatus={status} timeseries={timeseries} - yLabelFormat={asInteger} + yLabelFormat={asDecimalOrInteger} /> ); diff --git a/x-pack/plugins/observability_solution/logs_data_access/server/services/get_logs_error_rate_timeseries/get_logs_error_rate_timeseries.ts b/x-pack/plugins/observability_solution/logs_data_access/server/services/get_logs_error_rate_timeseries/get_logs_error_rate_timeseries.ts index 4766436fdebfc..ac4f62932b64a 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/server/services/get_logs_error_rate_timeseries/get_logs_error_rate_timeseries.ts +++ b/x-pack/plugins/observability_solution/logs_data_access/server/services/get_logs_error_rate_timeseries/get_logs_error_rate_timeseries.ts @@ -138,7 +138,7 @@ export function createGetLogErrorRateTimeseries() { const totalErrorsCount = logErrorCount + errorLogLevelErrorsCount; return { x: timeseriesBucket.key, - y: totalErrorsCount, + y: totalErrorsCount / (intervalString / 60), }; }); diff --git a/x-pack/plugins/observability_solution/logs_data_access/server/services/get_logs_rate_timeseries/get_logs_rate_timeseries.ts b/x-pack/plugins/observability_solution/logs_data_access/server/services/get_logs_rate_timeseries/get_logs_rate_timeseries.ts index cdcf360405e75..9df26b48db098 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/server/services/get_logs_rate_timeseries/get_logs_rate_timeseries.ts +++ b/x-pack/plugins/observability_solution/logs_data_access/server/services/get_logs_rate_timeseries/get_logs_rate_timeseries.ts @@ -104,12 +104,10 @@ export function createGetLogsRateTimeseries() { return buckets ? buckets.reduce((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), }; }); diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/entities/service_logs_rate_timeseries.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/entities/service_logs_rate_timeseries.spec.ts index fb10925b9906d..8a2a75851881c 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/entities/service_logs_rate_timeseries.spec.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/entities/service_logs_rate_timeseries.spec.ts @@ -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 () => { @@ -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); }); }); });