Skip to content

Commit

Permalink
Updates based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
smith committed Aug 3, 2021
1 parent 23472fb commit 549a910
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,27 @@

import { EuiButton, EuiFlexItem } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useContext, useEffect, useState } from 'react';
import React from 'react';
import { ContentsProps } from '.';
import { NodeStats } from '../../../../../common/service_map';
import { useUrlParams } from '../../../../context/url_params_context/use_url_params';
import { useApmParams } from '../../../../hooks/use_apm_params';
import { useApmRouter } from '../../../../hooks/use_apm_router';
import { FETCH_STATUS, useFetcher } from '../../../../hooks/use_fetcher';
import { CytoscapeContext } from '../Cytoscape';
import { StatsList } from './stats_list';

export function BackendContents({ nodeData }: ContentsProps) {
const { query } = useApmParams('/service-map');
const apmRouter = useApmRouter();
const {
urlParams: { environment, start, end },
} = useUrlParams();

const backendName = nodeData.label;

// We only want the backend stats for services upstream in the current view of
// the map. Get the ids for the upstream services and use them in the API request.
const [upstreamServices, setUpstreamServices] = useState<string[]>([]);
const cy = useContext(CytoscapeContext);
useEffect(() => {
if (cy) {
setUpstreamServices(
cy
.getElementById(nodeData.id!)
.connectedEdges()
.map((edge) => edge.source().id())
);
}
}, [cy, environment, nodeData.id, start, end]);

const { data = { transactionStats: {} } as NodeStats, status } = useFetcher(
(callApmApi) => {
if (backendName && start && end && upstreamServices.length > 0) {
if (backendName && start && end) {
return callApmApi({
endpoint: 'GET /api/apm/service-map/backend/{backendName}',
params: {
Expand All @@ -50,13 +36,12 @@ export function BackendContents({ nodeData }: ContentsProps) {
environment,
start,
end,
upstreamServices: JSON.stringify(upstreamServices),
},
},
});
}
},
[environment, backendName, start, end, upstreamServices],
[environment, backendName, start, end],
{
preservePreviousData: false,
}
Expand All @@ -65,6 +50,7 @@ export function BackendContents({ nodeData }: ContentsProps) {
const isLoading = status === FETCH_STATUS.LOADING;
const detailsUrl = apmRouter.link('/backends/:backendName/overview', {
path: { backendName },
query,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { rangeQuery } from '../../../../observability/server';
import {
EVENT_OUTCOME,
SERVICE_NAME,
SPAN_DESTINATION_SERVICE_RESOURCE,
SPAN_DESTINATION_SERVICE_RESPONSE_TIME_COUNT,
SPAN_DESTINATION_SERVICE_RESPONSE_TIME_SUM,
Expand All @@ -25,15 +24,13 @@ interface Options {
environment?: string;
backendName: string;
searchAggregatedTransactions: boolean;
upstreamServices: string[];
}

export function getServiceMapBackendNodeInfo({
environment,
backendName,
setup,
searchAggregatedTransactions,
upstreamServices,
}: Options) {
return withApmSpan('get_service_map_backend_node_stats', async () => {
const { apmEventClient, start, end } = setup;
Expand All @@ -54,7 +51,6 @@ export function getServiceMapBackendNodeInfo({
bool: {
filter: [
{ term: { [SPAN_DESTINATION_SERVICE_RESOURCE]: backendName } },
{ terms: { [SERVICE_NAME]: upstreamServices } },
...rangeQuery(start, end),
...environmentQuery(environment),
],
Expand Down
10 changes: 2 additions & 8 deletions x-pack/plugins/apm/server/routes/service_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import Boom from '@hapi/boom';
import { jsonRt } from '@kbn/io-ts-utils';
import * as t from 'io-ts';
import { isActivePlatinumLicense } from '../../common/license_check';
import { invalidLicenseMessage } from '../../common/service_map';
Expand Down Expand Up @@ -108,11 +107,7 @@ const serviceMapBackendNodeRoute = createApmServerRoute({
path: t.type({
backendName: t.string,
}),
query: t.intersection([
t.type({ upstreamServices: jsonRt.pipe(t.array(t.string)) }),
environmentRt,
rangeRt,
]),
query: t.intersection([environmentRt, rangeRt]),
}),
options: { tags: ['access:apm'] },
handler: async (resources) => {
Expand All @@ -128,7 +123,7 @@ const serviceMapBackendNodeRoute = createApmServerRoute({

const {
path: { backendName },
query: { environment, upstreamServices },
query: { environment },
} = params;

const searchAggregatedTransactions = await getSearchAggregatedTransactions(
Expand All @@ -140,7 +135,6 @@ const serviceMapBackendNodeRoute = createApmServerRoute({
setup,
backendName,
searchAggregatedTransactions,
upstreamServices,
});
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default function serviceMapsApiTests({ getService }: FtrProviderContext)
const q = querystring.stringify({
start: metadata.start,
end: metadata.end,
upstreamServices: JSON.stringify(['opbeans-node']),
});
const response = await supertest.get(`/api/apm/service-map/backend/postgres?${q}`);

Expand Down Expand Up @@ -285,12 +284,12 @@ export default function serviceMapsApiTests({ getService }: FtrProviderContext)

expectSnapshot(response.body).toMatchInline(`
Object {
"avgCpuUsage": 0.289166666666667,
"avgErrorRate": 0.00531914893617021,
"avgMemoryUsage": 0.213260669882427,
"avgCpuUsage": 0.240216666666667,
"avgErrorRate": 0,
"avgMemoryUsage": 0.202572668763642,
"transactionStats": Object {
"avgRequestsPerMinute": 5.26666666666667,
"avgTransactionDuration": 22281.4255319149,
"avgRequestsPerMinute": 5.2,
"avgTransactionDuration": 53906.6603773585,
},
}
`);
Expand All @@ -302,7 +301,6 @@ export default function serviceMapsApiTests({ getService }: FtrProviderContext)
const q = querystring.stringify({
start: metadata.start,
end: metadata.end,
upstreamServices: JSON.stringify(['opbeans-node']),
});
const response = await supertest.get(`/api/apm/service-map/backend/postgresql?${q}`);

Expand All @@ -312,8 +310,8 @@ export default function serviceMapsApiTests({ getService }: FtrProviderContext)
Object {
"avgErrorRate": 0,
"transactionStats": Object {
"avgRequestsPerMinute": 4.23333333333333,
"avgTransactionDuration": 2991.37795275591,
"avgRequestsPerMinute": 82.9666666666667,
"avgTransactionDuration": 18307.583366814,
},
}
`);
Expand Down

0 comments on commit 549a910

Please sign in to comment.