Skip to content

Commit

Permalink
[APM] Fix missing service.node.name (#84269)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Nov 27, 2020
1 parent ee5c9bc commit f99766e
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export function ServiceNodeMetrics({ match }: ServiceNodeMetricsProps) {
const { urlParams, uiFilters } = useUrlParams();
const { serviceName, serviceNodeName } = match.params;
const { agentName } = useAgentName();
const { data } = useServiceMetricCharts(urlParams, agentName);
const { data } = useServiceMetricCharts(
urlParams,
agentName,
serviceNodeName
);
const { start, end } = urlParams;

const { data: { host, containerId } = INITIAL_DATA, status } = useFetcher(
Expand Down Expand Up @@ -177,25 +181,6 @@ export function ServiceNodeMetrics({ match }: ServiceNodeMetricsProps) {
</EuiFlexItem>
</MetadataFlexGroup>
)}
{agentName && (
<ChartPointerEventContextProvider>
<EuiFlexGrid columns={2} gutterSize="s">
{data.charts.map((chart) => (
<EuiFlexItem key={chart.key}>
<EuiPanel>
<MetricsChart
start={start}
end={end}
chart={chart}
fetchStatus={status}
/>
</EuiPanel>
</EuiFlexItem>
))}
</EuiFlexGrid>
<EuiSpacer size="xxl" />
</ChartPointerEventContextProvider>
)}
<SearchBar />
<EuiPage>
{agentName && (
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/apm/public/hooks/useServiceMetricCharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const INITIAL_DATA: MetricsChartsByAgentAPIResponse = {

export function useServiceMetricCharts(
urlParams: IUrlParams,
agentName?: string
agentName?: string,
serviceNodeName?: string
) {
const { serviceName } = useParams<{ serviceName?: string }>();
const { start, end } = urlParams;
Expand All @@ -30,6 +31,7 @@ export function useServiceMetricCharts(
params: {
path: { serviceName },
query: {
serviceNodeName,
start,
end,
agentName,
Expand All @@ -39,7 +41,7 @@ export function useServiceMetricCharts(
});
}
},
[serviceName, start, end, agentName, uiFilters]
[serviceName, start, end, agentName, serviceNodeName, uiFilters]
);

return {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/server/lib/metrics/by_agent/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export async function getDefaultMetricsCharts(
serviceName: string
) {
const charts = await Promise.all([
getCPUChartData(setup, serviceName),
getMemoryChartData(setup, serviceName),
getCPUChartData({ setup, serviceName }),
getMemoryChartData({ setup, serviceName }),
]);

return { charts };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ const chartBase: ChartBase = {
series,
};

const getGcRateChart = (
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) => {
function getGcRateChart({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
return fetchAndTransformGcMetrics({
setup,
serviceName,
serviceNodeName,
chartBase,
fieldName: METRIC_JAVA_GC_COUNT,
});
};
}

export { getGcRateChart };
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ const chartBase: ChartBase = {
series,
};

const getGcTimeChart = (
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) => {
function getGcTimeChart({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
return fetchAndTransformGcMetrics({
setup,
serviceName,
serviceNodeName,
chartBase,
fieldName: METRIC_JAVA_GC_TIME,
});
};
}

export { getGcTimeChart };
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ const chartBase: ChartBase = {
series,
};

export async function getHeapMemoryChart(
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) {
export async function getHeapMemoryChart({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
return fetchAndTransformMetrics({
setup,
serviceName,
Expand Down
28 changes: 16 additions & 12 deletions x-pack/plugins/apm/server/lib/metrics/by_agent/java/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ import { getMemoryChartData } from '../shared/memory';
import { getGcRateChart } from './gc/get_gc_rate_chart';
import { getGcTimeChart } from './gc/get_gc_time_chart';

export async function getJavaMetricsCharts(
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) {
export async function getJavaMetricsCharts({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
const charts = await Promise.all([
getCPUChartData(setup, serviceName, serviceNodeName),
getMemoryChartData(setup, serviceName, serviceNodeName),
getHeapMemoryChart(setup, serviceName, serviceNodeName),
getNonHeapMemoryChart(setup, serviceName, serviceNodeName),
getThreadCountChart(setup, serviceName, serviceNodeName),
getGcRateChart(setup, serviceName, serviceNodeName),
getGcTimeChart(setup, serviceName, serviceNodeName),
getCPUChartData({ setup, serviceName, serviceNodeName }),
getMemoryChartData({ setup, serviceName, serviceNodeName }),
getHeapMemoryChart({ setup, serviceName, serviceNodeName }),
getNonHeapMemoryChart({ setup, serviceName, serviceNodeName }),
getThreadCountChart({ setup, serviceName, serviceNodeName }),
getGcRateChart({ setup, serviceName, serviceNodeName }),
getGcTimeChart({ setup, serviceName, serviceNodeName }),
]);

return { charts };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ const chartBase: ChartBase = {
series,
};

export async function getNonHeapMemoryChart(
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) {
export async function getNonHeapMemoryChart({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
return fetchAndTransformMetrics({
setup,
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ const chartBase: ChartBase = {
series,
};

export async function getThreadCountChart(
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) {
export async function getThreadCountChart({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
return fetchAndTransformMetrics({
setup,
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ const chartBase: ChartBase = {
series,
};

export async function getCPUChartData(
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) {
export async function getCPUChartData({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
const metricsChart = await fetchAndTransformMetrics({
setup,
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ export const percentCgroupMemoryUsedScript = {
`,
};

export async function getMemoryChartData(
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) {
export async function getMemoryChartData({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
const cgroupResponse = await fetchAndTransformMetrics({
setup,
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function getMetricsChartDataByAgent({
}): Promise<MetricsChartsByAgentAPIResponse> {
switch (agentName) {
case 'java': {
return getJavaMetricsCharts(setup, serviceName, serviceNodeName);
return getJavaMetricsCharts({ setup, serviceName, serviceNodeName });
}

default: {
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/apm/server/lib/metrics/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,39 @@ describe('metrics queries', () => {
const createTests = (serviceNodeName?: string) => {
it('fetches cpu chart data', async () => {
mock = await inspectSearchParams((setup) =>
getCPUChartData(setup, 'foo', serviceNodeName)
getCPUChartData({ setup, serviceName: 'foo', serviceNodeName })
);

expect(mock.params).toMatchSnapshot();
});

it('fetches memory chart data', async () => {
mock = await inspectSearchParams((setup) =>
getMemoryChartData(setup, 'foo', serviceNodeName)
getMemoryChartData({ setup, serviceName: 'foo', serviceNodeName })
);

expect(mock.params).toMatchSnapshot();
});

it('fetches heap memory chart data', async () => {
mock = await inspectSearchParams((setup) =>
getHeapMemoryChart(setup, 'foo', serviceNodeName)
getHeapMemoryChart({ setup, serviceName: 'foo', serviceNodeName })
);

expect(mock.params).toMatchSnapshot();
});

it('fetches non heap memory chart data', async () => {
mock = await inspectSearchParams((setup) =>
getNonHeapMemoryChart(setup, 'foo', serviceNodeName)
getNonHeapMemoryChart({ setup, serviceName: 'foo', serviceNodeName })
);

expect(mock.params).toMatchSnapshot();
});

it('fetches thread count chart data', async () => {
mock = await inspectSearchParams((setup) =>
getThreadCountChart(setup, 'foo', serviceNodeName)
getThreadCountChart({ setup, serviceName: 'foo', serviceNodeName })
);

expect(mock.params).toMatchSnapshot();
Expand Down

0 comments on commit f99766e

Please sign in to comment.