[APM] Add metric type interface (#83039)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Dario Gieselaar 2020-11-11 08:58:35 +01:00 committed by GitHub
parent 34c80e5d7c
commit 7d3e19801f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 128 additions and 9 deletions

View file

@ -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,
@ -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'> & {
@ -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];

View file

@ -4,6 +4,8 @@
* 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;
@ -11,10 +13,10 @@ export interface APMBaseDoc {
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;
}

View file

@ -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';
@ -41,6 +41,7 @@ interface Log {
export interface ErrorRaw extends APMBaseDoc {
processor: Processor;
timestamp: TimestampUs;
transaction?: {
id: string;
sampled?: boolean;
@ -66,5 +67,4 @@ export interface ErrorRaw extends APMBaseDoc {
service: Service;
url?: Url;
user?: User;
observer?: Observer;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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';
@ -48,9 +48,9 @@ export interface SpanRaw extends APMBaseDoc {
headers?: Record<string, unknown>;
};
};
timestamp: TimestampUs;
transaction?: {
id: string;
};
observer?: Observer;
child?: { id: string[] };
}

View file

@ -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';
@ -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 };
@ -63,5 +64,4 @@ export interface TransactionRaw extends APMBaseDoc {
url?: Url;
user?: User;
user_agent?: UserAgent;
observer?: Observer;
}

View file

@ -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;