Skip to content

Commit 3456bb3

Browse files
[7.x] [APM] Add metric type interface (#83039) (#83146)
Co-authored-by: Kibana Machine <[email protected]> # Conflicts: # x-pack/plugins/apm/typings/es_schemas/raw/apm_base_doc.ts
1 parent 0fc82f1 commit 3456bb3

File tree

8 files changed

+128
-9
lines changed

8 files changed

+128
-9
lines changed

x-pack/plugins/apm/server/lib/helpers/create_es_client/create_apm_event_client/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import { ValuesType } from 'utility-types';
8-
import { APMBaseDoc } from '../../../../../typings/es_schemas/raw/apm_base_doc';
98
import { APMError } from '../../../../../typings/es_schemas/ui/apm_error';
109
import {
1110
KibanaRequest,
@@ -21,6 +20,7 @@ import { addFilterToExcludeLegacyData } from './add_filter_to_exclude_legacy_dat
2120
import { callClientWithDebug } from '../call_client_with_debug';
2221
import { Transaction } from '../../../../../typings/es_schemas/ui/transaction';
2322
import { Span } from '../../../../../typings/es_schemas/ui/span';
23+
import { Metric } from '../../../../../typings/es_schemas/ui/metric';
2424
import { unpackProcessorEvents } from './unpack_processor_events';
2525

2626
export type APMEventESSearchRequest = Omit<ESSearchRequest, 'index'> & {
@@ -33,7 +33,7 @@ type TypeOfProcessorEvent<T extends ProcessorEvent> = {
3333
[ProcessorEvent.error]: APMError;
3434
[ProcessorEvent.transaction]: Transaction;
3535
[ProcessorEvent.span]: Span;
36-
[ProcessorEvent.metric]: APMBaseDoc;
36+
[ProcessorEvent.metric]: Metric;
3737
[ProcessorEvent.onboarding]: unknown;
3838
[ProcessorEvent.sourcemap]: unknown;
3939
}[T];

x-pack/plugins/apm/typings/es_schemas/raw/apm_base_doc.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { Observer } from './fields/observer';
8+
79
// all documents types extend APMBaseDoc and inherit all properties
810
export interface APMBaseDoc {
911
'@timestamp': string;
1012
agent: {
1113
name: string;
1214
version: string;
1315
};
14-
timestamp: { us: number };
1516
parent?: { id: string }; // parent ID is not available on root transactions
1617
trace?: { id: string };
1718
labels?: {
1819
[key: string]: string | number | boolean;
1920
};
2021
[key: string]: unknown;
22+
observer?: Observer;
2123
}

x-pack/plugins/apm/typings/es_schemas/raw/error_raw.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { Page } from './fields/page';
1313
import { Process } from './fields/process';
1414
import { Service } from './fields/service';
1515
import { Stackframe } from './fields/stackframe';
16+
import { TimestampUs } from './fields/timestamp_us';
1617
import { Url } from './fields/url';
1718
import { User } from './fields/user';
18-
import { Observer } from './fields/observer';
1919

2020
interface Processor {
2121
name: 'error';
@@ -43,6 +43,7 @@ interface Log {
4343

4444
export interface ErrorRaw extends APMBaseDoc {
4545
processor: Processor;
46+
timestamp: TimestampUs;
4647
transaction?: {
4748
id: string;
4849
sampled?: boolean;
@@ -69,5 +70,4 @@ export interface ErrorRaw extends APMBaseDoc {
6970
service: Service;
7071
url?: Url;
7172
user?: User;
72-
observer?: Observer;
7373
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export interface TimestampUs {
8+
us: number;
9+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { APMBaseDoc } from './apm_base_doc';
8+
import { Container } from './fields/container';
9+
import { Kubernetes } from './fields/kubernetes';
10+
11+
type BaseMetric = APMBaseDoc & {
12+
processor: {
13+
name: 'metric';
14+
event: 'metric';
15+
};
16+
};
17+
18+
type BaseBreakdownMetric = BaseMetric & {
19+
transaction: {
20+
name: string;
21+
type: string;
22+
};
23+
span: {
24+
self_time: {
25+
count: number;
26+
sum: {
27+
us: number;
28+
};
29+
};
30+
};
31+
};
32+
33+
type TransactionBreakdownMetric = BaseBreakdownMetric & {
34+
transaction: {
35+
duration: {
36+
count: number;
37+
sum: {
38+
us: number;
39+
};
40+
};
41+
breakdown: {
42+
count: number;
43+
};
44+
};
45+
};
46+
47+
type SpanBreakdownMetric = BaseBreakdownMetric & {
48+
span: {
49+
type: string;
50+
subtype?: string;
51+
};
52+
};
53+
54+
type SystemMetric = BaseMetric & {
55+
system: unknown;
56+
service: {
57+
node?: {
58+
name: string;
59+
};
60+
};
61+
};
62+
63+
type CGroupMetric = SystemMetric;
64+
type JVMMetric = SystemMetric & {
65+
jvm: unknown;
66+
};
67+
68+
type TransactionDurationMetric = BaseMetric & {
69+
transaction: {
70+
name: string;
71+
type: string;
72+
result?: string;
73+
duration: {
74+
histogram: {
75+
values: number[];
76+
counts: number[];
77+
};
78+
};
79+
};
80+
service: {
81+
name: string;
82+
node?: {
83+
name: string;
84+
};
85+
environment?: string;
86+
version?: string;
87+
};
88+
container?: Container;
89+
kubernetes?: Kubernetes;
90+
};
91+
92+
export type MetricRaw =
93+
| BaseMetric
94+
| TransactionBreakdownMetric
95+
| SpanBreakdownMetric
96+
| TransactionDurationMetric
97+
| SystemMetric
98+
| CGroupMetric
99+
| JVMMetric;

x-pack/plugins/apm/typings/es_schemas/raw/span_raw.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { APMBaseDoc } from './apm_base_doc';
88
import { Stackframe } from './fields/stackframe';
9-
import { Observer } from './fields/observer';
9+
import { TimestampUs } from './fields/timestamp_us';
1010

1111
interface Processor {
1212
name: 'transaction';
@@ -50,9 +50,9 @@ export interface SpanRaw extends APMBaseDoc {
5050
headers?: Record<string, unknown>;
5151
};
5252
};
53+
timestamp: TimestampUs;
5354
transaction?: {
5455
id: string;
5556
};
56-
observer?: Observer;
5757
child?: { id: string[] };
5858
}

x-pack/plugins/apm/typings/es_schemas/raw/transaction_raw.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { Kubernetes } from './fields/kubernetes';
1212
import { Page } from './fields/page';
1313
import { Process } from './fields/process';
1414
import { Service } from './fields/service';
15+
import { TimestampUs } from './fields/timestamp_us';
1516
import { Url } from './fields/url';
1617
import { User } from './fields/user';
1718
import { UserAgent } from './fields/user_agent';
18-
import { Observer } from './fields/observer';
1919

2020
interface Processor {
2121
name: 'transaction';
@@ -24,6 +24,7 @@ interface Processor {
2424

2525
export interface TransactionRaw extends APMBaseDoc {
2626
processor: Processor;
27+
timestamp: TimestampUs;
2728
trace: { id: string }; // trace is required
2829
transaction: {
2930
duration: { us: number };
@@ -65,5 +66,4 @@ export interface TransactionRaw extends APMBaseDoc {
6566
url?: Url;
6667
user?: User;
6768
user_agent?: UserAgent;
68-
observer?: Observer;
6969
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { MetricRaw } from '../raw/metric_raw';
8+
9+
export type Metric = MetricRaw;

0 commit comments

Comments
 (0)