Skip to content

Commit

Permalink
[APM] Add metric type interface (#83039)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
dgieselaar and kibanamachine authored Nov 11, 2020
1 parent 34c80e5 commit 7d3e198
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { ValuesType } from 'utility-types';
import { APMBaseDoc } from '../../../../../typings/es_schemas/raw/apm_base_doc';
import { APMError } from '../../../../../typings/es_schemas/ui/apm_error';
import {
KibanaRequest,
Expand All @@ -21,6 +20,7 @@ import { addFilterToExcludeLegacyData } from './add_filter_to_exclude_legacy_dat
import { callClientWithDebug } from '../call_client_with_debug';
import { Transaction } from '../../../../../typings/es_schemas/ui/transaction';
import { Span } from '../../../../../typings/es_schemas/ui/span';
import { Metric } from '../../../../../typings/es_schemas/ui/metric';
import { unpackProcessorEvents } from './unpack_processor_events';

export type APMEventESSearchRequest = Omit<ESSearchRequest, 'index'> & {
Expand All @@ -33,7 +33,7 @@ type TypeOfProcessorEvent<T extends ProcessorEvent> = {
[ProcessorEvent.error]: APMError;
[ProcessorEvent.transaction]: Transaction;
[ProcessorEvent.span]: Span;
[ProcessorEvent.metric]: APMBaseDoc;
[ProcessorEvent.metric]: Metric;
[ProcessorEvent.onboarding]: unknown;
[ProcessorEvent.sourcemap]: unknown;
}[T];
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/apm/typings/es_schemas/raw/apm_base_doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Observer } from './fields/observer';

// all documents types extend APMBaseDoc and inherit all properties
export interface APMBaseDoc {
'@timestamp': string;
agent: {
name: string;
version: string;
};
timestamp: { us: number };
parent?: { id: string }; // parent ID is not available on root transactions
trace?: { id: string };
labels?: {
[key: string]: string | number | boolean;
};
observer?: Observer;
}
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/typings/es_schemas/raw/error_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { Page } from './fields/page';
import { Process } from './fields/process';
import { Service } from './fields/service';
import { Stackframe } from './fields/stackframe';
import { TimestampUs } from './fields/timestamp_us';
import { Url } from './fields/url';
import { User } from './fields/user';
import { Observer } from './fields/observer';

interface Processor {
name: 'error';
Expand All @@ -41,6 +41,7 @@ interface Log {

export interface ErrorRaw extends APMBaseDoc {
processor: Processor;
timestamp: TimestampUs;
transaction?: {
id: string;
sampled?: boolean;
Expand All @@ -66,5 +67,4 @@ export interface ErrorRaw extends APMBaseDoc {
service: Service;
url?: Url;
user?: User;
observer?: Observer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

export interface TimestampUs {
us: number;
}
99 changes: 99 additions & 0 deletions x-pack/plugins/apm/typings/es_schemas/raw/metric_raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* 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 { APMBaseDoc } from './apm_base_doc';
import { Container } from './fields/container';
import { Kubernetes } from './fields/kubernetes';

type BaseMetric = APMBaseDoc & {
processor: {
name: 'metric';
event: 'metric';
};
};

type BaseBreakdownMetric = BaseMetric & {
transaction: {
name: string;
type: string;
};
span: {
self_time: {
count: number;
sum: {
us: number;
};
};
};
};

type TransactionBreakdownMetric = BaseBreakdownMetric & {
transaction: {
duration: {
count: number;
sum: {
us: number;
};
};
breakdown: {
count: number;
};
};
};

type SpanBreakdownMetric = BaseBreakdownMetric & {
span: {
type: string;
subtype?: string;
};
};

type SystemMetric = BaseMetric & {
system: unknown;
service: {
node?: {
name: string;
};
};
};

type CGroupMetric = SystemMetric;
type JVMMetric = SystemMetric & {
jvm: unknown;
};

type TransactionDurationMetric = BaseMetric & {
transaction: {
name: string;
type: string;
result?: string;
duration: {
histogram: {
values: number[];
counts: number[];
};
};
};
service: {
name: string;
node?: {
name: string;
};
environment?: string;
version?: string;
};
container?: Container;
kubernetes?: Kubernetes;
};

export type MetricRaw =
| BaseMetric
| TransactionBreakdownMetric
| SpanBreakdownMetric
| TransactionDurationMetric
| SystemMetric
| CGroupMetric
| JVMMetric;
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/typings/es_schemas/raw/span_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { APMBaseDoc } from './apm_base_doc';
import { Stackframe } from './fields/stackframe';
import { Observer } from './fields/observer';
import { TimestampUs } from './fields/timestamp_us';

interface Processor {
name: 'transaction';
Expand Down Expand Up @@ -48,9 +48,9 @@ export interface SpanRaw extends APMBaseDoc {
headers?: Record<string, unknown>;
};
};
timestamp: TimestampUs;
transaction?: {
id: string;
};
observer?: Observer;
child?: { id: string[] };
}
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/typings/es_schemas/raw/transaction_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { Kubernetes } from './fields/kubernetes';
import { Page } from './fields/page';
import { Process } from './fields/process';
import { Service } from './fields/service';
import { TimestampUs } from './fields/timestamp_us';
import { Url } from './fields/url';
import { User } from './fields/user';
import { UserAgent } from './fields/user_agent';
import { Observer } from './fields/observer';

interface Processor {
name: 'transaction';
Expand All @@ -24,6 +24,7 @@ interface Processor {

export interface TransactionRaw extends APMBaseDoc {
processor: Processor;
timestamp: TimestampUs;
trace: { id: string }; // trace is required
transaction: {
duration: { us: number };
Expand Down Expand Up @@ -63,5 +64,4 @@ export interface TransactionRaw extends APMBaseDoc {
url?: Url;
user?: User;
user_agent?: UserAgent;
observer?: Observer;
}
9 changes: 9 additions & 0 deletions x-pack/plugins/apm/typings/es_schemas/ui/metric.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 { MetricRaw } from '../raw/metric_raw';

export type Metric = MetricRaw;

0 comments on commit 7d3e198

Please sign in to comment.