Skip to content

Commit

Permalink
[APM] Show message for missing transaction sample (elastic#25141)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Nov 6, 2018
1 parent 9ff005a commit 04bf2d9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 34 deletions.
5 changes: 3 additions & 2 deletions src/ui/public/kfetch/kfetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ export async function kfetch(
});

return fetch(fullUrl, restOptions).then(async res => {
const body = await getBodyAsJson(res);
if (res.ok) {
return res.json();
return body;
}
throw new KFetchError(res, await getBodyAsJson(res));
throw new KFetchError(res, body);
});
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import {
EuiTitle,
EuiToolTip
} from '@elastic/eui';
import { isEmpty } from 'lodash';
import React from 'react';
import { Transaction as ITransaction } from '../../../../../typings/Transaction';
import { IUrlParams } from '../../../../store/urlParams';
import EmptyMessage from '../../../shared/EmptyMessage';
import { TransactionLink } from '../../../shared/TransactionLink';
import { DiscoverTransactionLink } from './ActionMenu';
import { StickyTransactionProperties } from './StickyTransactionProperties';
Expand Down Expand Up @@ -71,15 +69,6 @@ export const Transaction: React.SFC<Props> = ({
location,
waterfall
}) => {
if (isEmpty(transaction)) {
return (
<EmptyMessage
heading="No transaction sample available."
subheading="Try another time range, reset the search filter or select another bucket from the distribution histogram."
/>
);
}

return (
<EuiPanel paddingSize="m">
<EuiFlexGroup justifyContent="spaceBetween">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { EuiSpacer } from '@elastic/eui';
import React from 'react';
import { RRRRenderResponse } from 'react-redux-request';
// @ts-ignore
import { TransactionDetailsRequest } from '../../../store/reactReduxRequest/transactionDetails';
// @ts-ignore
import { TransactionDetailsChartsRequest } from '../../../store/reactReduxRequest/transactionDetailsCharts';
Expand All @@ -16,6 +15,7 @@ import { WaterfallRequest } from '../../../store/reactReduxRequest/waterfall';
import { IUrlParams } from '../../../store/urlParams';
// @ts-ignore
import TransactionCharts from '../../shared/charts/TransactionCharts';
import EmptyMessage from '../../shared/EmptyMessage';
// @ts-ignore
import { KueryBar } from '../../shared/KueryBar';
// @ts-ignore
Expand Down Expand Up @@ -64,6 +64,15 @@ export function TransactionDetailsView({ urlParams, location }: Props) {
<TransactionDetailsRequest
urlParams={urlParams}
render={({ data: transaction }) => {
if (!transaction) {
return (
<EmptyMessage
heading="No transaction sample available."
subheading="Try another time range, reset the search filter or select another bucket from the distribution histogram."
/>
);
}

return (
<WaterfallRequest
urlParams={urlParams}
Expand Down
9 changes: 5 additions & 4 deletions x-pack/plugins/apm/public/services/rest/apm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

// @ts-ignore
import { camelizeKeys } from 'humps';
import { isEmpty } from 'lodash';
import { ServiceResponse } from 'x-pack/plugins/apm/server/lib/services/get_service';
import { ServiceListItemResponse } from 'x-pack/plugins/apm/server/lib/services/get_services';
import { IDistributionResponse } from 'x-pack/plugins/apm/server/lib/transactions/distribution/get_distribution';
Expand Down Expand Up @@ -147,8 +146,10 @@ export async function loadTransactionDistribution({
});
}

function addVersion<T extends Span | Transaction>(item: T): T {
if (!isEmpty(item)) {
function addVersion<T extends Span | Transaction | null | undefined>(
item: T
): T {
if (item != null) {
item.version = item.hasOwnProperty('trace') ? 'v2' : 'v1';
}

Expand Down Expand Up @@ -204,7 +205,7 @@ export async function loadTransaction({
traceId,
kuery
}: IUrlParams) {
const result: Transaction = await callApi(
const result: Transaction | null = await callApi(
{
pathname: `/api/apm/services/${serviceName}/transactions/${transactionId}`,
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function TransactionDetailsRequest({
render
}: {
urlParams: IUrlParams;
render: RRRRender<Transaction>;
render: RRRRender<Transaction | null>;
}) {
const { serviceName, start, end, transactionId, traceId, kuery } = urlParams;

Expand Down
16 changes: 1 addition & 15 deletions x-pack/plugins/apm/server/lib/transactions/get_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import {
} from '../../../common/constants';
import { Setup } from '../helpers/setup_request';

interface HttpError extends Error {
statusCode?: number;
}

export async function getTransaction(
transactionId: string,
traceId: string | undefined,
Expand Down Expand Up @@ -58,15 +54,5 @@ export async function getTransaction(
}

const resp: SearchResponse<Transaction> = await client('search', params);
const result = oc(resp).hits.hits[0]._source();

if (result === undefined) {
const notFoundError = new Error(
`No results found for transaction ID ${transactionId} and trace ID ${traceId}`
) as HttpError;
notFoundError.statusCode = 404;
throw notFoundError;
}

return result;
return oc(resp).hits.hits[0]._source() || null;
}

0 comments on commit 04bf2d9

Please sign in to comment.