Skip to content

Commit

Permalink
Merge branch 'main' into prebuilt_security_job_update
Browse files Browse the repository at this point in the history
  • Loading branch information
ajosh0504 authored Dec 13, 2022
2 parents d1a74d0 + bb269f5 commit 54da921
Show file tree
Hide file tree
Showing 37 changed files with 1,354 additions and 9,689 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import { getCriticalPath } from './get_critical_path';

describe('getCriticalPath', () => {
function getCriticalPathFromEvents(events: ApmFields[]) {
const waterfall = getWaterfall(
{
const entryTransaction = dedot(events[0]!, {}) as Transaction;
const waterfall = getWaterfall({
traceItems: {
traceDocs: events.map(
(event) => dedot(event, {}) as Transaction | Span
),
errorDocs: [],
exceedsMax: false,
linkedChildrenOfSpanCountBySpanId: {},
spanLinksCountById: {},
},
events[0]['transaction.id']!
);
entryTransaction,
});

return {
waterfall,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion x-pack/plugins/apm/common/es_fields/apm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const TIMESTAMP = 'timestamp.us';
export const AGENT = 'agent';
export const AGENT_NAME = 'agent.name';
export const AGENT_VERSION = 'agent.version';
Expand Down Expand Up @@ -81,6 +81,13 @@ export const SPAN_LINKS = 'span.links';
export const SPAN_LINKS_TRACE_ID = 'span.links.trace.id';
export const SPAN_LINKS_SPAN_ID = 'span.links.span.id';

export const SPAN_COMPOSITE_COUNT = 'span.composite.count';
export const SPAN_COMPOSITE_SUM = 'span.composite.sum.us';
export const SPAN_COMPOSITE_COMPRESSION_STRATEGY =
'span.composite.compression_strategy';

export const SPAN_SYNC = 'span.sync';

// Parent ID for a transaction or span
export const PARENT_ID = 'parent.id';

Expand All @@ -89,6 +96,7 @@ export const ERROR_GROUP_ID = 'error.grouping_key';
export const ERROR_CULPRIT = 'error.culprit';
export const ERROR_LOG_LEVEL = 'error.log.level';
export const ERROR_LOG_MESSAGE = 'error.log.message';
export const ERROR_EXCEPTION = 'error.exception';
export const ERROR_EXC_MESSAGE = 'error.exception.message'; // only to be used in es queries, since error.exception is now an array
export const ERROR_EXC_HANDLED = 'error.exception.handled'; // only to be used in es queries, since error.exception is now an array
export const ERROR_EXC_TYPE = 'error.exception.type';
Expand Down Expand Up @@ -151,3 +159,5 @@ export const INDEX = '_index';
// Mobile
export const NETWORK_CONNECTION_TYPE = 'network.connection.type';
export const DEVICE_MODEL_NAME = 'device.model.name';

export const CHILD_ID = 'child.id';
88 changes: 88 additions & 0 deletions x-pack/plugins/apm/common/waterfall/typings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { Exception } from '../../typings/es_schemas/raw/error_raw';
import { EventOutcome } from '../../typings/es_schemas/raw/fields/event_outcome';
import { SpanLink } from '../../typings/es_schemas/raw/fields/span_links';
import { TimestampUs } from '../../typings/es_schemas/raw/fields/timestamp_us';
import { AgentName } from '../../typings/es_schemas/ui/fields/agent';

export interface WaterfallTransaction {
timestamp: TimestampUs;
trace: { id: string };
service: {
name: string;
environment?: string;
};
agent: { name: AgentName };
event?: { outcome?: EventOutcome };
parent?: { id?: string };
processor: { event: 'transaction' };
transaction: {
duration: { us: number };
id: string;
name: string;
type: string;
result?: string;
};
faas?: {
coldstart?: boolean;
};
span?: {
links?: SpanLink[];
};
}

export interface WaterfallSpan {
timestamp: TimestampUs;
trace: { id: string };
service: {
name: string;
environment?: string;
};
agent: { name: AgentName };
event?: { outcome?: EventOutcome };
parent?: { id?: string };
processor: { event: 'span' };
span: {
id: string;
type: string;
subtype?: string;
action?: string;
name: string;
composite?: {
count: number;
sum: { us: number };
compression_strategy: string;
};
sync?: boolean;
duration: { us: number };
links?: SpanLink[];
};
transaction?: {
id: string;
};
child?: { id: string[] };
}

export interface WaterfallError {
timestamp: TimestampUs;
trace?: { id: string };
transaction?: { id: string };
parent?: { id: string };
error: {
id: string;
log?: {
message: string;
};
exception?: Exception[];
grouping_key: string;
};
service: {
name: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('transaction_details/distribution', () => {
describe('TransactionDistribution', () => {
it('shows loading indicator when the service is running and returned no results yet', async () => {
jest.spyOn(useFetcherModule, 'useFetcher').mockImplementation(() => ({
data: {},
data: undefined,
refetch: () => {},
status: useFetcherModule.FETCH_STATUS.LOADING,
}));
Expand All @@ -104,11 +104,21 @@ describe('transaction_details/distribution', () => {
});

it("doesn't show loading indicator when the service isn't running", async () => {
jest.spyOn(useFetcherModule, 'useFetcher').mockImplementation(() => ({
data: { percentileThresholdValue: 1234, overallHistogram: [] },
refetch: () => {},
status: useFetcherModule.FETCH_STATUS.SUCCESS,
}));
jest
.spyOn(useFetcherModule, 'useFetcher')
.mockImplementationOnce(() => ({
data: {
traceItems: {},
entryTransaction: {},
},
refetch: () => {},
status: useFetcherModule.FETCH_STATUS.SUCCESS,
}))
.mockImplementationOnce(() => ({
data: { percentileThresholdValue: 1234, overallHistogram: [] },
refetch: () => {},
status: useFetcherModule.FETCH_STATUS.SUCCESS,
}));

render(
<Wrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import { APIReturnType } from '../../../services/rest/create_call_apm_api';
import { getWaterfall } from './waterfall_with_summary/waterfall_container/waterfall/waterfall_helpers/waterfall_helpers';

const INITIAL_DATA: APIReturnType<'GET /internal/apm/traces/{traceId}'> = {
errorDocs: [],
traceDocs: [],
exceedsMax: false,
linkedChildrenOfSpanCountBySpanId: {},
traceItems: {
errorDocs: [],
traceDocs: [],
exceedsMax: false,
spanLinksCountById: {},
},
entryTransaction: undefined,
};
export type WaterfallFetchResult = ReturnType<typeof useWaterfallFetcher>;

Expand All @@ -35,25 +38,23 @@ export function useWaterfallFetcher({
error,
} = useFetcher(
(callApmApi) => {
if (traceId && start && end) {
if (traceId && start && end && transactionId) {
return callApmApi('GET /internal/apm/traces/{traceId}', {
params: {
path: { traceId },
query: {
start,
end,
entryTransactionId: transactionId,
},
},
});
}
},
[traceId, start, end]
[traceId, start, end, transactionId]
);

const waterfall = useMemo(
() => getWaterfall(data, transactionId),
[data, transactionId]
);
const waterfall = useMemo(() => getWaterfall(data), [data]);

return { waterfall, status, error };
}
Loading

0 comments on commit 54da921

Please sign in to comment.