diff --git a/x-pack/plugins/apm/public/components/app/ServiceDetails/MetricsChart.tsx b/x-pack/plugins/apm/public/components/app/ServiceDetails/MetricsChart.tsx index 346e6640286f3..d652e7c1bd8c6 100644 --- a/x-pack/plugins/apm/public/components/app/ServiceDetails/MetricsChart.tsx +++ b/x-pack/plugins/apm/public/components/app/ServiceDetails/MetricsChart.tsx @@ -5,7 +5,7 @@ */ import { EuiTitle } from '@elastic/eui'; import React from 'react'; -import { GenericMetricsChart } from '../../../../server/lib/metrics/types'; +import { GenericMetricsChart } from '../../../../server/lib/metrics/transform_metrics_chart'; // @ts-ignore import CustomPlot from '../../shared/charts/CustomPlot'; import { HoverXHandlers } from '../../shared/charts/SyncChartGroup'; diff --git a/x-pack/plugins/apm/server/lib/metrics/get_metrics_chart_data_by_agent.ts b/x-pack/plugins/apm/server/lib/metrics/get_metrics_chart_data_by_agent.ts index 6f9a8d6b0fc26..02b94c515d841 100644 --- a/x-pack/plugins/apm/server/lib/metrics/get_metrics_chart_data_by_agent.ts +++ b/x-pack/plugins/apm/server/lib/metrics/get_metrics_chart_data_by_agent.ts @@ -6,7 +6,7 @@ import { Setup } from '../helpers/setup_request'; import { getJavaMetricsCharts } from './by_agent/java'; import { getDefaultMetricsCharts } from './by_agent/default'; -import { GenericMetricsChart } from './types'; +import { GenericMetricsChart } from './transform_metrics_chart'; export interface MetricsChartsByAgentAPIResponse { charts: GenericMetricsChart[]; @@ -20,7 +20,7 @@ export async function getMetricsChartDataByAgent({ setup: Setup; serviceName: string; agentName: string; -}) { +}): Promise { switch (agentName) { case 'java': { return getJavaMetricsCharts(setup, serviceName); diff --git a/x-pack/plugins/apm/server/lib/metrics/transform_metrics_chart.ts b/x-pack/plugins/apm/server/lib/metrics/transform_metrics_chart.ts index ba3ec0a3a8383..951f4ff919a9a 100644 --- a/x-pack/plugins/apm/server/lib/metrics/transform_metrics_chart.ts +++ b/x-pack/plugins/apm/server/lib/metrics/transform_metrics_chart.ts @@ -5,7 +5,7 @@ */ import { AggregationSearchResponse } from 'elasticsearch'; import theme from '@elastic/eui/dist/eui_theme_light.json'; -import { ChartBase, Chart, MetricsAggs, MetricsKeys } from './types'; +import { ChartBase, MetricsAggs, MetricsKeys } from './types'; const colors = [ theme.euiColorVis0, @@ -17,6 +17,7 @@ const colors = [ theme.euiColorVis6 ]; +export type GenericMetricsChart = ReturnType; export function transformDataToChart( result: AggregationSearchResponse>, chartBase: ChartBase @@ -24,8 +25,10 @@ export function transformDataToChart( const { aggregations, hits } = result; const { timeseriesData } = aggregations; - const chart: Chart = { - ...chartBase, + return { + title: chartBase.title, + key: chartBase.key, + yUnit: chartBase.yUnit, totalHits: hits.total, series: Object.keys(chartBase.series).map((seriesKey, i) => ({ title: chartBase.series[seriesKey].title, @@ -43,6 +46,4 @@ export function transformDataToChart( }) })) }; - - return chart; } diff --git a/x-pack/plugins/apm/server/lib/metrics/types.ts b/x-pack/plugins/apm/server/lib/metrics/types.ts index 15d54e1dd3fe5..7c22ddc73f553 100644 --- a/x-pack/plugins/apm/server/lib/metrics/types.ts +++ b/x-pack/plugins/apm/server/lib/metrics/types.ts @@ -5,61 +5,36 @@ */ import { ChartType, YUnit } from '../../../typings/timeseries'; -import { Coordinate } from '../../../typings/timeseries'; export interface AggValue { value: number | null; } -export interface TimeSeriesBucket { - key_as_string: string; // timestamp as string - key: number; // timestamp as epoch milliseconds - doc_count: number; -} - export interface MetricsKeys { [key: string]: AggValue; } -interface SeriesDetails { - title: string; - color?: string; -} - -type SeriesDetailsMap = { - [key in keyof T]: SeriesDetails -}; - export interface ChartBase { title: string; key: string; type: ChartType; yUnit: YUnit; - transformValue?: (value: number) => number; - series: SeriesDetailsMap; -} - -export interface Chart { - title: ChartBase['title']; - key: ChartBase['key']; - type: ChartBase['type']; - yUnit: ChartBase['yUnit']; - totalHits: number; - series: Array>; -} - -export type GenericMetricsChart = Chart; - -export interface ChartSeries { - title: string; - key: keyof T; - type: ChartType; - overallValue: number | null; - data: Coordinate[]; + series: { + [key in keyof T]: { + title: string; + color?: string; + } + }; } export type MetricsAggs = { timeseriesData: { - buckets: Array; + buckets: Array< + { + key_as_string: string; // timestamp as string + key: number; // timestamp as epoch milliseconds + doc_count: number; + } & T + >; }; } & T;