Skip to content

Commit

Permalink
[APM] Fix issues with v1 spans (#24332)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Oct 23, 2018
1 parent 1c65a40 commit 0296faf
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { WaterfallV1Request } from 'x-pack/plugins/apm/public/store/reactReduxRe
import { WaterfallV2Request } from 'x-pack/plugins/apm/public/store/reactReduxRequest/waterfallV2';
import { IUrlParams } from 'x-pack/plugins/apm/public/store/urlParams';
import { WaterfallResponse } from 'x-pack/plugins/apm/typings/waterfall';
// @ts-ignore
import { loadSpans, loadTrace } from '../../../../../services/rest/apm';
import { getServiceColors } from './getServiceColors';
import { ServiceLegends } from './ServiceLegends';
import { Waterfall } from './Waterfall';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@
* you may not use this file except in compliance with the Elastic License.
*/

// @ts-ignore
import { camelizeKeys } from 'humps';
import { isEmpty } from 'lodash';
import { IDistributionResponse } from 'x-pack/plugins/apm/server/lib/transactions/distribution/get_distribution';
import { Span } from 'x-pack/plugins/apm/typings/Span';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { ITransactionGroup } from 'x-pack/plugins/apm/typings/TransactionGroup';
import { WaterfallResponse } from 'x-pack/plugins/apm/typings/waterfall';
import { IUrlParams } from '../../store/urlParams';
// @ts-ignore
import { convertKueryToEsQuery } from '../kuery';
// @ts-ignore
import { callApi } from './callApi';
// @ts-ignore
import { getAPMIndexPattern } from './savedObjects';

export async function loadLicense() {
Expand All @@ -27,7 +38,7 @@ export async function loadAgentStatus() {
});
}

export async function getEncodedEsQuery(kuery) {
export async function getEncodedEsQuery(kuery?: string) {
if (!kuery) {
return;
}
Expand All @@ -42,7 +53,7 @@ export async function getEncodedEsQuery(kuery) {
return encodeURIComponent(JSON.stringify(esFilterQuery));
}

export async function loadServiceList({ start, end, kuery }) {
export async function loadServiceList({ start, end, kuery }: IUrlParams) {
return callApi({
pathname: `/api/apm/services`,
query: {
Expand All @@ -53,7 +64,12 @@ export async function loadServiceList({ start, end, kuery }) {
});
}

export async function loadServiceDetails({ serviceName, start, end, kuery }) {
export async function loadServiceDetails({
serviceName,
start,
end,
kuery
}: IUrlParams) {
return callApi({
pathname: `/api/apm/services/${serviceName}`,
query: {
Expand All @@ -64,7 +80,11 @@ export async function loadServiceDetails({ serviceName, start, end, kuery }) {
});
}

export async function loadTraceList({ start, end, kuery }) {
export async function loadTraceList({
start,
end,
kuery
}: IUrlParams): Promise<ITransactionGroup[]> {
return callApi({
pathname: '/api/apm/traces',
query: {
Expand All @@ -81,7 +101,7 @@ export async function loadTransactionList({
end,
kuery,
transactionType
}) {
}: IUrlParams): Promise<ITransactionGroup[]> {
return callApi({
pathname: `/api/apm/services/${serviceName}/transactions`,
query: {
Expand All @@ -99,7 +119,7 @@ export async function loadTransactionDistribution({
end,
transactionName,
kuery
}) {
}: IUrlParams): Promise<IDistributionResponse> {
return callApi({
pathname: `/api/apm/services/${serviceName}/transactions/distribution`,
query: {
Expand All @@ -111,26 +131,40 @@ export async function loadTransactionDistribution({
});
}

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

return item;
}

export async function loadSpans({ serviceName, start, end, transactionId }) {
const result = await callApi({
function addSpanId(hit: Span, i: number) {
if (!hit.span.id) {
hit.span.id = i;
}
return hit;
}

export async function loadSpans({
serviceName,
start,
end,
transactionId
}: IUrlParams) {
const hits: Span[] = await callApi({
pathname: `/api/apm/services/${serviceName}/transactions/${transactionId}/spans`,
query: {
start,
end
}
});

result.hits = result.hits.map(addVersion);
return result;
return hits.map(addVersion).map(addSpanId);
}

export async function loadTrace({ traceId, start, end }) {
const result = await callApi(
export async function loadTrace({ traceId, start, end }: IUrlParams) {
const result: WaterfallResponse = await callApi(
{
pathname: `/api/apm/traces/${traceId}`,
query: {
Expand All @@ -154,7 +188,7 @@ export async function loadTransaction({
transactionId,
traceId,
kuery
}) {
}: IUrlParams) {
const result = await callApi(
{
pathname: `/api/apm/services/${serviceName}/transactions/${transactionId}`,
Expand All @@ -180,7 +214,7 @@ export async function loadCharts({
kuery,
transactionType,
transactionName
}) {
}: IUrlParams) {
return callApi({
pathname: `/api/apm/services/${serviceName}/transactions/charts`,
query: {
Expand All @@ -193,6 +227,12 @@ export async function loadCharts({
});
}

interface ErrorGroupListParams extends IUrlParams {
size: number;
sortField: string;
sortDirection: string;
}

export async function loadErrorGroupList({
serviceName,
start,
Expand All @@ -201,7 +241,7 @@ export async function loadErrorGroupList({
size,
sortField,
sortDirection
}) {
}: ErrorGroupListParams) {
return callApi({
pathname: `/api/apm/services/${serviceName}/errors`,
query: {
Expand All @@ -221,7 +261,7 @@ export async function loadErrorGroupDetails({
end,
kuery,
errorGroupId
}) {
}: IUrlParams) {
const res = await callApi(
{
pathname: `/api/apm/services/${serviceName}/errors/${errorGroupId}`,
Expand All @@ -248,7 +288,7 @@ export async function loadErrorDistribution({
end,
kuery,
errorGroupId
}) {
}: IUrlParams) {
return callApi({
pathname: `/api/apm/services/${serviceName}/errors/${errorGroupId}/distribution`,
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import React from 'react';
import { Request } from 'react-redux-request';
import { IDistributionResponse } from '../../../server/lib/transactions/distribution/get_distribution';
// @ts-ignore
import { loadTransactionDistribution } from '../../services/rest/apm';
import { IReduxState } from '../rootReducer';
import { IUrlParams } from '../urlParams';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {
import { Span } from 'x-pack/plugins/apm/typings/Span';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { WaterfallResponse } from 'x-pack/plugins/apm/typings/waterfall';
// @ts-ignore
import { loadSpans, loadTrace } from '../../services/rest/apm';
import { loadSpans } from '../../services/rest/apm';
import { IUrlParams } from '../urlParams';
// @ts-ignore
import { createInitialDataSelector } from './helpers';
Expand All @@ -42,7 +41,7 @@ export function WaterfallV1Request({ urlParams, transaction, render }: Props) {
id={ID}
fn={loadSpans}
args={[{ serviceName, start, end, transactionId }]}
render={({ status, data, args }) => {
render={({ status, data = [], args }) => {
const res = {
hits: [transaction, ...data],
services: [serviceName]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import { Request, RRRRender } from 'react-redux-request';
import { TRACE_ID } from 'x-pack/plugins/apm/common/constants';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { WaterfallResponse } from 'x-pack/plugins/apm/typings/waterfall';

// @ts-ignore
import { loadSpans, loadTrace } from '../../services/rest/apm';
import { loadTrace } from '../../services/rest/apm';
import { IUrlParams } from '../urlParams';
// @ts-ignore
import { createInitialDataSelector } from './helpers';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/typings/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface SpanV1 extends APMDocV1 {
};
name: string;
type: string;
id: number; // id will be derived from hex encoded 64 bit hex_id string in v2
id: number; // we are manually adding span.id
parent?: string; // only v1
stacktrace?: Stackframe[];
};
Expand Down

0 comments on commit 0296faf

Please sign in to comment.