Skip to content

Commit

Permalink
Added type safety to property config
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Jan 23, 2019
1 parent 78c5fe9 commit 7bd8798
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ exports[`Error METRIC_SYSTEM_FREE_MEMORY 1`] = `undefined`;

exports[`Error METRIC_SYSTEM_TOTAL_MEMORY 1`] = `undefined`;

exports[`Error OBSERVER_LISTENING 1`] = `undefined`;

exports[`Error PARENT_ID 1`] = `"parentId"`;

exports[`Error PROCESSOR_EVENT 1`] = `"error"`;
Expand Down Expand Up @@ -96,6 +98,8 @@ exports[`Span METRIC_SYSTEM_FREE_MEMORY 1`] = `undefined`;

exports[`Span METRIC_SYSTEM_TOTAL_MEMORY 1`] = `undefined`;

exports[`Span OBSERVER_LISTENING 1`] = `undefined`;

exports[`Span PARENT_ID 1`] = `"parentId"`;

exports[`Span PROCESSOR_EVENT 1`] = `"span"`;
Expand Down Expand Up @@ -166,6 +170,8 @@ exports[`Transaction METRIC_SYSTEM_FREE_MEMORY 1`] = `undefined`;

exports[`Transaction METRIC_SYSTEM_TOTAL_MEMORY 1`] = `undefined`;

exports[`Transaction OBSERVER_LISTENING 1`] = `undefined`;

exports[`Transaction PARENT_ID 1`] = `"parentId"`;

exports[`Transaction PROCESSOR_EVENT 1`] = `"transaction"`;
Expand Down
16 changes: 10 additions & 6 deletions x-pack/plugins/apm/common/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ describe('Transaction', () => {
name: 'agent name',
version: 'agent version'
},
http: { request: { method: 'GET' } },
http: {
request: { method: 'GET' },
response: { status_code: 200 }
},
url: { full: 'http://www.elastic.co' },
service: {
name: 'service name',
Expand Down Expand Up @@ -93,12 +96,13 @@ describe('Span', () => {
id: 'parentId'
},
span: {
duration: {
us: 1337
},
action: 'my action',
duration: { us: 1337 },
id: 'span id',
name: 'span name',
type: 'span type',
id: 'span id'
subtype: 'my subtype',
sync: false,
type: 'span type'
},
transaction: {
id: 'transaction id'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,10 @@ exports[`DetailView should render tabs 1`] = `
<EuiTab
disabled={false}
isSelected={false}
key="tags"
key="labels"
onClick={[Function]}
>
Tags
</EuiTab>
<EuiTab
disabled={false}
isSelected={false}
key="custom"
onClick={[Function]}
>
Custom
Labels
</EuiTab>
</EuiTabs>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,83 @@
*/

import { i18n } from '@kbn/i18n';
import { APMError } from 'x-pack/plugins/apm/typings/es_schemas/Error';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/Transaction';

export interface TabWithKey {
export interface Tab {
key: string;
label: string;
required: boolean;
presortedKeys: string[];
}

export interface Tab {
key: string;
type AllKeys = keyof NonNullable<Transaction> | keyof NonNullable<APMError>;
interface ConfigItem<T extends AllKeys> {
key: T;
label: string;
required: boolean;
presortedKeys: Array<
T extends keyof Transaction
? keyof NonNullable<Transaction[T]>
: T extends keyof APMError
? keyof NonNullable<APMError[T]>
: never
>;
}

export const PROPERTY_CONFIG: TabWithKey[] = [
export const PROPERTY_CONFIG = [
{
key: 'url',
label: i18n.translate('xpack.apm.propertiesTable.tabs.urlLabel', {
defaultMessage: 'Url'
}),
required: false,
presortedKeys: [
'http_version',
'method',
'url',
'socket',
'headers',
'body'
]
},
presortedKeys: []
} as ConfigItem<'url'>,
{
key: 'http',
label: i18n.translate('xpack.apm.propertiesTable.tabs.httpLabel', {
defaultMessage: 'HTTP'
}),
required: false,
presortedKeys: ['status_code', 'headers', 'headers_sent', 'finished']
},
presortedKeys: []
} as ConfigItem<'http'>,
{
key: 'system',
label: i18n.translate('xpack.apm.propertiesTable.tabs.systemLabel', {
defaultMessage: 'System'
key: 'host',
label: i18n.translate('xpack.apm.propertiesTable.tabs.hostLabel', {
defaultMessage: 'Host'
}),
required: false,
presortedKeys: ['hostname', 'architecture', 'platform']
},
} as ConfigItem<'host'>,
{
key: 'service',
label: i18n.translate('xpack.apm.propertiesTable.tabs.serviceLabel', {
defaultMessage: 'Service'
}),
required: false,
presortedKeys: ['runtime', 'framework', 'agent', 'version']
},
} as ConfigItem<'service'>,
{
key: 'process',
label: i18n.translate('xpack.apm.propertiesTable.tabs.processLabel', {
defaultMessage: 'Process'
}),
required: false,
presortedKeys: ['pid', 'title', 'argv']
},
presortedKeys: ['pid', 'title', 'args']
} as ConfigItem<'process'>,
{
key: 'user',
label: i18n.translate('xpack.apm.propertiesTable.tabs.userLabel', {
defaultMessage: 'User'
}),
required: true,
presortedKeys: ['id', 'username', 'email']
},
{
key: 'tags',
label: i18n.translate('xpack.apm.propertiesTable.tabs.tagsLabel', {
defaultMessage: 'Tags'
}),
required: true,
presortedKeys: []
},
} as ConfigItem<'user'>,
{
key: 'custom',
label: i18n.translate('xpack.apm.propertiesTable.tabs.customLabel', {
defaultMessage: 'Custom'
key: 'labels',
label: i18n.translate('xpack.apm.propertiesTable.tabs.labelsLabel', {
defaultMessage: 'Labels'
}),
required: true,
presortedKeys: []
}
} as ConfigItem<'labels'>
];
15 changes: 8 additions & 7 deletions x-pack/plugins/apm/typings/es_schemas/APMDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ export interface Context {
[key: string]: unknown;
}

// TODO: APMDoc should perhaps only be the base for errors and transactions. Not spans
export interface APMDoc {
'@timestamp': string;
host?: {
architecture?: string;
hostname?: string;
ip?: string;
os?: {
platform?: string;
};
os?: { platform?: string };
};
agent: {
name: string;
Expand All @@ -29,9 +28,8 @@ export interface APMDoc {
full: string;
};
http?: {
request: {
method: string;
};
request: { method: string };
response: { status_code: number };
};
service: {
name: string;
Expand All @@ -52,7 +50,7 @@ export interface APMDoc {
process?: {
pid: number;
title: string;
argv: string[];
args: string[];
[key: string]: unknown;
};
timestamp: {
Expand All @@ -69,5 +67,8 @@ export interface APMDoc {
username?: string;
email?: string;
};
labels?: {
[key: string]: unknown;
};
context?: Context;
}
16 changes: 10 additions & 6 deletions x-pack/plugins/apm/typings/es_schemas/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface Processor {
event: 'span';
}

// TODO: should spanContext extend shared context?
interface SpanContext extends Context {
db?: {
instance?: string;
Expand All @@ -20,24 +21,27 @@ interface SpanContext extends Context {
user?: string;
};
http?: {
method?: string;
status_code?: number;
url?: string;
};
tags?: {
[key: string]: string;
[key: string]: string; // is this always a string?
};
}

export interface Span extends APMDoc {
processor: Processor;
context?: SpanContext;
span: {
duration: {
us: number;
};
name: string;
type: string;
action: string;
duration: { us: number };
id: string;
name: string;
stacktrace?: IStackframe[];
subtype: string;
sync: boolean;
type: string;
};
transaction: {
id: string;
Expand Down

0 comments on commit 7bd8798

Please sign in to comment.