Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Fix missing service.node.name #84269

Merged
merged 4 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the crux of the problem with missing service.node.name

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 && (
<ChartsSyncContextProvider>
<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" />
</ChartsSyncContextProvider>
)}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the chart section was duplicated

<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 }),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server side changes from here and down are purely stylistic (destructured arguments)

]);

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