Skip to content

Commit

Permalink
Implement HTTP API versioned types in usage collection plugin (#152875)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
TinaHeiligers and kibanamachine authored Mar 9, 2023
1 parent 48b3b90 commit 8a9789b
Show file tree
Hide file tree
Showing 21 changed files with 499 additions and 69 deletions.
11 changes: 11 additions & 0 deletions src/plugins/usage_collection/common/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * as Stats from './stats';
export * as UiCounters from './ui_counters';
export * as UsageCounters from './usage_counters';
219 changes: 219 additions & 0 deletions src/plugins/usage_collection/common/types/stats/core_metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

/**
* The types are exact duplicates of the ops metrics types declared in core needed for reporting in the stats api.
* We use a copy of these to detect changes in the ops metrics reported from core
* See packages/core/metrics/core-metrics-server/index.ts
*/

/**
* an IntervalHistogram object that samples and reports the event loop delay over time.
* The delays will be reported in milliseconds.
* See {@link IntervalHistogram}
* @public
*/
export interface IntervalHistogram {
// The first timestamp the interval timer kicked in for collecting data points.
fromTimestamp: string;
// Last timestamp the interval timer kicked in for collecting data points.
lastUpdatedAt: string;
// The minimum recorded event loop delay.
min: number;
// The maximum recorded event loop delay.
max: number;
// The mean of the recorded event loop delays.
mean: number;
// The number of times the event loop delay exceeded the maximum 1 hour event loop delay threshold.
exceeds: number;
// The standard deviation of the recorded event loop delays.
stddev: number;
// An object detailing the accumulated percentile distribution.
percentiles: {
// 50th percentile of delays of the collected data points.
50: number;
// 75th percentile of delays of the collected data points.
75: number;
// 95th percentile of delays of the collected data points.
95: number;
// 99th percentile of delays of the collected data points.
99: number;
};
}

/**
* See {@link ElasticsearchClientProtocol}
* Protocol(s) used by the Elasticsearch Client
* @public
*/

export type ElasticsearchClientProtocol = 'none' | 'http' | 'https' | 'mixed';

/**
* See {@link ElasticsearchClientsMetrics}
* Metrics related to the elasticsearch clients
* @public
*/
export interface ElasticsearchClientsMetrics {
/** Total number of active sockets (all nodes, all connections) */
totalActiveSockets: number;
/** Total number of available sockets (alive but idle, all nodes, all connections) */
totalIdleSockets: number;
/** Total number of queued requests (all nodes, all connections) */
totalQueuedRequests: number;
}

/**
* See {@link OpsProcessMetrics}
* Process related metrics
* @public
*/
export interface OpsProcessMetrics {
/** pid of the kibana process */
pid: number;
/** process memory usage */
memory: {
/** heap memory usage */
heap: {
/** total heap available */
total_in_bytes: number;
/** used heap */
used_in_bytes: number;
/** v8 heap size limit */
size_limit: number;
};
/** node rss */
resident_set_size_in_bytes: number;
};
/** mean event loop delay since last collection*/
event_loop_delay: number;
/** node event loop delay histogram since last collection */
event_loop_delay_histogram: IntervalHistogram;
/** uptime of the kibana process */
uptime_in_millis: number;
}

/**
* See {@link OpsOsMetrics}
* OS related metrics
* @public
*/
export interface OpsOsMetrics {
/** The os platform */
platform: NodeJS.Platform;
/** The os platform release, prefixed by the platform name */
platformRelease: string;
/** The os distrib. Only present for linux platforms */
distro?: string;
/** The os distrib release, prefixed by the os distrib. Only present for linux platforms */
distroRelease?: string;
/** cpu load metrics */
load: {
/** load for last minute */
'1m': number;
/** load for last 5 minutes */
'5m': number;
/** load for last 15 minutes */
'15m': number;
};
/** system memory usage metrics */
memory: {
/** total memory available */
total_in_bytes: number;
/** current free memory */
free_in_bytes: number;
/** current used memory */
used_in_bytes: number;
};
/** the OS uptime */
uptime_in_millis: number;

/** cpu accounting metrics, undefined when not running in a cgroup */
cpuacct?: {
/** name of this process's cgroup */
control_group: string;
/** cpu time used by this process's cgroup */
usage_nanos: number;
};

/** cpu cgroup metrics, undefined when not running in a cgroup */
cpu?: {
/** name of this process's cgroup */
control_group: string;
/** the length of the cfs period */
cfs_period_micros: number;
/** total available run-time within a cfs period */
cfs_quota_micros: number;
/** current stats on the cfs periods */
stat: {
/** number of cfs periods that elapsed */
number_of_elapsed_periods: number;
/** number of times the cgroup has been throttled */
number_of_times_throttled: number;
/** total amount of time the cgroup has been throttled for */
time_throttled_nanos: number;
};
};
}

/**
* {@link OpsServerMetrics}
* server related metrics
* @public
*/
export interface OpsServerMetrics {
/** server response time stats */
response_times: {
/** average response time */
avg_in_millis: number;
/** maximum response time */
max_in_millis: number;
};
/** server requests stats */
requests: {
/** number of disconnected requests since startup */
disconnects: number;
/** total number of requests handled since startup */
total: number;
/** number of request handled per response status code */
statusCodes: Record<number, number>;
};
/** number of current concurrent connections to the server */
concurrent_connections: number;
}

/**
* {@link OpsMetrics}
* Regroups metrics gathered by all the collectors.
* This contains metrics about the os/runtime, the kibana process and the http server.
* @public
*/
export interface OpsMetrics {
/** Time metrics were recorded at. */
collected_at: Date;
/**
* Metrics related to the elasticsearch client
*/
elasticsearch_client: ElasticsearchClientsMetrics;
/**
* Process related metrics.
* @remarks processes field preferred
*/
process: OpsProcessMetrics;
/** Process related metrics. Reports an array of objects for each kibana pid.*/
processes: OpsProcessMetrics[];
/** OS related metrics */
os: OpsOsMetrics;
/** server response time stats */
response_times: OpsServerMetrics['response_times'];
/** server requests stats */
requests: OpsServerMetrics['requests'];
/** number of current concurrent connections to the server */
concurrent_connections: OpsServerMetrics['concurrent_connections'];
}
10 changes: 10 additions & 0 deletions src/plugins/usage_collection/common/types/stats/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * as v1 from './v1';
export * from './latest';
9 changes: 9 additions & 0 deletions src/plugins/usage_collection/common/types/stats/latest.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
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
export * as OpsMetricsCopy from './core_metrics';
export * from './v1';
70 changes: 70 additions & 0 deletions src/plugins/usage_collection/common/types/stats/v1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import * as OpsMetricsCopy from './core_metrics';

/** v1 types Start */
/**
* stats query v1
* @remarks exclude_usage is always interpreted as true. query param retained to prevent breaking changes to existing consumers.
*/
export interface StatsHTTPQuery {
extended?: boolean | '';
legacy?: boolean | '';
exclude_usage?: boolean | '';
}

export interface UsageObject {
kibana?: UsageObject;
xpack?: UsageObject;
[key: string]: unknown | UsageObject;
}

export interface ClusterUuidLegacy {
clusterUuid?: string;
}
export interface ClusterUuid {
cluster_uuid?: string;
}
/**
* Extended usage stats.
* @remarks
* Legacy implementation used to conditionally include kibana usage metrics
* as of https://github.com/elastic/kibana/pull/151082, usage is no longer reported
* and set to an empty object to prevent breaking changes to existing consumers.
*/
export interface ExtendedStats {
[key: string]: unknown | UsageObject;
clusterUuid?: string; // camel case if legacy === true
cluster_uuid?: string; // snake_case if legacy === false
}
/**
* OpsMetrics: aliased from a duplicate of core's OpsMetrics types
* @remarks the alternative to creating a local copy of the OpsMetrics types is to declare them as `unknown` and assume validation happens elsewhere.
* The disadvantage is that any changes made to the original OpsMetrics will be passed through without needing to update the API types.
*/
export type LastOpsMetrics = OpsMetricsCopy.OpsMetrics;

export type KibanaServiceStatus = Record<string, string>;
/** explicitly typed stats for kibana */
export interface KibanaStats {
// kibana
kibana: {
uuid: string;
name: string;
index: string;
host: string;
locale: string;
transport_address: string;
version: string;
snapshot: boolean;
status: string;
};
}
/** Stats response body */
export type StatsHTTPBodyTyped = LastOpsMetrics | KibanaStats | ExtendedStats;
10 changes: 10 additions & 0 deletions src/plugins/usage_collection/common/types/ui_counters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * as v1 from './v1';
export * from './latest';
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
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * as v1 from './v1';
Loading

0 comments on commit 8a9789b

Please sign in to comment.