Skip to content

Commit

Permalink
[APM] APIs refactoring (#85010)
Browse files Browse the repository at this point in the history
* renaiming /transaction_groups to /transactions/groups

* renaiming /transaction_groups to /transactions/groups

* renaiming /transaction_groups/charts to /transactions/charts

* renaiming /transaction_groups/distribution to transactions/charts/distribution

* renaiming /transaction_groups/breakdown to transactions/charts/breakdown

* removing /api/apm/transaction_sample. Unused

* renaiming /transaction_groups/error_rate to transactions/charts/error_rate

* removing transaction_groups

* removing /api/apm/transaction_sample. Unused

* renaiming /overview_transaction_groups to transactions/groups/overview

* refactoring error_groups

* addressing pr comments

* fixing test
  • Loading branch information
cauemarcondes authored Dec 5, 2020
1 parent 2f32754 commit d4370ff
Show file tree
Hide file tree
Showing 33 changed files with 4,073 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ import { unit } from '../../../../style/variables';
import { ChartContainer } from '../../../shared/charts/chart_container';
import { EmptyMessage } from '../../../shared/EmptyMessage';

type TransactionDistributionAPIResponse = APIReturnType<'GET /api/apm/services/{serviceName}/transaction_groups/distribution'>;
type TransactionDistributionAPIResponse = APIReturnType<'GET /api/apm/services/{serviceName}/transactions/charts/distribution'>;

type DistributionApiResponse = APIReturnType<'GET /api/apm/services/{serviceName}/transaction_groups/distribution'>;

type DistributionBucket = DistributionApiResponse['buckets'][0];
type DistributionBucket = TransactionDistributionAPIResponse['buckets'][0];

interface IChartPoint {
x0: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { MaybeViewTraceLink } from './MaybeViewTraceLink';
import { TransactionTabs } from './TransactionTabs';
import { IWaterfall } from './WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers';

type DistributionApiResponse = APIReturnType<'GET /api/apm/services/{serviceName}/transaction_groups/distribution'>;
type DistributionApiResponse = APIReturnType<'GET /api/apm/services/{serviceName}/transactions/charts/distribution'>;

type DistributionBucket = DistributionApiResponse['buckets'][0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { ImpactBar } from '../../../shared/ImpactBar';
import { ServiceOverviewTable } from '../service_overview_table';

type ServiceTransactionGroupItem = ValuesType<
APIReturnType<'GET /api/apm/services/{serviceName}/overview_transaction_groups'>['transactionGroups']
APIReturnType<'GET /api/apm/services/{serviceName}/transactions/groups/overview'>['transactionGroups']
>;

interface Props {
Expand Down Expand Up @@ -100,7 +100,7 @@ export function ServiceOverviewTransactionsTable(props: Props) {

return callApmApi({
endpoint:
'GET /api/apm/services/{serviceName}/overview_transaction_groups',
'GET /api/apm/services/{serviceName}/transactions/groups/overview',
params: {
path: { serviceName },
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { APIReturnType } from '../../../../services/rest/createCallApmApi';
import { MockApmPluginContextWrapper } from '../../../../context/apm_plugin/mock_apm_plugin_context';
import { TransactionList } from './';

type TransactionGroup = APIReturnType<'GET /api/apm/services/{serviceName}/transaction_groups'>['items'][0];
type TransactionGroup = APIReturnType<'GET /api/apm/services/{serviceName}/transactions/groups'>['items'][0];

export default {
title: 'app/TransactionOverview/TransactionList',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt';
import { EmptyMessage } from '../../../shared/EmptyMessage';
import { TransactionDetailLink } from '../../../shared/Links/apm/TransactionDetailLink';

type TransactionGroup = APIReturnType<'GET /api/apm/services/{serviceName}/transaction_groups'>['items'][0];
type TransactionGroup = APIReturnType<'GET /api/apm/services/{serviceName}/transactions/groups'>['items'][0];

// Truncate both the link and the child span (the tooltip anchor.) The link so
// it doesn't overflow, and the anchor so we get the ellipsis.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { APIReturnType } from '../../../services/rest/createCallApmApi';
import { useFetcher } from '../../../hooks/use_fetcher';
import { useUrlParams } from '../../../context/url_params_context/use_url_params';

type TransactionsAPIResponse = APIReturnType<'GET /api/apm/services/{serviceName}/transaction_groups'>;
type TransactionsAPIResponse = APIReturnType<'GET /api/apm/services/{serviceName}/transactions/groups'>;

const DEFAULT_RESPONSE: Partial<TransactionsAPIResponse> = {
items: undefined,
Expand All @@ -25,7 +25,7 @@ export function useTransactionListFetcher() {
(callApmApi) => {
if (serviceName && start && end && transactionType) {
return callApmApi({
endpoint: 'GET /api/apm/services/{serviceName}/transaction_groups',
endpoint: 'GET /api/apm/services/{serviceName}/transactions/groups',
params: {
path: { serviceName },
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useTransactionBreakdown() {
if (serviceName && start && end && transactionType) {
return callApmApi({
endpoint:
'GET /api/apm/services/{serviceName}/transaction_groups/breakdown',
'GET /api/apm/services/{serviceName}/transaction/charts/breakdown',
params: {
path: { serviceName },
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function TransactionErrorRateChart({
if (serviceName && start && end) {
return callApmApi({
endpoint:
'GET /api/apm/services/{serviceName}/transaction_groups/error_rate',
'GET /api/apm/services/{serviceName}/transactions/charts/error_rate',
params: {
path: {
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export function useTransactionChartsFetcher() {
(callApmApi) => {
if (serviceName && start && end) {
return callApmApi({
endpoint:
'GET /api/apm/services/{serviceName}/transaction_groups/charts',
endpoint: 'GET /api/apm/services/{serviceName}/transactions/charts',
params: {
path: { serviceName },
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { maybe } from '../../common/utils/maybe';
import { APIReturnType } from '../services/rest/createCallApmApi';
import { useUrlParams } from '../context/url_params_context/use_url_params';

type APIResponse = APIReturnType<'GET /api/apm/services/{serviceName}/transaction_groups/distribution'>;
type APIResponse = APIReturnType<'GET /api/apm/services/{serviceName}/transactions/charts/distribution'>;

const INITIAL_DATA = {
buckets: [] as APIResponse['buckets'],
Expand All @@ -38,7 +38,7 @@ export function useTransactionDistributionFetcher() {
if (serviceName && start && end && transactionType && transactionName) {
const response = await callApmApi({
endpoint:
'GET /api/apm/services/{serviceName}/transaction_groups/distribution',
'GET /api/apm/services/{serviceName}/transactions/charts/distribution',
params: {
path: {
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { rangeFilter } from '../../../common/utils/range_filter';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getTransaction } from '../transactions/get_transaction';

// TODO: rename from "getErrorGroup" to "getErrorGroupSample" (since a single error is returned, not an errorGroup)
export async function getErrorGroup({
export async function getErrorGroupSample({
serviceName,
groupId,
setup,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/server/lib/errors/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { getErrorGroup } from './get_error_group';
import { getErrorGroupSample } from './get_error_group_sample';
import { getErrorGroups } from './get_error_groups';
import {
SearchParamsMock,
Expand All @@ -20,7 +20,7 @@ describe('error queries', () => {

it('fetches a single error group', async () => {
mock = await inspectSearchParams((setup) =>
getErrorGroup({
getErrorGroupSample({
groupId: 'groupId',
serviceName: 'serviceName',
setup,
Expand Down

This file was deleted.

26 changes: 12 additions & 14 deletions x-pack/plugins/apm/server/routes/create_apm_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
serviceAnnotationsCreateRoute,
serviceErrorGroupsRoute,
serviceThroughputRoute,
serviceTransactionGroupsRoute,
} from './services';
import {
agentConfigurationRoute,
Expand Down Expand Up @@ -52,13 +51,13 @@ import {
correlationsForFailedTransactionsRoute,
} from './correlations';
import {
transactionGroupsBreakdownRoute,
transactionGroupsChartsRoute,
transactionGroupsDistributionRoute,
transactionChartsBreakdownRoute,
transactionChartsRoute,
transactionChartsDistributionRoute,
transactionChartsErrorRateRoute,
transactionGroupsRoute,
transactionSampleForGroupRoute,
transactionGroupsErrorRateRoute,
} from './transaction_groups';
transactionGroupsOverviewRoute,
} from './transactions/transactions_routes';
import {
errorGroupsLocalFiltersRoute,
metricsLocalFiltersRoute,
Expand Down Expand Up @@ -122,7 +121,6 @@ const createApmApi = () => {
.add(serviceAnnotationsCreateRoute)
.add(serviceErrorGroupsRoute)
.add(serviceThroughputRoute)
.add(serviceTransactionGroupsRoute)

// Agent configuration
.add(getSingleAgentConfigurationRoute)
Expand Down Expand Up @@ -152,13 +150,13 @@ const createApmApi = () => {
.add(tracesByIdRoute)
.add(rootTransactionByTraceIdRoute)

// Transaction groups
.add(transactionGroupsBreakdownRoute)
.add(transactionGroupsChartsRoute)
.add(transactionGroupsDistributionRoute)
// Transactions
.add(transactionChartsBreakdownRoute)
.add(transactionChartsRoute)
.add(transactionChartsDistributionRoute)
.add(transactionChartsErrorRateRoute)
.add(transactionGroupsRoute)
.add(transactionSampleForGroupRoute)
.add(transactionGroupsErrorRateRoute)
.add(transactionGroupsOverviewRoute)

// UI filters
.add(errorGroupsLocalFiltersRoute)
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/server/routes/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as t from 'io-ts';
import { createRoute } from './create_route';
import { getErrorDistribution } from '../lib/errors/distribution/get_distribution';
import { getErrorGroup } from '../lib/errors/get_error_group';
import { getErrorGroupSample } from '../lib/errors/get_error_group_sample';
import { getErrorGroups } from '../lib/errors/get_error_groups';
import { setupRequest } from '../lib/helpers/setup_request';
import { uiFiltersRt, rangeRt } from './default_api_types';
Expand Down Expand Up @@ -56,7 +56,7 @@ export const errorGroupsRoute = createRoute({
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName, groupId } = context.params.path;
return getErrorGroup({ serviceName, groupId, setup });
return getErrorGroupSample({ serviceName, groupId, setup });
},
});

Expand Down
50 changes: 0 additions & 50 deletions x-pack/plugins/apm/server/routes/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { dateAsStringRt } from '../../common/runtime_types/date_as_string_rt';
import { getSearchAggregatedTransactions } from '../lib/helpers/aggregated_transactions';
import { getServiceErrorGroups } from '../lib/services/get_service_error_groups';
import { toNumberRt } from '../../common/runtime_types/to_number_rt';
import { getServiceTransactionGroups } from '../lib/services/get_service_transaction_groups';
import { getThroughput } from '../lib/services/get_throughput';

export const servicesRoute = createRoute({
Expand Down Expand Up @@ -276,52 +275,3 @@ export const serviceThroughputRoute = createRoute({
});
},
});

export const serviceTransactionGroupsRoute = createRoute({
endpoint: 'GET /api/apm/services/{serviceName}/overview_transaction_groups',
params: t.type({
path: t.type({ serviceName: t.string }),
query: t.intersection([
rangeRt,
uiFiltersRt,
t.type({
size: toNumberRt,
numBuckets: toNumberRt,
pageIndex: toNumberRt,
sortDirection: t.union([t.literal('asc'), t.literal('desc')]),
sortField: t.union([
t.literal('latency'),
t.literal('throughput'),
t.literal('errorRate'),
t.literal('impact'),
]),
}),
]),
}),
options: {
tags: ['access:apm'],
},
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

const searchAggregatedTransactions = await getSearchAggregatedTransactions(
setup
);

const {
path: { serviceName },
query: { size, numBuckets, pageIndex, sortDirection, sortField },
} = context.params;

return getServiceTransactionGroups({
setup,
serviceName,
pageIndex,
searchAggregatedTransactions,
size,
sortDirection,
sortField,
numBuckets,
});
},
});
Loading

0 comments on commit d4370ff

Please sign in to comment.