Skip to content

Commit

Permalink
returning transaction error rate
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jul 14, 2020
1 parent a161a36 commit f7965a1
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import cytoscape from 'cytoscape';
import React, { MouseEvent } from 'react';
import { SERVICE_ENVIRONMENT } from '../../../../../common/elasticsearch_fieldnames';
import { popoverMinWidth } from '../cytoscapeOptions';
import { Buttons } from './Buttons';
import { Info } from './Info';
import { ServiceStatsFetcher } from './ServiceStatsFetcher';
Expand Down Expand Up @@ -75,6 +74,7 @@ export function Contents({
<ServiceStatsFetcher
environment={selectedNodeData[SERVICE_ENVIRONMENT]}
serviceName={selectedNodeServiceName}
serviceAnomalyStats={selectedNodeData.serviceAnomalyStats}
/>
) : (
<Info {...selectedNodeData} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ storiesOf('app/ServiceMap/Popover/ServiceStatsList', module)
avgRequestsPerMinute: 164.47222031860858,
avgTransactionDuration: 61634.38905590272,
}}
isLoading={false}
avgErrorRate={0.556068173242986}
/>
),
Expand All @@ -97,7 +96,6 @@ storiesOf('app/ServiceMap/Popover/ServiceStatsList', module)
avgRequestsPerMinute: null,
avgTransactionDuration: null,
}}
isLoading={true}
/>
),
{ info: { propTablesExclude: [EuiThemeProvider] } }
Expand All @@ -113,7 +111,6 @@ storiesOf('app/ServiceMap/Popover/ServiceStatsList', module)
avgRequestsPerMinute: 8.439583235652972,
avgTransactionDuration: 238792.54809512055,
}}
isLoading={false}
/>
),
{ info: { propTablesExclude: [EuiThemeProvider] } }
Expand All @@ -129,7 +126,6 @@ storiesOf('app/ServiceMap/Popover/ServiceStatsList', module)
avgRequestsPerMinute: null,
avgTransactionDuration: null,
}}
isLoading={false}
/>
),
{ info: { propTablesExclude: [EuiThemeProvider] } }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { Logger } from 'src/core/server';
import { UIFilters } from '../../../../typings/ui_filters';

export function getParsedUiFilters({
uiFilters,
logger,
}: {
uiFilters: string;
logger: Logger;
}): UIFilters {
try {
return JSON.parse(uiFilters);
} catch (error) {
logger.error(error);
}
return {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { getServiceMapServiceNodeInfo } from './get_service_map_service_node_info';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import * as getErrorRateModule from '../errors/get_error_rate';
import * as getErrorRateModule from '../transaction_groups/get_error_rate';

describe('getServiceMapServiceNodeInfo', () => {
describe('with no results', () => {
Expand All @@ -23,7 +23,7 @@ describe('getServiceMapServiceNodeInfo', () => {
const environment = 'test environment';
const serviceName = 'test service name';
const result = await getServiceMapServiceNodeInfo({
environment,
uiFilters: { environment },
setup,
serviceName,
});
Expand All @@ -32,17 +32,21 @@ describe('getServiceMapServiceNodeInfo', () => {
avgCpuUsage: null,
avgErrorRate: null,
avgMemoryUsage: null,
avgRequestsPerMinute: null,
avgTransactionDuration: null,
transactionStats: {
avgRequestsPerMinute: null,
avgTransactionDuration: null,
},
});
});
});

describe('with some results', () => {
it('returns data', async () => {
jest
.spyOn(getErrorRateModule, 'getErrorRate')
.mockResolvedValueOnce({ average: 0.5, errorRates: [], noHits: false });
jest.spyOn(getErrorRateModule, 'getErrorRate').mockResolvedValueOnce({
average: 0.5,
erroneousTransactionsRate: [],
noHits: false,
});

const setup = ({
client: {
Expand All @@ -58,7 +62,7 @@ describe('getServiceMapServiceNodeInfo', () => {
const environment = 'test environment';
const serviceName = 'test service name';
const result = await getServiceMapServiceNodeInfo({
environment,
uiFilters: { environment },
setup,
serviceName,
});
Expand All @@ -67,8 +71,10 @@ describe('getServiceMapServiceNodeInfo', () => {
avgCpuUsage: null,
avgErrorRate: 0.5,
avgMemoryUsage: null,
avgRequestsPerMinute: 0.000001586873761097901,
avgTransactionDuration: null,
transactionStats: {
avgRequestsPerMinute: 0.000001586873761097901,
avgTransactionDuration: null,
},
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { UIFilters } from '../../../typings/ui_filters';
import {
TRANSACTION_TYPE,
METRIC_SYSTEM_CPU_PERCENT,
Expand All @@ -16,20 +17,17 @@ import {
import { ProcessorEvent } from '../../../common/processor_event';
import { rangeFilter } from '../../../common/utils/range_filter';
import { ESFilter } from '../../../typings/elasticsearch';
import {
Setup,
SetupTimeRange,
SetupUIFilters,
} from '../helpers/setup_request';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { percentMemoryUsedScript } from '../metrics/by_agent/shared/memory';
import {
TRANSACTION_REQUEST,
TRANSACTION_PAGE_LOAD,
} from '../../../common/transaction_types';
import { getErrorRate } from '../transaction_groups/get_error_rate';
import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es';

interface Options {
setup: Setup & SetupTimeRange & SetupUIFilters;
setup: Setup & SetupTimeRange;
environment?: string;
serviceName: string;
}
Expand All @@ -45,17 +43,19 @@ interface TaskParameters {
export async function getServiceMapServiceNodeInfo({
serviceName,
setup,
}: Options & { serviceName: string }) {
const { start, end, uiFiltersES } = setup;
uiFilters,
}: Options & { serviceName: string; uiFilters: UIFilters }) {
const { start, end } = setup;

const filter: ESFilter[] = [
{ range: rangeFilter(start, end) },
{ term: { [SERVICE_NAME]: serviceName } },
...uiFiltersES,
...getEnvironmentUiFilterES(uiFilters.environment),
];

const minutes = Math.abs((end - start) / (1000 * 60));
const taskParams = {
environment: uiFilters.environment,
filter,
minutes,
serviceName,
Expand Down Expand Up @@ -84,11 +84,20 @@ export async function getServiceMapServiceNodeInfo({
async function getErrorStats({
setup,
serviceName,
environment,
}: {
setup: Options['setup'];
serviceName: string;
environment?: string;
}) {
const { noHits, average } = await getErrorRate({ setup, serviceName });
const setupWithBlankUiFilters = {
...setup,
uiFiltersES: getEnvironmentUiFilterES(environment),
};
const { noHits, average } = await getErrorRate({
setup: setupWithBlankUiFilters,
serviceName,
});
return { avgErrorRate: noHits ? null : average };
}

Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/apm/server/routes/service_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getServiceMapServiceNodeInfo } from '../lib/service_map/get_service_map
import { createRoute } from './create_route';
import { rangeRt, uiFiltersRt } from './default_api_types';
import { APM_SERVICE_MAPS_FEATURE_NAME } from '../feature';
import { getParsedUiFilters } from '../lib/helpers/convert_ui_filters/get_parsed_ui_filters';

export const serviceMapRoute = createRoute(() => ({
path: '/api/apm/service-map',
Expand Down Expand Up @@ -61,15 +62,20 @@ export const serviceMapServiceNodeRoute = createRoute(() => ({
if (!isValidPlatinumLicense(context.licensing.license)) {
throw Boom.forbidden(invalidLicenseMessage);
}
const logger = context.logger;
const setup = await setupRequest(context, request);

const {
query: { uiFilters: uiFiltersJson },
path: { serviceName },
} = context.params;

const uiFilters = getParsedUiFilters({ uiFilters: uiFiltersJson, logger });

return getServiceMapServiceNodeInfo({
setup,
serviceName,
uiFilters,
});
},
}));
10 changes: 3 additions & 7 deletions x-pack/plugins/apm/server/routes/transaction_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { uiFiltersRt, rangeRt } from './default_api_types';
import { getTransactionAvgDurationByBrowser } from '../lib/transactions/avg_duration_by_browser';
import { getTransactionAvgDurationByCountry } from '../lib/transactions/avg_duration_by_country';
import { getErrorRate } from '../lib/transaction_groups/get_error_rate';
import { UIFilters } from '../../typings/ui_filters';
import { getParsedUiFilters } from '../lib/helpers/convert_ui_filters/get_parsed_ui_filters';

export const transactionGroupsRoute = createRoute(() => ({
path: '/api/apm/services/{serviceName}/transaction_groups',
Expand Down Expand Up @@ -71,12 +71,8 @@ export const transactionGroupsChartsRoute = createRoute(() => ({
transactionName,
uiFilters: uiFiltersJson,
} = context.params.query;
let uiFilters: UIFilters = {};
try {
uiFilters = JSON.parse(uiFiltersJson);
} catch (error) {
logger.error(error);
}

const uiFilters = getParsedUiFilters({ uiFilters: uiFiltersJson, logger });

return getTransactionCharts({
serviceName,
Expand Down

0 comments on commit f7965a1

Please sign in to comment.