Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Convert errors API to typescript #26801

Merged
merged 7 commits into from
Dec 12, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move to es_schema folder
# Conflicts:
#	x-pack/plugins/apm/public/components/app/TransactionDetails/Transaction/ActionMenu.tsx
#	x-pack/plugins/apm/public/components/app/TransactionDetails/Transaction/WaterfallContainer/Waterfall/SpanFlyout/index.tsx
#	x-pack/plugins/apm/public/components/app/TransactionDetails/Transaction/WaterfallContainer/Waterfall/TransactionFlyout/index.tsx
#	x-pack/plugins/apm/public/components/shared/DiscoverButton.tsx
#	x-pack/plugins/apm/public/services/rest/apm/apm.ts
sorenlouv committed Dec 12, 2018
commit f83f9d84da709b855d3e2e40b8f1aaeffc8da0d2
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/common/constants.test.ts
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
*/

import { get } from 'lodash';
import { Span } from '../typings/Span';
import { Transaction } from '../typings/Transaction';
import { Span } from '../typings/es_schemas/Span';
import { Transaction } from '../typings/es_schemas/Transaction';
import * as constants from './constants';

describe('Transaction v1:', () => {
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
import React from 'react';
import { Redirect } from 'react-router-dom';

import { StringMap } from '../../../../typings/common';
import { StringMap } from '../../../../typings/es_schemas/common';
import { legacyDecodeURIComponent } from '../../../utils/url';
// @ts-ignore
import ErrorGroupDetails from '../ErrorGroupDetails';
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import {
} from '@elastic/eui';
import React from 'react';
import { KibanaLink } from 'x-pack/plugins/apm/public/utils/url';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import { DiscoverTransactionButton } from '../../../shared/DiscoverButtons/DiscoverTransactionButton';

function getInfraMetricsQuery(transaction: Transaction) {
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import {
TRANSACTION_RESULT,
USER_ID
} from '../../../../../common/constants';
import { Transaction } from '../../../../../typings/Transaction';
import { Transaction } from '../../../../../typings/es_schemas/Transaction';
import { asPercent, asTime } from '../../../../utils/formatters';
// @ts-ignore
import {
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import {
import { capitalize, first, get } from 'lodash';
import React from 'react';
import styled from 'styled-components';
import { Transaction } from '../../../../../typings/Transaction';
import { Transaction } from '../../../../../typings/es_schemas/Transaction';
import { IUrlParams } from '../../../../store/urlParams';
import { px, units } from '../../../../style/variables';
import { fromQuery, history, toQuery } from '../../../../utils/url';
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
import { EuiSpacer, EuiTab, EuiTabs } from '@elastic/eui';
import { capitalize, first, get } from 'lodash';
import React from 'react';
import { Transaction } from '../../../../../typings/Transaction';
import { Transaction } from '../../../../../typings/es_schemas/Transaction';
import { IUrlParams } from '../../../../store/urlParams';
// @ts-ignore
import { fromQuery, history, toQuery } from '../../../../utils/url';
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import {
import { StickyProperties } from 'x-pack/plugins/apm/public/components/shared/StickyProperties';
import { TransactionLink } from 'x-pack/plugins/apm/public/components/shared/TransactionLink';
import { KibanaLink } from 'x-pack/plugins/apm/public/utils/url';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';

interface Props {
transaction?: Transaction;
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ import { xcode } from 'react-syntax-highlighter/dist/styles';
import sql from 'react-syntax-highlighter/dist/languages/sql';

import { EuiTitle } from '@elastic/eui';
import { DbContext } from '../../../../../../../../typings/Span';
import { DbContext } from '../../../../../../../../typings/es_schemas/Span';

registerLanguage('sql', sql);

Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import {
} from '../../../../../../../style/variables';

import { EuiTitle } from '@elastic/eui';
import { HttpContext } from '../../../../../../../../typings/Span';
import { HttpContext } from '../../../../../../../../typings/es_schemas/Span';

const DatabaseStatement = styled.div`
margin-top: ${px(unit)};
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import {
SPAN_NAME,
SPAN_TYPE
} from 'x-pack/plugins/apm/common/constants';
import { Span } from '../../../../../../../../typings/Span';
import { Span } from '../../../../../../../../typings/es_schemas/Span';
import { asMillis, asPercent } from '../../../../../../../utils/formatters';
import { StickyProperties } from '../../../../../../shared/StickyProperties';

Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ import { HttpContext } from './HttpContext';
import { StickySpanProperties } from './StickySpanProperties';

import { DiscoverSpanButton } from 'x-pack/plugins/apm/public/components/shared/DiscoverButtons/DiscoverSpanButton';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Span } from '../../../../../../../../typings/Span';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import { Span } from '../../../../../../../../typings/es_schemas/Span';
import { FlyoutTopLevelProperties } from '../FlyoutTopLevelProperties';

const StackTraceContainer = styled.div`
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ import styled from 'styled-components';
import { DiscoverTransactionButton } from 'x-pack/plugins/apm/public/components/shared/DiscoverButtons/DiscoverTransactionButton';
import { IUrlParams } from 'x-pack/plugins/apm/public/store/urlParams';
import { APM_AGENT_DROPPED_SPANS_DOCS } from 'x-pack/plugins/apm/public/utils/documentation/agents';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import { StickyTransactionProperties } from '../../../StickyTransactionProperties';
import { TransactionPropertiesTableForFlyout } from '../../../TransactionPropertiesTableForFlyout';
import { FlyoutTopLevelProperties } from '../FlyoutTopLevelProperties';
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
*/

import { groupBy } from 'lodash';
import { Span } from 'x-pack/plugins/apm/typings/Span';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Span } from 'x-pack/plugins/apm/typings/es_schemas/Span';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import {
getClockSkew,
getWaterfallItems,
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ import {
zipObject
} from 'lodash';
import { colors } from 'x-pack/plugins/apm/public/style/variables';
import { Span } from '../../../../../../../../typings/Span';
import { Transaction } from '../../../../../../../../typings/Transaction';
import { Span } from '../../../../../../../../typings/es_schemas/Span';
import { Transaction } from '../../../../../../../../typings/es_schemas/Transaction';

export interface IWaterfallIndex {
[key: string]: IWaterfallItem;
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import { getAgentMarks } from './get_agent_marks';

describe('getAgentMarks', () => {
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
*/

import { sortBy } from 'lodash';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';

export interface AgentMark {
name: string;
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import {
TRACE_ID,
TRANSACTION_ID
} from '../../../../../../common/constants';
import { Transaction } from '../../../../../../typings/Transaction';
import { Transaction } from '../../../../../../typings/es_schemas/Transaction';

import { EuiBadge, EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui';

Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import {
EuiToolTip
} from '@elastic/eui';
import React from 'react';
import { Transaction as ITransaction } from '../../../../../typings/Transaction';
import { Transaction as ITransaction } from '../../../../../typings/es_schemas/Transaction';
import { IUrlParams } from '../../../../store/urlParams';
import { DiscoverTransactionButton } from '../../../shared/DiscoverButtons/DiscoverTransactionButton';
import { TransactionLink } from '../../../shared/TransactionLink';
34 changes: 34 additions & 0 deletions x-pack/plugins/apm/public/components/shared/DiscoverButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.
*/

// @ts-ignore
import { EuiButtonEmpty } from '@elastic/eui';
import React from 'react';
import { StringMap } from 'x-pack/plugins/apm/typings/common';
import { KibanaLink } from '../../utils/url';

interface Props {
query: StringMap;
}

export const DiscoverButton: React.SFC<Props> = ({
query,
children,
...rest
}) => {
return (
<KibanaLink
pathname={'/app/kibana'}
hash={'/discover'}
query={query}
{...rest}
>
<EuiButtonEmpty iconType="discoverApp">
{children || 'View in Discover'}
</EuiButtonEmpty>
</KibanaLink>
);
};
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

import { EuiProgress } from '@elastic/eui';
import React from 'react';
import { StringMap } from '../../../../typings/common';
import { StringMap } from '../../../../typings/es_schemas/common';

// TODO: extend from EUI's EuiProgress prop interface
export interface ImpactBarProps extends StringMap<any> {
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
import { EuiBasicTable } from '@elastic/eui';
import { get, sortByOrder } from 'lodash';
import React, { Component } from 'react';
import { StringMap } from '../../../../typings/common';
import { StringMap } from '../../../../typings/es_schemas/common';

// TODO: this should really be imported from EUI
export interface ITableColumn {
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import _ from 'lodash';
import React from 'react';
import styled from 'styled-components';

import { StringMap } from '../../../../typings/common';
import { StringMap } from '../../../../typings/es_schemas/common';
import {
colors,
fontFamilyCode,
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import _ from 'lodash';
import React from 'react';
import styled from 'styled-components';

import { StringMap } from '../../../../typings/common';
import { StringMap } from '../../../../typings/es_schemas/common';
import {
colors,
fontSize,
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
*/

import React from 'react';
import { Transaction } from '../../../typings/Transaction';
import { Transaction } from '../../../typings/es_schemas/Transaction';
import { KibanaLink, legacyEncodeURIComponent } from '../../utils/url';

interface TransactionLinkProps {
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { StringMap } from 'x-pack/plugins/apm/typings/common';
import { StringMap } from 'x-pack/plugins/apm/typings/es_schemas/common';

export class SessionStorageMock {
private store: StringMap = {};
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/public/services/rest/apm/apm.ts
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Span } from 'x-pack/plugins/apm/typings/Span';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Span } from 'x-pack/plugins/apm/typings/es_schemas/Span';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import { convertKueryToEsQuery, getAPMIndexPatternForKuery } from '../../kuery';

export async function getEncodedEsQuery(kuery?: string) {
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

import { TransactionAPIResponse } from 'x-pack/plugins/apm/server/lib/transactions/get_transaction';
import { SpanListAPIResponse } from 'x-pack/plugins/apm/server/lib/transactions/spans/get_spans';
import { Span } from 'x-pack/plugins/apm/typings/Span';
import { Span } from 'x-pack/plugins/apm/typings/es_schemas/Span';
import { IUrlParams } from '../../../store/urlParams';
import { callApi } from '../callApi';
import { addVersion, getEncodedEsQuery } from './apm';
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

import React from 'react';
import { Request, RRRRender } from 'react-redux-request';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import { loadTransaction } from '../../services/rest/apm/transactions';
import { IReduxState } from '../rootReducer';
import { IUrlParams } from '../urlParams';
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

import React from 'react';
import { RRRRender } from 'react-redux-request';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import { IWaterfall } from '../../components/app/TransactionDetails/Transaction/WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers';
import { IUrlParams } from '../urlParams';
import { WaterfallV1Request } from './waterfallV1';
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ import {
SERVICE_NAME,
TRANSACTION_ID
} from 'x-pack/plugins/apm/common/constants';
import { Span } from 'x-pack/plugins/apm/typings/Span';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Span } from 'x-pack/plugins/apm/typings/es_schemas/Span';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import {
getWaterfall,
IWaterfall
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import React from 'react';
import { Request, RRRRender } from 'react-redux-request';
import { TRACE_ID } from 'x-pack/plugins/apm/common/constants';
import { TraceAPIResponse } from 'x-pack/plugins/apm/server/lib/traces/get_trace';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import {
getWaterfall,
IWaterfall
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/public/store/rootReducer.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

import { reducer } from 'react-redux-request';
import { combineReducers } from 'redux';
import { StringMap } from '../../typings/common';
import { StringMap } from '../../typings/es_schemas/common';
// @ts-ignore
import location from './location';
import { IUrlParams, urlParamsReducer } from './urlParams';
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import { rgba } from 'polished';
import { TimeSeriesAPIResponse } from 'x-pack/plugins/apm/server/lib/transactions/charts';
import { AnomalyTimeSeriesResponse } from 'x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform';
import { ApmTimeSeriesResponse } from 'x-pack/plugins/apm/server/lib/transactions/charts/get_timeseries_data/transform';
import { StringMap } from 'x-pack/plugins/apm/typings/common';
import { StringMap } from 'x-pack/plugins/apm/typings/es_schemas/common';
import {
Coordinate,
RectCoordinate
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/public/utils/url.tsx
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import { Link } from 'react-router-dom';
import rison from 'rison-node';
import chrome from 'ui/chrome';
import url from 'url';
import { StringMap } from '../../typings/common';
import { StringMap } from '../../typings/es_schemas/common';

// Kibana default set in: https://github.com/elastic/kibana/blob/e13e47fc4eb6112f2a5401408e9f765eae90f55d/x-pack/plugins/apm/public/utils/timepicker/index.js#L31-L35
// TODO: store this in config or a shared constant?
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/server/lib/traces/get_trace.ts
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@

import { SearchParams } from 'elasticsearch';
import { TRACE_ID } from '../../../common/constants';
import { Span } from '../../../typings/Span';
import { Transaction } from '../../../typings/Transaction';
import { Span } from '../../../typings/es_schemas/Span';
import { Transaction } from '../../../typings/es_schemas/Transaction';
import { Setup } from '../helpers/setup_request';

export type TraceAPIResponse = Array<Transaction | Span>;
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import {
TRANSACTION_DURATION,
TRANSACTION_NAME
} from '../../../common/constants';
import { Transaction } from '../../../typings/Transaction';
import { Transaction } from '../../../typings/es_schemas/Transaction';
import { Setup } from '../helpers/setup_request';

interface Bucket {
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

import moment from 'moment';
import { oc } from 'ts-optchain';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import { ESResponse } from './fetcher';

export interface ITransactionGroup {
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import {
TRANSACTION_TYPE
} from 'x-pack/plugins/apm/common/constants';
import { Setup } from 'x-pack/plugins/apm/server/lib/helpers/setup_request';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';

interface Bucket {
key: number;
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

import { SearchParams } from 'elasticsearch';
import { oc } from 'ts-optchain';
import { Transaction } from 'x-pack/plugins/apm/typings/Transaction';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';
import {
PROCESSOR_EVENT,
TRACE_ID,
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Span } from 'x-pack/plugins/apm/typings/Span';
import { Span } from 'x-pack/plugins/apm/typings/es_schemas/Span';
import {
PROCESSOR_EVENT,
SPAN_START,
46 changes: 0 additions & 46 deletions x-pack/plugins/apm/typings/Error.ts

This file was deleted.

File renamed without changes.
84 changes: 84 additions & 0 deletions x-pack/plugins/apm/typings/es_schemas/Error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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 { APMDocV1, APMDocV2, ContextService, Stackframe } from './APMDoc';

interface Agent {
hostname: string;
type: string;
version: string;
}

interface Processor {
name: 'error';
event: 'error';
}

interface Context {
process?: {
pid: number;
};
service: ContextService;
}

interface Exception {
message?: string; // either message or type are given
type?: string;
code?: string;
module?: string;
attributes?: unknown;
handled?: boolean;
stacktrace?: Stackframe[];
}

interface Log {
message: string;
param_message?: string;
logger_name?: string;
level?: string;
stacktrace?: Stackframe[];
}

interface ErrorV1 extends APMDocV1 {
version: 'v1';
agent: Agent;
processor: Processor;
context: Context;
transaction?: {
id: string; // transaction ID is not required in v1
};
error: {
id?: string; // ID is not required in v1
timestamp: string;
culprit: string;
grouping_key: string;
// either exception or log are given
exception?: Exception;
log?: Log;
};
}

interface ErrorV2 extends APMDocV2 {
version: 'v2';
agent: Agent;
processor: Processor;
context: Context;
transaction: {
id: string; // transaction ID is required in v2
};
error: {
id: string; // ID is required in v2
timestamp: string;
culprit: string;
grouping_key: string;
// either exception or log are given
exception?: Exception;
log?: Log;
};
}

// Not calling it "Error" to avoid clashes with types for native Error
export type APMError = ErrorV1 | ErrorV2;
File renamed without changes.
File renamed without changes.