mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Migrate core's metrics service to packages (#136909)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
9792c748c6
commit
d80890467f
84 changed files with 1242 additions and 234 deletions
10
package.json
10
package.json
|
@ -213,6 +213,11 @@
|
||||||
"@kbn/core-logging-server": "link:bazel-bin/packages/core/logging/core-logging-server",
|
"@kbn/core-logging-server": "link:bazel-bin/packages/core/logging/core-logging-server",
|
||||||
"@kbn/core-logging-server-internal": "link:bazel-bin/packages/core/logging/core-logging-server-internal",
|
"@kbn/core-logging-server-internal": "link:bazel-bin/packages/core/logging/core-logging-server-internal",
|
||||||
"@kbn/core-logging-server-mocks": "link:bazel-bin/packages/core/logging/core-logging-server-mocks",
|
"@kbn/core-logging-server-mocks": "link:bazel-bin/packages/core/logging/core-logging-server-mocks",
|
||||||
|
"@kbn/core-metrics-collectors-server-internal": "link:bazel-bin/packages/core/metrics/core-metrics-collectors-server-internal",
|
||||||
|
"@kbn/core-metrics-collectors-server-mocks": "link:bazel-bin/packages/core/metrics/core-metrics-collectors-server-mocks",
|
||||||
|
"@kbn/core-metrics-server": "link:bazel-bin/packages/core/metrics/core-metrics-server",
|
||||||
|
"@kbn/core-metrics-server-internal": "link:bazel-bin/packages/core/metrics/core-metrics-server-internal",
|
||||||
|
"@kbn/core-metrics-server-mocks": "link:bazel-bin/packages/core/metrics/core-metrics-server-mocks",
|
||||||
"@kbn/core-node-server": "link:bazel-bin/packages/core/node/core-node-server",
|
"@kbn/core-node-server": "link:bazel-bin/packages/core/node/core-node-server",
|
||||||
"@kbn/core-node-server-internal": "link:bazel-bin/packages/core/node/core-node-server-internal",
|
"@kbn/core-node-server-internal": "link:bazel-bin/packages/core/node/core-node-server-internal",
|
||||||
"@kbn/core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks",
|
"@kbn/core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks",
|
||||||
|
@ -808,6 +813,11 @@
|
||||||
"@types/kbn__core-logging-server": "link:bazel-bin/packages/core/logging/core-logging-server/npm_module_types",
|
"@types/kbn__core-logging-server": "link:bazel-bin/packages/core/logging/core-logging-server/npm_module_types",
|
||||||
"@types/kbn__core-logging-server-internal": "link:bazel-bin/packages/core/logging/core-logging-server-internal/npm_module_types",
|
"@types/kbn__core-logging-server-internal": "link:bazel-bin/packages/core/logging/core-logging-server-internal/npm_module_types",
|
||||||
"@types/kbn__core-logging-server-mocks": "link:bazel-bin/packages/core/logging/core-logging-server-mocks/npm_module_types",
|
"@types/kbn__core-logging-server-mocks": "link:bazel-bin/packages/core/logging/core-logging-server-mocks/npm_module_types",
|
||||||
|
"@types/kbn__core-metrics-collectors-server-internal": "link:bazel-bin/packages/core/metrics/core-metrics-collectors-server-internal/npm_module_types",
|
||||||
|
"@types/kbn__core-metrics-collectors-server-mocks": "link:bazel-bin/packages/core/metrics/core-metrics-collectors-server-mocks/npm_module_types",
|
||||||
|
"@types/kbn__core-metrics-server": "link:bazel-bin/packages/core/metrics/core-metrics-server/npm_module_types",
|
||||||
|
"@types/kbn__core-metrics-server-internal": "link:bazel-bin/packages/core/metrics/core-metrics-server-internal/npm_module_types",
|
||||||
|
"@types/kbn__core-metrics-server-mocks": "link:bazel-bin/packages/core/metrics/core-metrics-server-mocks/npm_module_types",
|
||||||
"@types/kbn__core-node-server": "link:bazel-bin/packages/core/node/core-node-server/npm_module_types",
|
"@types/kbn__core-node-server": "link:bazel-bin/packages/core/node/core-node-server/npm_module_types",
|
||||||
"@types/kbn__core-node-server-internal": "link:bazel-bin/packages/core/node/core-node-server-internal/npm_module_types",
|
"@types/kbn__core-node-server-internal": "link:bazel-bin/packages/core/node/core-node-server-internal/npm_module_types",
|
||||||
"@types/kbn__core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks/npm_module_types",
|
"@types/kbn__core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks/npm_module_types",
|
||||||
|
|
|
@ -81,6 +81,11 @@ filegroup(
|
||||||
"//packages/core/logging/core-logging-server-internal:build",
|
"//packages/core/logging/core-logging-server-internal:build",
|
||||||
"//packages/core/logging/core-logging-server-mocks:build",
|
"//packages/core/logging/core-logging-server-mocks:build",
|
||||||
"//packages/core/logging/core-logging-server:build",
|
"//packages/core/logging/core-logging-server:build",
|
||||||
|
"//packages/core/metrics/core-metrics-collectors-server-internal:build",
|
||||||
|
"//packages/core/metrics/core-metrics-collectors-server-mocks:build",
|
||||||
|
"//packages/core/metrics/core-metrics-server-internal:build",
|
||||||
|
"//packages/core/metrics/core-metrics-server-mocks:build",
|
||||||
|
"//packages/core/metrics/core-metrics-server:build",
|
||||||
"//packages/core/node/core-node-server-internal:build",
|
"//packages/core/node/core-node-server-internal:build",
|
||||||
"//packages/core/node/core-node-server-mocks:build",
|
"//packages/core/node/core-node-server-mocks:build",
|
||||||
"//packages/core/node/core-node-server:build",
|
"//packages/core/node/core-node-server:build",
|
||||||
|
@ -301,6 +306,11 @@ filegroup(
|
||||||
"//packages/core/logging/core-logging-server-internal:build_types",
|
"//packages/core/logging/core-logging-server-internal:build_types",
|
||||||
"//packages/core/logging/core-logging-server-mocks:build_types",
|
"//packages/core/logging/core-logging-server-mocks:build_types",
|
||||||
"//packages/core/logging/core-logging-server:build_types",
|
"//packages/core/logging/core-logging-server:build_types",
|
||||||
|
"//packages/core/metrics/core-metrics-collectors-server-internal:build_types",
|
||||||
|
"//packages/core/metrics/core-metrics-collectors-server-mocks:build_types",
|
||||||
|
"//packages/core/metrics/core-metrics-server-internal:build_types",
|
||||||
|
"//packages/core/metrics/core-metrics-server-mocks:build_types",
|
||||||
|
"//packages/core/metrics/core-metrics-server:build_types",
|
||||||
"//packages/core/node/core-node-server-internal:build_types",
|
"//packages/core/node/core-node-server-internal:build_types",
|
||||||
"//packages/core/node/core-node-server-mocks:build_types",
|
"//packages/core/node/core-node-server-mocks:build_types",
|
||||||
"//packages/core/node/core-node-server:build_types",
|
"//packages/core/node/core-node-server:build_types",
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_config")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||||
|
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
|
||||||
|
|
||||||
|
PKG_DIRNAME = "core-metrics-collectors-server-internal"
|
||||||
|
PKG_REQUIRE_NAME = "@kbn/core-metrics-collectors-server-internal"
|
||||||
|
|
||||||
|
SOURCE_FILES = glob(
|
||||||
|
[
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/*.stories.*",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
SRCS = SOURCE_FILES
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "srcs",
|
||||||
|
srcs = SRCS,
|
||||||
|
)
|
||||||
|
|
||||||
|
NPM_MODULE_EXTRA_FILES = [
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
RUNTIME_DEPS = [
|
||||||
|
"//packages/kbn-logging",
|
||||||
|
"@npm//moment",
|
||||||
|
"@npm//getos",
|
||||||
|
]
|
||||||
|
|
||||||
|
TYPES_DEPS = [
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/jest",
|
||||||
|
"@npm//moment",
|
||||||
|
"@npm//@types/getos",
|
||||||
|
"@npm//@hapi/hapi",
|
||||||
|
"@npm//@types/hapi__hapi",
|
||||||
|
"//packages/kbn-logging:npm_module_types",
|
||||||
|
"//packages/core/metrics/core-metrics-server:npm_module_types",
|
||||||
|
]
|
||||||
|
|
||||||
|
jsts_transpiler(
|
||||||
|
name = "target_node",
|
||||||
|
srcs = SRCS,
|
||||||
|
build_pkg_name = package_name(),
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_config(
|
||||||
|
name = "tsconfig",
|
||||||
|
src = "tsconfig.json",
|
||||||
|
deps = [
|
||||||
|
"//:tsconfig.base.json",
|
||||||
|
"//:tsconfig.bazel.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_project(
|
||||||
|
name = "tsc_types",
|
||||||
|
args = ['--pretty'],
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = TYPES_DEPS,
|
||||||
|
declaration = True,
|
||||||
|
declaration_map = True,
|
||||||
|
emit_declaration_only = True,
|
||||||
|
out_dir = "target_types",
|
||||||
|
root_dir = "src",
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
)
|
||||||
|
|
||||||
|
js_library(
|
||||||
|
name = PKG_DIRNAME,
|
||||||
|
srcs = NPM_MODULE_EXTRA_FILES,
|
||||||
|
deps = RUNTIME_DEPS + [":target_node"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm(
|
||||||
|
name = "npm_module",
|
||||||
|
deps = [":" + PKG_DIRNAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build",
|
||||||
|
srcs = [":npm_module"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm_types(
|
||||||
|
name = "npm_module_types",
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = [":tsc_types"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build_types",
|
||||||
|
srcs = [":npm_module_types"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,3 @@
|
||||||
|
# @kbn/core-metrics-collectors-server-internal
|
||||||
|
|
||||||
|
This package contains the implementation, internal types, unit tests, and internal mocks for Core's server-side metrics service's collectors.
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: '@kbn/test/jest_node',
|
||||||
|
rootDir: '../../../..',
|
||||||
|
roots: ['<rootDir>/packages/core/metrics/core-metrics-collectors-server-internal'],
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "@kbn/core-metrics-collectors-server-internal",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "./target_node/index.js",
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { mocked } from '../event_loop_delays_monitor.mocks';
|
import { mocked } from '../mocks_internal';
|
||||||
|
|
||||||
export const monitorEventLoopDelay = jest.fn().mockImplementation(() => {
|
export const monitorEventLoopDelay = jest.fn().mockImplementation(() => {
|
||||||
const mockedHistogram = mocked.createHistogram();
|
const mockedHistogram = mocked.createHistogram();
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { join as joinPath } from 'path';
|
import { join as joinPath } from 'path';
|
||||||
import { Logger } from '@kbn/logging';
|
import type { Logger } from '@kbn/logging';
|
||||||
import { MetricsCollector, OpsOsMetrics } from './types';
|
import type { MetricsCollector, OpsOsMetrics } from '@kbn/core-metrics-server';
|
||||||
|
|
||||||
type OsCgroupMetrics = Pick<OpsOsMetrics, 'cpu' | 'cpuacct'>;
|
type OsCgroupMetrics = Pick<OpsOsMetrics, 'cpu' | 'cpuacct'>;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
jest.mock('perf_hooks');
|
jest.mock('perf_hooks');
|
||||||
import { monitorEventLoopDelay } from 'perf_hooks';
|
import { monitorEventLoopDelay } from 'perf_hooks';
|
||||||
import { EventLoopDelaysMonitor, nsToMs } from './event_loop_delays_monitor';
|
import { EventLoopDelaysMonitor, nsToMs } from './event_loop_delays_monitor';
|
||||||
import { mocked } from './event_loop_delays_monitor.mocks';
|
import { mocked } from './mocks_internal';
|
||||||
|
|
||||||
describe('EventLoopDelaysMonitor', () => {
|
describe('EventLoopDelaysMonitor', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import type { IntervalHistogram as PerfIntervalHistogram } from 'perf_hooks';
|
import type { IntervalHistogram as PerfIntervalHistogram } from 'perf_hooks';
|
||||||
import { monitorEventLoopDelay } from 'perf_hooks';
|
import { monitorEventLoopDelay } from 'perf_hooks';
|
||||||
import type { IntervalHistogram } from '../types';
|
import type { IntervalHistogram, IEventLoopDelaysMonitor } from '@kbn/core-metrics-server';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nanosecond to milisecond conversion unit
|
* Nanosecond to milisecond conversion unit
|
||||||
|
@ -22,7 +22,7 @@ export function nsToMs(metric: number) {
|
||||||
return metric / ONE_MILLISECOND_AS_NANOSECONDS;
|
return metric / ONE_MILLISECOND_AS_NANOSECONDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EventLoopDelaysMonitor {
|
export class EventLoopDelaysMonitor implements IEventLoopDelaysMonitor {
|
||||||
private readonly loopMonitor: PerfIntervalHistogram;
|
private readonly loopMonitor: PerfIntervalHistogram;
|
||||||
private fromTimestamp: Date;
|
private fromTimestamp: Date;
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type { OpsProcessMetrics, OpsOsMetrics, OpsServerMetrics, MetricsCollector } from './types';
|
|
||||||
export { OsMetricsCollector } from './os';
|
export { OsMetricsCollector } from './os';
|
||||||
export type { OpsMetricsCollectorOptions } from './os';
|
export type { OpsMetricsCollectorOptions } from './os';
|
||||||
export { ProcessMetricsCollector } from './process';
|
export { ProcessMetricsCollector } from './process';
|
||||||
export { ServerMetricsCollector } from './server';
|
export { ServerMetricsCollector } from './server';
|
||||||
|
export { EventLoopDelaysMonitor } from './event_loop_delays_monitor';
|
|
@ -0,0 +1,133 @@
|
||||||
|
/*
|
||||||
|
* 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 moment from 'moment';
|
||||||
|
import type {
|
||||||
|
MetricsCollector,
|
||||||
|
IntervalHistogram,
|
||||||
|
OpsProcessMetrics,
|
||||||
|
} from '@kbn/core-metrics-server';
|
||||||
|
import { EventLoopDelaysMonitor } from './event_loop_delays_monitor';
|
||||||
|
|
||||||
|
// internal duplicate of metricsCollectorMock
|
||||||
|
const createCollector = <T = any>(
|
||||||
|
collectReturnValue: any = {}
|
||||||
|
): jest.Mocked<MetricsCollector<T>> => {
|
||||||
|
const collector: jest.Mocked<MetricsCollector<T>> = {
|
||||||
|
collect: jest.fn().mockResolvedValue(collectReturnValue),
|
||||||
|
reset: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return collector;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const metricsCollectorMock = {
|
||||||
|
create: createCollector,
|
||||||
|
};
|
||||||
|
|
||||||
|
// internal duplicate of process.mocks
|
||||||
|
function createMockOpsProcessMetrics(): OpsProcessMetrics {
|
||||||
|
const histogram = mocked.createHistogram();
|
||||||
|
|
||||||
|
return {
|
||||||
|
memory: {
|
||||||
|
heap: { total_in_bytes: 1, used_in_bytes: 1, size_limit: 1 },
|
||||||
|
resident_set_size_in_bytes: 1,
|
||||||
|
},
|
||||||
|
event_loop_delay: 1,
|
||||||
|
event_loop_delay_histogram: histogram,
|
||||||
|
pid: 1,
|
||||||
|
uptime_in_millis: 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// internal duplicate of base collector mock
|
||||||
|
const createMock = () => {
|
||||||
|
const mocked: jest.Mocked<MetricsCollector<any>> = {
|
||||||
|
collect: jest.fn(),
|
||||||
|
reset: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
mocked.collect.mockResolvedValue({});
|
||||||
|
|
||||||
|
return mocked;
|
||||||
|
};
|
||||||
|
|
||||||
|
// internal duplicate of `collectorMock` exposed in @kbn/core-metrics-collectors-server-mocks for unit tests*/
|
||||||
|
export const collectorMock = {
|
||||||
|
create: createMock,
|
||||||
|
createOpsProcessMetrics: createMockOpsProcessMetrics,
|
||||||
|
};
|
||||||
|
|
||||||
|
// internal duplicate of EventLoopDelay mocks exposed in @kbn/core-metrics-collectors-server-mocks for unit tests
|
||||||
|
function createMockRawNsDataHistogram(
|
||||||
|
overwrites: Partial<IntervalHistogram> = {}
|
||||||
|
): IntervalHistogram {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
const mockedRawCollectedDataInNs = {
|
||||||
|
min: 9093120,
|
||||||
|
max: 53247999,
|
||||||
|
mean: 11993238,
|
||||||
|
exceeds: 0,
|
||||||
|
stddev: 1168191,
|
||||||
|
fromTimestamp: moment(now).toISOString(),
|
||||||
|
lastUpdatedAt: moment(now).toISOString(),
|
||||||
|
percentiles: {
|
||||||
|
'50': 12607487,
|
||||||
|
'75': 12615679,
|
||||||
|
'95': 12648447,
|
||||||
|
'99': 12713983,
|
||||||
|
},
|
||||||
|
...overwrites,
|
||||||
|
};
|
||||||
|
return mockedRawCollectedDataInNs;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createMockMonitorDataMsHistogram(
|
||||||
|
overwrites: Partial<IntervalHistogram> = {}
|
||||||
|
): IntervalHistogram {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
const mockedRawCollectedDataInMs = {
|
||||||
|
min: 9.09312,
|
||||||
|
max: 53.247999,
|
||||||
|
mean: 11.993238,
|
||||||
|
exceeds: 0,
|
||||||
|
stddev: 1.168191,
|
||||||
|
fromTimestamp: moment(now).toISOString(),
|
||||||
|
lastUpdatedAt: moment(now).toISOString(),
|
||||||
|
percentiles: {
|
||||||
|
'50': 12.607487,
|
||||||
|
'75': 12.615679,
|
||||||
|
'95': 12.648447,
|
||||||
|
'99': 12.713983,
|
||||||
|
},
|
||||||
|
...overwrites,
|
||||||
|
};
|
||||||
|
return mockedRawCollectedDataInMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createMockEventLoopDelaysMonitor() {
|
||||||
|
const mockCollect = jest.fn();
|
||||||
|
const MockEventLoopDelaysMonitor: jest.MockedClass<typeof EventLoopDelaysMonitor> = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue({
|
||||||
|
collect: mockCollect,
|
||||||
|
reset: jest.fn(),
|
||||||
|
stop: jest.fn(),
|
||||||
|
});
|
||||||
|
|
||||||
|
mockCollect.mockReturnValue(createMockMonitorDataMsHistogram()); // this must mock the return value of the public collect method from this monitor.
|
||||||
|
|
||||||
|
return new MockEventLoopDelaysMonitor();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const mocked = {
|
||||||
|
createHistogram: createMockRawNsDataHistogram, // raw data as received from Node.js perf_hooks.monitorEventLoopDelay([options])
|
||||||
|
createEventLoopDelaysMonitor: createMockEventLoopDelaysMonitor,
|
||||||
|
};
|
|
@ -6,8 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { metricsCollectorMock } from './collector.mock';
|
import { metricsCollectorMock } from './mocks_internal';
|
||||||
|
|
||||||
export const cgroupCollectorMock = metricsCollectorMock.create();
|
export const cgroupCollectorMock = metricsCollectorMock.create();
|
||||||
jest.doMock('./cgroup', () => ({
|
jest.doMock('./cgroup', () => ({
|
||||||
OsCgroupMetricsCollector: jest.fn(() => cgroupCollectorMock),
|
OsCgroupMetricsCollector: jest.fn(() => cgroupCollectorMock),
|
|
@ -9,8 +9,8 @@
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import getosAsync, { LinuxOs } from 'getos';
|
import getosAsync, { LinuxOs } from 'getos';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import { Logger } from '@kbn/logging';
|
import type { Logger } from '@kbn/logging';
|
||||||
import { OpsOsMetrics, MetricsCollector } from './types';
|
import type { OpsOsMetrics, MetricsCollector } from '@kbn/core-metrics-server';
|
||||||
import { OsCgroupMetricsCollector } from './cgroup';
|
import { OsCgroupMetricsCollector } from './cgroup';
|
||||||
|
|
||||||
const getos = promisify(getosAsync);
|
const getos = promisify(getosAsync);
|
|
@ -7,8 +7,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import v8 from 'v8';
|
import v8 from 'v8';
|
||||||
import { OpsProcessMetrics, MetricsCollector } from './types';
|
import type { OpsProcessMetrics, MetricsCollector } from '@kbn/core-metrics-server';
|
||||||
import { EventLoopDelaysMonitor } from '../event_loop_delays';
|
import { EventLoopDelaysMonitor } from './event_loop_delays_monitor';
|
||||||
|
|
||||||
export class ProcessMetricsCollector implements MetricsCollector<OpsProcessMetrics[]> {
|
export class ProcessMetricsCollector implements MetricsCollector<OpsProcessMetrics[]> {
|
||||||
static getMainThreadMetrics(processes: OpsProcessMetrics[]): undefined | OpsProcessMetrics {
|
static getMainThreadMetrics(processes: OpsProcessMetrics[]): undefined | OpsProcessMetrics {
|
|
@ -6,8 +6,8 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ResponseObject, Server as HapiServer } from '@hapi/hapi';
|
import type { ResponseObject, Server as HapiServer } from '@hapi/hapi';
|
||||||
import { OpsServerMetrics, MetricsCollector } from './types';
|
import type { OpsServerMetrics, MetricsCollector } from '@kbn/core-metrics-server';
|
||||||
|
|
||||||
interface ServerResponseTime {
|
interface ServerResponseTime {
|
||||||
count: number;
|
count: number;
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.bazel.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"emitDeclarationOnly": true,
|
||||||
|
"outDir": "target_types",
|
||||||
|
"rootDir": "src",
|
||||||
|
"stripInternal": false,
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_config")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||||
|
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
|
||||||
|
|
||||||
|
PKG_DIRNAME = "core-metrics-collectors-server-mocks"
|
||||||
|
PKG_REQUIRE_NAME = "@kbn/core-metrics-collectors-server-mocks"
|
||||||
|
|
||||||
|
SOURCE_FILES = glob(
|
||||||
|
[
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/*.stories.*",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
SRCS = SOURCE_FILES
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "srcs",
|
||||||
|
srcs = SRCS,
|
||||||
|
)
|
||||||
|
|
||||||
|
NPM_MODULE_EXTRA_FILES = [
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
RUNTIME_DEPS = [
|
||||||
|
"@npm//moment",
|
||||||
|
"//packages/core/metrics/core-metrics-server",
|
||||||
|
]
|
||||||
|
|
||||||
|
TYPES_DEPS = [
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/jest",
|
||||||
|
"@npm//moment",
|
||||||
|
"//packages/core/metrics/core-metrics-server:npm_module_types",
|
||||||
|
"//packages/core/metrics/core-metrics-collectors-server-internal:npm_module_types",
|
||||||
|
]
|
||||||
|
|
||||||
|
jsts_transpiler(
|
||||||
|
name = "target_node",
|
||||||
|
srcs = SRCS,
|
||||||
|
build_pkg_name = package_name(),
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_config(
|
||||||
|
name = "tsconfig",
|
||||||
|
src = "tsconfig.json",
|
||||||
|
deps = [
|
||||||
|
"//:tsconfig.base.json",
|
||||||
|
"//:tsconfig.bazel.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_project(
|
||||||
|
name = "tsc_types",
|
||||||
|
args = ['--pretty'],
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = TYPES_DEPS,
|
||||||
|
declaration = True,
|
||||||
|
declaration_map = True,
|
||||||
|
emit_declaration_only = True,
|
||||||
|
out_dir = "target_types",
|
||||||
|
root_dir = "src",
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
)
|
||||||
|
|
||||||
|
js_library(
|
||||||
|
name = PKG_DIRNAME,
|
||||||
|
srcs = NPM_MODULE_EXTRA_FILES,
|
||||||
|
deps = RUNTIME_DEPS + [":target_node"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm(
|
||||||
|
name = "npm_module",
|
||||||
|
deps = [":" + PKG_DIRNAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build",
|
||||||
|
srcs = [":npm_module"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm_types(
|
||||||
|
name = "npm_module_types",
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = [":tsc_types"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build_types",
|
||||||
|
srcs = [":npm_module_types"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,3 @@
|
||||||
|
# @kbn/core-metrics-collectors-server-mocks
|
||||||
|
|
||||||
|
This package contains the mocks for Core's server-side metrics service collectors and event loop delays monitor.
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: '@kbn/test/jest_node',
|
||||||
|
rootDir: '../../../..',
|
||||||
|
roots: ['<rootDir>/packages/core/metrics/core-metrics-collectors-server-mocks'],
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "@kbn/core-metrics-collectors-server-mocks",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "./target_node/index.js",
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MetricsCollector } from './types';
|
import type { MetricsCollector } from '@kbn/core-metrics-server';
|
||||||
|
|
||||||
const createCollector = <T = any>(
|
const createCollector = <T = any>(
|
||||||
collectReturnValue: any = {}
|
collectReturnValue: any = {}
|
|
@ -6,8 +6,8 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import type { EventLoopDelaysMonitor } from './event_loop_delays_monitor';
|
import type { IntervalHistogram } from '@kbn/core-metrics-server';
|
||||||
import type { IntervalHistogram } from '../types';
|
import type { EventLoopDelaysMonitor } from '@kbn/core-metrics-collectors-server-internal';
|
||||||
|
|
||||||
function createMockRawNsDataHistogram(
|
function createMockRawNsDataHistogram(
|
||||||
overwrites: Partial<IntervalHistogram> = {}
|
overwrites: Partial<IntervalHistogram> = {}
|
|
@ -0,0 +1,12 @@
|
||||||
|
/*
|
||||||
|
* 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 { metricsCollectorMock } from './collector.mock';
|
||||||
|
export { collectorMock } from './mocks';
|
||||||
|
export { createMockOpsProcessMetrics } from './process.mocks';
|
||||||
|
export { mocked } from './event_loop_delays_monitor.mocks';
|
|
@ -6,7 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { MetricsCollector } from './types';
|
import type { MetricsCollector } from '@kbn/core-metrics-server';
|
||||||
import { createMockOpsProcessMetrics } from './process.mocks';
|
import { createMockOpsProcessMetrics } from './process.mocks';
|
||||||
|
|
||||||
const createMock = () => {
|
const createMock = () => {
|
|
@ -5,8 +5,8 @@
|
||||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
import { mocked } from '../event_loop_delays/event_loop_delays_monitor.mocks';
|
import type { OpsProcessMetrics } from '@kbn/core-metrics-server';
|
||||||
import type { OpsProcessMetrics } from './types';
|
import { mocked } from './event_loop_delays_monitor.mocks';
|
||||||
|
|
||||||
export function createMockOpsProcessMetrics(): OpsProcessMetrics {
|
export function createMockOpsProcessMetrics(): OpsProcessMetrics {
|
||||||
const histogram = mocked.createHistogram();
|
const histogram = mocked.createHistogram();
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.bazel.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"emitDeclarationOnly": true,
|
||||||
|
"outDir": "target_types",
|
||||||
|
"rootDir": "src",
|
||||||
|
"stripInternal": false,
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
]
|
||||||
|
}
|
115
packages/core/metrics/core-metrics-server-internal/BUILD.bazel
Normal file
115
packages/core/metrics/core-metrics-server-internal/BUILD.bazel
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_config")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||||
|
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
|
||||||
|
|
||||||
|
PKG_DIRNAME = "core-metrics-server-internal"
|
||||||
|
PKG_REQUIRE_NAME = "@kbn/core-metrics-server-internal"
|
||||||
|
|
||||||
|
SOURCE_FILES = glob(
|
||||||
|
[
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/*.stories.*",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
SRCS = SOURCE_FILES
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "srcs",
|
||||||
|
srcs = SRCS,
|
||||||
|
)
|
||||||
|
|
||||||
|
NPM_MODULE_EXTRA_FILES = [
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
RUNTIME_DEPS = [
|
||||||
|
"@npm//rxjs",
|
||||||
|
"@npm//moment",
|
||||||
|
"//packages/kbn-logging-mocks",
|
||||||
|
"//packages/kbn-config-schema",
|
||||||
|
"//packages/core/http/core-http-server-mocks",
|
||||||
|
"//packages/core/metrics/core-metrics-collectors-server-internal",
|
||||||
|
"//packages/core/metrics/core-metrics-collectors-server-mocks",
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
TYPES_DEPS = [
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/jest",
|
||||||
|
"@npm//rxjs",
|
||||||
|
"@npm//moment",
|
||||||
|
"@npm//@hapi/hapi",
|
||||||
|
"//packages/kbn-logging:npm_module_types",
|
||||||
|
"//packages/kbn-config-schema:npm_module_types",
|
||||||
|
"//packages/core/base/core-base-server-internal:npm_module_types",
|
||||||
|
"//packages/core/http/core-http-server-internal:npm_module_types",
|
||||||
|
"//packages/core/metrics/core-metrics-server:npm_module_types",
|
||||||
|
"//packages/core/metrics/core-metrics-collectors-server-internal:npm_module_types",
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
jsts_transpiler(
|
||||||
|
name = "target_node",
|
||||||
|
srcs = SRCS,
|
||||||
|
build_pkg_name = package_name(),
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_config(
|
||||||
|
name = "tsconfig",
|
||||||
|
src = "tsconfig.json",
|
||||||
|
deps = [
|
||||||
|
"//:tsconfig.base.json",
|
||||||
|
"//:tsconfig.bazel.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_project(
|
||||||
|
name = "tsc_types",
|
||||||
|
args = ['--pretty'],
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = TYPES_DEPS,
|
||||||
|
declaration = True,
|
||||||
|
declaration_map = True,
|
||||||
|
emit_declaration_only = True,
|
||||||
|
out_dir = "target_types",
|
||||||
|
root_dir = "src",
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
)
|
||||||
|
|
||||||
|
js_library(
|
||||||
|
name = PKG_DIRNAME,
|
||||||
|
srcs = NPM_MODULE_EXTRA_FILES,
|
||||||
|
deps = RUNTIME_DEPS + [":target_node"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm(
|
||||||
|
name = "npm_module",
|
||||||
|
deps = [":" + PKG_DIRNAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build",
|
||||||
|
srcs = [":npm_module"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm_types(
|
||||||
|
name = "npm_module_types",
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = [":tsc_types"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build_types",
|
||||||
|
srcs = [":npm_module_types"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,3 @@
|
||||||
|
# @kbn/core-metrics-server-internal
|
||||||
|
|
||||||
|
This package contains the internal types and implementation for Core's server-side metrics service.
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: '@kbn/test/jest_node',
|
||||||
|
rootDir: '../../../..',
|
||||||
|
roots: ['<rootDir>/packages/core/metrics/core-metrics-server-internal'],
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "@kbn/core-metrics-server-internal",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "./target_node/index.js",
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* 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 {
|
||||||
|
type MetricsServiceSetupDeps,
|
||||||
|
type InternalMetricsServiceStart,
|
||||||
|
type InternalMetricsServiceSetup,
|
||||||
|
MetricsService,
|
||||||
|
} from './metrics_service';
|
||||||
|
export { opsConfig, type OpsConfigType } from './ops_config';
|
|
@ -6,9 +6,9 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { OpsMetrics } from '..';
|
import type { OpsMetrics } from '@kbn/core-metrics-server';
|
||||||
import { getEcsOpsMetricsLog } from './get_ops_metrics_log';
|
import { getEcsOpsMetricsLog } from './get_ops_metrics_log';
|
||||||
import { collectorMock } from '../collectors/mocks';
|
import { collectorMock } from '@kbn/core-metrics-collectors-server-mocks';
|
||||||
|
|
||||||
function createBaseOpsMetrics(): OpsMetrics {
|
function createBaseOpsMetrics(): OpsMetrics {
|
||||||
const mockProcess = collectorMock.createOpsProcessMetrics();
|
const mockProcess = collectorMock.createOpsProcessMetrics();
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import numeral from '@elastic/numeral';
|
import numeral from '@elastic/numeral';
|
||||||
import { LogMeta } from '@kbn/logging';
|
import { LogMeta } from '@kbn/logging';
|
||||||
import { OpsMetrics } from '..';
|
import type { OpsMetrics } from '@kbn/core-metrics-server';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts ops metrics into ECS-compliant `LogMeta` for logging
|
* Converts ops metrics into ECS-compliant `LogMeta` for logging
|
|
@ -6,7 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { collectorMock } from './collectors/mocks';
|
import { collectorMock } from '@kbn/core-metrics-collectors-server-mocks';
|
||||||
|
|
||||||
export const mockOpsCollector = collectorMock.create();
|
export const mockOpsCollector = collectorMock.create();
|
||||||
|
|
|
@ -8,17 +8,27 @@
|
||||||
|
|
||||||
import { firstValueFrom, ReplaySubject } from 'rxjs';
|
import { firstValueFrom, ReplaySubject } from 'rxjs';
|
||||||
import type { CoreContext, CoreService } from '@kbn/core-base-server-internal';
|
import type { CoreContext, CoreService } from '@kbn/core-base-server-internal';
|
||||||
import { Logger } from '@kbn/logging';
|
import type { Logger } from '@kbn/logging';
|
||||||
import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
|
import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
|
||||||
import { InternalMetricsServiceSetup, InternalMetricsServiceStart, OpsMetrics } from './types';
|
import type {
|
||||||
|
OpsMetrics,
|
||||||
|
MetricsServiceSetup,
|
||||||
|
MetricsServiceStart,
|
||||||
|
} from '@kbn/core-metrics-server';
|
||||||
import { OpsMetricsCollector } from './ops_metrics_collector';
|
import { OpsMetricsCollector } from './ops_metrics_collector';
|
||||||
import { opsConfig, OpsConfigType } from './ops_config';
|
import { OPS_CONFIG_PATH, type OpsConfigType } from './ops_config';
|
||||||
import { getEcsOpsMetricsLog } from './logging';
|
import { getEcsOpsMetricsLog } from './logging';
|
||||||
|
|
||||||
export interface MetricsServiceSetupDeps {
|
export interface MetricsServiceSetupDeps {
|
||||||
http: InternalHttpServiceSetup;
|
http: InternalHttpServiceSetup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
export type InternalMetricsServiceSetup = MetricsServiceSetup;
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
export type InternalMetricsServiceStart = MetricsServiceStart;
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export class MetricsService
|
export class MetricsService
|
||||||
implements CoreService<InternalMetricsServiceSetup, InternalMetricsServiceStart>
|
implements CoreService<InternalMetricsServiceSetup, InternalMetricsServiceStart>
|
||||||
|
@ -37,7 +47,7 @@ export class MetricsService
|
||||||
|
|
||||||
public async setup({ http }: MetricsServiceSetupDeps): Promise<InternalMetricsServiceSetup> {
|
public async setup({ http }: MetricsServiceSetupDeps): Promise<InternalMetricsServiceSetup> {
|
||||||
const config = await firstValueFrom(
|
const config = await firstValueFrom(
|
||||||
this.coreContext.configService.atPath<OpsConfigType>(opsConfig.path)
|
this.coreContext.configService.atPath<OpsConfigType>(OPS_CONFIG_PATH)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.metricsCollector = new OpsMetricsCollector(http.server, {
|
this.metricsCollector = new OpsMetricsCollector(http.server, {
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* 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 { schema } from '@kbn/config-schema';
|
||||||
|
import { ServiceConfigDescriptor } from '@kbn/core-base-server-internal';
|
||||||
|
import type { Duration } from 'moment';
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
export const OPS_CONFIG_PATH = 'ops' as const;
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
const OPS_METRICS_INTERVAL = '5s';
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
interface OpsConfigCGroupOverridesOps {
|
||||||
|
cpuPath?: string;
|
||||||
|
cpuAcctPath?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
export interface OpsConfigType {
|
||||||
|
interval: Duration;
|
||||||
|
cGroupOverrides: OpsConfigCGroupOverridesOps;
|
||||||
|
}
|
||||||
|
|
||||||
|
const configSchema = schema.object({
|
||||||
|
interval: schema.duration({ defaultValue: OPS_METRICS_INTERVAL }),
|
||||||
|
cGroupOverrides: schema.object({
|
||||||
|
cpuPath: schema.maybe(schema.string()),
|
||||||
|
cpuAcctPath: schema.maybe(schema.string()),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const opsConfig: ServiceConfigDescriptor<OpsConfigType> = {
|
||||||
|
path: OPS_CONFIG_PATH,
|
||||||
|
schema: configSchema,
|
||||||
|
};
|
|
@ -6,19 +6,16 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { collectorMock } from './collectors/mocks';
|
import { collectorMock } from '@kbn/core-metrics-collectors-server-mocks';
|
||||||
|
|
||||||
export const mockOsCollector = collectorMock.create();
|
export const mockOsCollector = collectorMock.create();
|
||||||
jest.doMock('./collectors/os', () => ({
|
|
||||||
OsMetricsCollector: jest.fn().mockImplementation(() => mockOsCollector),
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const mockProcessCollector = collectorMock.create();
|
export const mockProcessCollector = collectorMock.create();
|
||||||
jest.doMock('./collectors/process', () => ({
|
|
||||||
ProcessMetricsCollector: jest.fn().mockImplementation(() => mockProcessCollector),
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const mockServerCollector = collectorMock.create();
|
export const mockServerCollector = collectorMock.create();
|
||||||
jest.doMock('./collectors/server', () => ({
|
|
||||||
ServerMetricsCollector: jest.fn().mockImplementation(() => mockServerCollector),
|
jest.doMock('@kbn/core-metrics-collectors-server-internal', () => {
|
||||||
}));
|
return {
|
||||||
|
OsMetricsCollector: jest.fn().mockImplementation(() => mockOsCollector),
|
||||||
|
ProcessMetricsCollector: jest.fn().mockImplementation(() => mockProcessCollector),
|
||||||
|
ServerMetricsCollector: jest.fn().mockImplementation(() => mockServerCollector),
|
||||||
|
};
|
||||||
|
});
|
|
@ -7,14 +7,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Server as HapiServer } from '@hapi/hapi';
|
import { Server as HapiServer } from '@hapi/hapi';
|
||||||
|
import type { OpsMetrics, MetricsCollector } from '@kbn/core-metrics-server';
|
||||||
import {
|
import {
|
||||||
ProcessMetricsCollector,
|
ProcessMetricsCollector,
|
||||||
OsMetricsCollector,
|
OsMetricsCollector,
|
||||||
OpsMetricsCollectorOptions,
|
type OpsMetricsCollectorOptions,
|
||||||
ServerMetricsCollector,
|
ServerMetricsCollector,
|
||||||
MetricsCollector,
|
} from '@kbn/core-metrics-collectors-server-internal';
|
||||||
} from './collectors';
|
|
||||||
import { OpsMetrics } from './types';
|
|
||||||
|
|
||||||
export class OpsMetricsCollector implements MetricsCollector<OpsMetrics> {
|
export class OpsMetricsCollector implements MetricsCollector<OpsMetrics> {
|
||||||
private readonly processCollector: ProcessMetricsCollector;
|
private readonly processCollector: ProcessMetricsCollector;
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.bazel.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"emitDeclarationOnly": true,
|
||||||
|
"outDir": "target_types",
|
||||||
|
"rootDir": "src",
|
||||||
|
"stripInternal": false,
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
]
|
||||||
|
}
|
104
packages/core/metrics/core-metrics-server-mocks/BUILD.bazel
Normal file
104
packages/core/metrics/core-metrics-server-mocks/BUILD.bazel
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_config")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||||
|
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
|
||||||
|
|
||||||
|
PKG_DIRNAME = "core-metrics-server-mocks"
|
||||||
|
PKG_REQUIRE_NAME = "@kbn/core-metrics-server-mocks"
|
||||||
|
|
||||||
|
SOURCE_FILES = glob(
|
||||||
|
[
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/*.stories.*",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
SRCS = SOURCE_FILES
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "srcs",
|
||||||
|
srcs = SRCS,
|
||||||
|
)
|
||||||
|
|
||||||
|
NPM_MODULE_EXTRA_FILES = [
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
RUNTIME_DEPS = [
|
||||||
|
"@npm//rxjs",
|
||||||
|
"//packages/core/metrics/core-metrics-collectors-server-mocks",
|
||||||
|
]
|
||||||
|
|
||||||
|
TYPES_DEPS = [
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/jest",
|
||||||
|
"@npm//rxjs",
|
||||||
|
"//packages/kbn-utility-types:npm_module_types",
|
||||||
|
"//packages/core/metrics/core-metrics-server:npm_module_types",
|
||||||
|
"//packages/core/metrics/core-metrics-server-internal:npm_module_types",
|
||||||
|
"//packages/core/metrics/core-metrics-collectors-server-mocks:npm_module_types",
|
||||||
|
]
|
||||||
|
|
||||||
|
jsts_transpiler(
|
||||||
|
name = "target_node",
|
||||||
|
srcs = SRCS,
|
||||||
|
build_pkg_name = package_name(),
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_config(
|
||||||
|
name = "tsconfig",
|
||||||
|
src = "tsconfig.json",
|
||||||
|
deps = [
|
||||||
|
"//:tsconfig.base.json",
|
||||||
|
"//:tsconfig.bazel.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_project(
|
||||||
|
name = "tsc_types",
|
||||||
|
args = ['--pretty'],
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = TYPES_DEPS,
|
||||||
|
declaration = True,
|
||||||
|
declaration_map = True,
|
||||||
|
emit_declaration_only = True,
|
||||||
|
out_dir = "target_types",
|
||||||
|
root_dir = "src",
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
)
|
||||||
|
|
||||||
|
js_library(
|
||||||
|
name = PKG_DIRNAME,
|
||||||
|
srcs = NPM_MODULE_EXTRA_FILES,
|
||||||
|
deps = RUNTIME_DEPS + [":target_node"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm(
|
||||||
|
name = "npm_module",
|
||||||
|
deps = [":" + PKG_DIRNAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build",
|
||||||
|
srcs = [":npm_module"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm_types(
|
||||||
|
name = "npm_module_types",
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = [":tsc_types"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build_types",
|
||||||
|
srcs = [":npm_module_types"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,3 @@
|
||||||
|
# @kbn/core-metrics-server-mocks
|
||||||
|
|
||||||
|
This package contains the mocks for Core's server-side metrics service.
|
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: '@kbn/test/jest_node',
|
||||||
|
rootDir: '../../../..',
|
||||||
|
roots: ['<rootDir>/packages/core/metrics/core-metrics-server-mocks'],
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "@kbn/core-metrics-server-mocks",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "./target_node/index.js",
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||||
|
}
|
|
@ -6,4 +6,4 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { EventLoopDelaysMonitor } from './event_loop_delays_monitor';
|
export { metricsServiceMock } from './metrics_service.mock';
|
|
@ -8,15 +8,16 @@
|
||||||
|
|
||||||
import { BehaviorSubject } from 'rxjs';
|
import { BehaviorSubject } from 'rxjs';
|
||||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||||
import type { MetricsService } from './metrics_service';
|
import type {
|
||||||
import { collectorMock } from './collectors/mocks';
|
MetricsService,
|
||||||
import { mocked as eventLoopDelaysMonitorMock } from './event_loop_delays/event_loop_delays_monitor.mocks';
|
|
||||||
import {
|
|
||||||
InternalMetricsServiceSetup,
|
InternalMetricsServiceSetup,
|
||||||
InternalMetricsServiceStart,
|
InternalMetricsServiceStart,
|
||||||
MetricsServiceSetup,
|
} from '@kbn/core-metrics-server-internal';
|
||||||
MetricsServiceStart,
|
import {
|
||||||
} from './types';
|
mocked as eventLoopDelaysMonitorMock,
|
||||||
|
collectorMock,
|
||||||
|
} from '@kbn/core-metrics-collectors-server-mocks';
|
||||||
|
import type { MetricsServiceSetup, MetricsServiceStart } from '@kbn/core-metrics-server';
|
||||||
|
|
||||||
const createInternalSetupContractMock = () => {
|
const createInternalSetupContractMock = () => {
|
||||||
const setupContract: jest.Mocked<InternalMetricsServiceSetup> = {
|
const setupContract: jest.Mocked<InternalMetricsServiceSetup> = {
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.bazel.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"emitDeclarationOnly": true,
|
||||||
|
"outDir": "target_types",
|
||||||
|
"rootDir": "src",
|
||||||
|
"stripInternal": false,
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
]
|
||||||
|
}
|
99
packages/core/metrics/core-metrics-server/BUILD.bazel
Normal file
99
packages/core/metrics/core-metrics-server/BUILD.bazel
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_config")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
||||||
|
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
|
||||||
|
|
||||||
|
PKG_DIRNAME = "core-metrics-server"
|
||||||
|
PKG_REQUIRE_NAME = "@kbn/core-metrics-server"
|
||||||
|
|
||||||
|
SOURCE_FILES = glob(
|
||||||
|
[
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
exclude = [
|
||||||
|
"**/*.test.*",
|
||||||
|
"**/*.stories.*",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
SRCS = SOURCE_FILES
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "srcs",
|
||||||
|
srcs = SRCS,
|
||||||
|
)
|
||||||
|
|
||||||
|
NPM_MODULE_EXTRA_FILES = [
|
||||||
|
"package.json",
|
||||||
|
]
|
||||||
|
|
||||||
|
RUNTIME_DEPS = [
|
||||||
|
]
|
||||||
|
|
||||||
|
TYPES_DEPS = [
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/jest",
|
||||||
|
"@npm//rxjs",
|
||||||
|
"//packages/kbn-utility-types:npm_module_types"
|
||||||
|
]
|
||||||
|
|
||||||
|
jsts_transpiler(
|
||||||
|
name = "target_node",
|
||||||
|
srcs = SRCS,
|
||||||
|
build_pkg_name = package_name(),
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_config(
|
||||||
|
name = "tsconfig",
|
||||||
|
src = "tsconfig.json",
|
||||||
|
deps = [
|
||||||
|
"//:tsconfig.base.json",
|
||||||
|
"//:tsconfig.bazel.json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
ts_project(
|
||||||
|
name = "tsc_types",
|
||||||
|
args = ['--pretty'],
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = TYPES_DEPS,
|
||||||
|
declaration = True,
|
||||||
|
declaration_map = True,
|
||||||
|
emit_declaration_only = True,
|
||||||
|
out_dir = "target_types",
|
||||||
|
root_dir = "src",
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
)
|
||||||
|
|
||||||
|
js_library(
|
||||||
|
name = PKG_DIRNAME,
|
||||||
|
srcs = NPM_MODULE_EXTRA_FILES,
|
||||||
|
deps = RUNTIME_DEPS + [":target_node"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm(
|
||||||
|
name = "npm_module",
|
||||||
|
deps = [":" + PKG_DIRNAME],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build",
|
||||||
|
srcs = [":npm_module"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_npm_types(
|
||||||
|
name = "npm_module_types",
|
||||||
|
srcs = SRCS,
|
||||||
|
deps = [":tsc_types"],
|
||||||
|
package_name = PKG_REQUIRE_NAME,
|
||||||
|
tsconfig = ":tsconfig",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "build_types",
|
||||||
|
srcs = [":npm_module_types"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
3
packages/core/metrics/core-metrics-server/README.md
Normal file
3
packages/core/metrics/core-metrics-server/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# @kbn/core-metrics-server
|
||||||
|
|
||||||
|
This package contains the public types for Core's server-side metrics service.
|
13
packages/core/metrics/core-metrics-server/jest.config.js
Normal file
13
packages/core/metrics/core-metrics-server/jest.config.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
preset: '@kbn/test/jest_node',
|
||||||
|
rootDir: '../../../..',
|
||||||
|
roots: ['<rootDir>/packages/core/metrics/core-metrics-server'],
|
||||||
|
};
|
7
packages/core/metrics/core-metrics-server/package.json
Normal file
7
packages/core/metrics/core-metrics-server/package.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "@kbn/core-metrics-server",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "./target_node/index.js",
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||||
|
}
|
45
packages/core/metrics/core-metrics-server/src/collectors.ts
Normal file
45
packages/core/metrics/core-metrics-server/src/collectors.ts
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* 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 type { MaybePromise } from '@kbn/utility-types';
|
||||||
|
import type { IntervalHistogram } from './metrics';
|
||||||
|
|
||||||
|
/** Base interface for all metrics gatherers */
|
||||||
|
export interface MetricsCollector<T> {
|
||||||
|
/** collect the data currently gathered by the collector */
|
||||||
|
collect(): MaybePromise<T>;
|
||||||
|
/** reset the internal state of the collector */
|
||||||
|
reset(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creating a new instance from EventLoopDelaysMonitor will
|
||||||
|
* automatically start tracking event loop delays.
|
||||||
|
* See {@link IntervalHistogram}
|
||||||
|
* @public
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export interface IEventLoopDelaysMonitor<T = IntervalHistogram> {
|
||||||
|
/**
|
||||||
|
* Collect gathers event loop delays metrics from nodejs perf_hooks.monitorEventLoopDelay
|
||||||
|
* the histogram calculations start from the last time `reset` was called or this
|
||||||
|
* EventLoopDelaysMonitor instance was created.
|
||||||
|
*
|
||||||
|
* Returns metrics in milliseconds.
|
||||||
|
|
||||||
|
* @returns {IntervalHistogram}
|
||||||
|
*/
|
||||||
|
collect(): T;
|
||||||
|
/**
|
||||||
|
* Resets the collected histogram data.
|
||||||
|
*/
|
||||||
|
reset(): void;
|
||||||
|
/**
|
||||||
|
* Disables updating the interval timer for collecting new data points.
|
||||||
|
*/
|
||||||
|
stop(): void;
|
||||||
|
}
|
39
packages/core/metrics/core-metrics-server/src/contracts.ts
Normal file
39
packages/core/metrics/core-metrics-server/src/contracts.ts
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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 type { Observable } from 'rxjs';
|
||||||
|
import type { OpsMetrics } from './metrics';
|
||||||
|
/**
|
||||||
|
* APIs to retrieves metrics gathered and exposed by the core platform.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export interface MetricsServiceSetup {
|
||||||
|
/** Interval metrics are collected in milliseconds */
|
||||||
|
readonly collectionInterval: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve an observable emitting the {@link OpsMetrics} gathered.
|
||||||
|
* The observable will emit an initial value during core's `start` phase, and a new value every fixed interval of time,
|
||||||
|
* based on the `opts.interval` configuration property.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* core.metrics.getOpsMetrics$().subscribe(metrics => {
|
||||||
|
* // do something with the metrics
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
getOpsMetrics$: () => Observable<OpsMetrics>;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* {@inheritdoc MetricsServiceSetup}
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export type MetricsServiceStart = MetricsServiceSetup;
|
17
packages/core/metrics/core-metrics-server/src/index.ts
Normal file
17
packages/core/metrics/core-metrics-server/src/index.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* 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 type { MetricsServiceSetup, MetricsServiceStart } from './contracts';
|
||||||
|
export type { MetricsCollector, IEventLoopDelaysMonitor } from './collectors';
|
||||||
|
export type {
|
||||||
|
OpsMetrics,
|
||||||
|
IntervalHistogram,
|
||||||
|
OpsProcessMetrics,
|
||||||
|
OpsOsMetrics,
|
||||||
|
OpsServerMetrics,
|
||||||
|
} from './metrics';
|
|
@ -5,15 +5,39 @@
|
||||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
import { MaybePromise } from '@kbn/utility-types';
|
|
||||||
import type { IntervalHistogram } from '../types';
|
|
||||||
|
|
||||||
/** Base interface for all metrics gatherers */
|
/**
|
||||||
export interface MetricsCollector<T> {
|
* an IntervalHistogram object that samples and reports the event loop delay over time.
|
||||||
/** collect the data currently gathered by the collector */
|
* The delays will be reported in milliseconds.
|
||||||
collect(): MaybePromise<T>;
|
*
|
||||||
/** reset the internal state of the collector */
|
* @public
|
||||||
reset(): void;
|
*/
|
||||||
|
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;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,3 +155,30 @@ export interface OpsServerMetrics {
|
||||||
/** number of current concurrent connections to the server */
|
/** number of current concurrent connections to the server */
|
||||||
concurrent_connections: number;
|
concurrent_connections: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
/**
|
||||||
|
* Process related metrics.
|
||||||
|
* @deprecated use the processes field instead.
|
||||||
|
* @removeBy 8.8.0
|
||||||
|
*/
|
||||||
|
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'];
|
||||||
|
}
|
18
packages/core/metrics/core-metrics-server/tsconfig.json
Normal file
18
packages/core/metrics/core-metrics-server/tsconfig.json
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.bazel.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"emitDeclarationOnly": true,
|
||||||
|
"outDir": "target_types",
|
||||||
|
"rootDir": "src",
|
||||||
|
"stripInternal": false,
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
]
|
||||||
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
import { httpServiceMock } from '@kbn/core-http-browser-mocks';
|
import { httpServiceMock } from '@kbn/core-http-browser-mocks';
|
||||||
import type { StatusResponse } from '../../../../types/status';
|
import type { StatusResponse } from '../../../../types/status';
|
||||||
import { notificationServiceMock } from '../../../notifications/notifications_service.mock';
|
import { notificationServiceMock } from '../../../notifications/notifications_service.mock';
|
||||||
import { mocked } from '../../../../server/metrics/event_loop_delays/event_loop_delays_monitor.mocks';
|
import { mocked } from '@kbn/core-metrics-collectors-server-mocks';
|
||||||
import { loadStatus } from './load_status';
|
import { loadStatus } from './load_status';
|
||||||
|
|
||||||
const mockedResponse: StatusResponse = {
|
const mockedResponse: StatusResponse = {
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { config as RawElasticsearchConfig } from '@kbn/core-elasticsearch-server
|
||||||
import { config as RawHttpConfig } from '@kbn/core-http-server-internal';
|
import { config as RawHttpConfig } from '@kbn/core-http-server-internal';
|
||||||
import { savedObjectsConfig as RawSavedObjectsConfig } from '../saved_objects/saved_objects_config';
|
import { savedObjectsConfig as RawSavedObjectsConfig } from '../saved_objects/saved_objects_config';
|
||||||
import { httpServiceMock } from '@kbn/core-http-server-mocks';
|
import { httpServiceMock } from '@kbn/core-http-server-mocks';
|
||||||
import { metricsServiceMock } from '../metrics/metrics_service.mock';
|
import { metricsServiceMock } from '@kbn/core-metrics-server-mocks';
|
||||||
import { savedObjectsServiceMock } from '../saved_objects/saved_objects_service.mock';
|
import { savedObjectsServiceMock } from '../saved_objects/saved_objects_service.mock';
|
||||||
|
|
||||||
import { CoreUsageDataService } from './core_usage_data_service';
|
import { CoreUsageDataService } from './core_usage_data_service';
|
||||||
|
|
|
@ -22,6 +22,7 @@ import type { Logger } from '@kbn/logging';
|
||||||
import type { HttpConfigType, InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
|
import type { HttpConfigType, InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
|
||||||
import type { ElasticsearchServiceStart } from '@kbn/core-elasticsearch-server';
|
import type { ElasticsearchServiceStart } from '@kbn/core-elasticsearch-server';
|
||||||
import type { ElasticsearchConfigType } from '@kbn/core-elasticsearch-server-internal';
|
import type { ElasticsearchConfigType } from '@kbn/core-elasticsearch-server-internal';
|
||||||
|
import type { MetricsServiceSetup, OpsMetrics } from '@kbn/core-metrics-server';
|
||||||
import { SavedObjectsServiceStart, SavedObjectTypeRegistry } from '..';
|
import { SavedObjectsServiceStart, SavedObjectTypeRegistry } from '..';
|
||||||
|
|
||||||
import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config';
|
import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config';
|
||||||
|
@ -38,7 +39,6 @@ import { coreUsageStatsType } from './core_usage_stats';
|
||||||
import { LEGACY_URL_ALIAS_TYPE } from '../saved_objects/object_types';
|
import { LEGACY_URL_ALIAS_TYPE } from '../saved_objects/object_types';
|
||||||
import { CORE_USAGE_STATS_TYPE } from './constants';
|
import { CORE_USAGE_STATS_TYPE } from './constants';
|
||||||
import { CoreUsageStatsClient } from './core_usage_stats_client';
|
import { CoreUsageStatsClient } from './core_usage_stats_client';
|
||||||
import { MetricsServiceSetup, OpsMetrics } from '..';
|
|
||||||
import { CoreIncrementUsageCounter } from './types';
|
import { CoreIncrementUsageCounter } from './types';
|
||||||
|
|
||||||
export type ExposedConfigsToUsage = Map<string, Record<string, boolean>>;
|
export type ExposedConfigsToUsage = Map<string, Record<string, boolean>>;
|
||||||
|
|
|
@ -52,7 +52,8 @@ import type {
|
||||||
HttpServiceStart,
|
HttpServiceStart,
|
||||||
} from '@kbn/core-http-server';
|
} from '@kbn/core-http-server';
|
||||||
import type { PrebootServicePreboot } from '@kbn/core-preboot-server';
|
import type { PrebootServicePreboot } from '@kbn/core-preboot-server';
|
||||||
import type {
|
import type { MetricsServiceSetup, MetricsServiceStart } from '@kbn/core-metrics-server';
|
||||||
|
import {
|
||||||
ElasticsearchServiceSetup,
|
ElasticsearchServiceSetup,
|
||||||
ElasticsearchServiceStart,
|
ElasticsearchServiceStart,
|
||||||
ElasticsearchServicePreboot,
|
ElasticsearchServicePreboot,
|
||||||
|
@ -64,7 +65,6 @@ import { HttpResources } from './http_resources';
|
||||||
import { PluginsServiceSetup, PluginsServiceStart, PluginOpaqueId } from './plugins';
|
import { PluginsServiceSetup, PluginsServiceStart, PluginOpaqueId } from './plugins';
|
||||||
import { UiSettingsServiceSetup, UiSettingsServiceStart } from './ui_settings';
|
import { UiSettingsServiceSetup, UiSettingsServiceStart } from './ui_settings';
|
||||||
import { SavedObjectsServiceSetup, SavedObjectsServiceStart } from './saved_objects';
|
import { SavedObjectsServiceSetup, SavedObjectsServiceStart } from './saved_objects';
|
||||||
import { MetricsServiceSetup, MetricsServiceStart } from './metrics';
|
|
||||||
import { StatusServiceSetup } from './status';
|
import { StatusServiceSetup } from './status';
|
||||||
import { CoreUsageDataStart, CoreUsageDataSetup } from './core_usage_data';
|
import { CoreUsageDataStart, CoreUsageDataSetup } from './core_usage_data';
|
||||||
import { I18nServiceSetup } from './i18n';
|
import { I18nServiceSetup } from './i18n';
|
||||||
|
@ -402,8 +402,9 @@ export type {
|
||||||
MetricsServiceSetup,
|
MetricsServiceSetup,
|
||||||
MetricsServiceStart,
|
MetricsServiceStart,
|
||||||
IntervalHistogram,
|
IntervalHistogram,
|
||||||
} from './metrics';
|
IEventLoopDelaysMonitor,
|
||||||
export { EventLoopDelaysMonitor } from './metrics';
|
} from '@kbn/core-metrics-server';
|
||||||
|
export { EventLoopDelaysMonitor } from '@kbn/core-metrics-collectors-server-internal';
|
||||||
|
|
||||||
export type { I18nServiceSetup } from './i18n';
|
export type { I18nServiceSetup } from './i18n';
|
||||||
export type {
|
export type {
|
||||||
|
|
|
@ -15,7 +15,7 @@ import type { IRouter } from '@kbn/core-http-server';
|
||||||
import { contextServiceMock } from '@kbn/core-http-context-server-mocks';
|
import { contextServiceMock } from '@kbn/core-http-context-server-mocks';
|
||||||
import type { HttpService } from '@kbn/core-http-server-internal';
|
import type { HttpService } from '@kbn/core-http-server-internal';
|
||||||
import { executionContextServiceMock } from '@kbn/core-execution-context-server-mocks';
|
import { executionContextServiceMock } from '@kbn/core-execution-context-server-mocks';
|
||||||
import { ServerMetricsCollector } from '../../metrics/collectors/server';
|
import { ServerMetricsCollector } from '@kbn/core-metrics-collectors-server-internal';
|
||||||
import { setTimeout as setTimeoutPromise } from 'timers/promises';
|
import { setTimeout as setTimeoutPromise } from 'timers/promises';
|
||||||
|
|
||||||
describe('ServerMetricsCollector', () => {
|
describe('ServerMetricsCollector', () => {
|
||||||
|
|
|
@ -13,8 +13,8 @@ import { omit } from 'lodash';
|
||||||
import { ContextService } from '@kbn/core-http-context-server-internal';
|
import { ContextService } from '@kbn/core-http-context-server-internal';
|
||||||
import { createCoreContext, createHttpServer } from '@kbn/core-http-server-mocks';
|
import { createCoreContext, createHttpServer } from '@kbn/core-http-server-mocks';
|
||||||
import type { HttpService, InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
|
import type { HttpService, InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
|
||||||
import { metricsServiceMock } from '../../../metrics/metrics_service.mock';
|
import { metricsServiceMock } from '@kbn/core-metrics-server-mocks';
|
||||||
import type { MetricsServiceSetup } from '../../../metrics';
|
import type { MetricsServiceSetup } from '@kbn/core-metrics-server';
|
||||||
|
|
||||||
import { registerStatusRoute } from '../../../status/routes/status';
|
import { registerStatusRoute } from '../../../status/routes/status';
|
||||||
import { ServiceStatus, ServiceStatusLevels, ServiceStatusLevel } from '../../../status/types';
|
import { ServiceStatus, ServiceStatusLevels, ServiceStatusLevel } from '../../../status/types';
|
||||||
|
|
|
@ -32,6 +32,10 @@ import type {
|
||||||
InternalHttpServiceStart,
|
InternalHttpServiceStart,
|
||||||
} from '@kbn/core-http-server-internal';
|
} from '@kbn/core-http-server-internal';
|
||||||
import type {
|
import type {
|
||||||
|
InternalMetricsServiceSetup,
|
||||||
|
InternalMetricsServiceStart,
|
||||||
|
} from '@kbn/core-metrics-server-internal';
|
||||||
|
import {
|
||||||
InternalElasticsearchServicePreboot,
|
InternalElasticsearchServicePreboot,
|
||||||
InternalElasticsearchServiceSetup,
|
InternalElasticsearchServiceSetup,
|
||||||
InternalElasticsearchServiceStart,
|
InternalElasticsearchServiceStart,
|
||||||
|
@ -46,7 +50,6 @@ import {
|
||||||
InternalUiSettingsServiceSetup,
|
InternalUiSettingsServiceSetup,
|
||||||
InternalUiSettingsServiceStart,
|
InternalUiSettingsServiceStart,
|
||||||
} from './ui_settings';
|
} from './ui_settings';
|
||||||
import { InternalMetricsServiceSetup, InternalMetricsServiceStart } from './metrics';
|
|
||||||
import { InternalRenderingServiceSetup } from './rendering';
|
import { InternalRenderingServiceSetup } from './rendering';
|
||||||
import { InternalHttpResourcesPreboot, InternalHttpResourcesSetup } from './http_resources';
|
import { InternalHttpResourcesPreboot, InternalHttpResourcesSetup } from './http_resources';
|
||||||
import { InternalStatusServiceSetup } from './status';
|
import { InternalStatusServiceSetup } from './status';
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 type {
|
|
||||||
InternalMetricsServiceStart,
|
|
||||||
InternalMetricsServiceSetup,
|
|
||||||
MetricsServiceSetup,
|
|
||||||
MetricsServiceStart,
|
|
||||||
OpsMetrics,
|
|
||||||
IntervalHistogram,
|
|
||||||
} from './types';
|
|
||||||
export type { OpsProcessMetrics, OpsServerMetrics, OpsOsMetrics } from './collectors';
|
|
||||||
export { MetricsService } from './metrics_service';
|
|
||||||
export { opsConfig } from './ops_config';
|
|
||||||
export type { OpsConfigType } from './ops_config';
|
|
||||||
export { EventLoopDelaysMonitor } from './event_loop_delays';
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 { schema, TypeOf } from '@kbn/config-schema';
|
|
||||||
|
|
||||||
export const opsConfig = {
|
|
||||||
path: 'ops',
|
|
||||||
schema: schema.object({
|
|
||||||
interval: schema.duration({ defaultValue: '5s' }),
|
|
||||||
cGroupOverrides: schema.object({
|
|
||||||
cpuPath: schema.maybe(schema.string()),
|
|
||||||
cpuAcctPath: schema.maybe(schema.string()),
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
export type OpsConfigType = TypeOf<typeof opsConfig.schema>;
|
|
|
@ -1,104 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 { Observable } from 'rxjs';
|
|
||||||
import type { OpsProcessMetrics, OpsOsMetrics, OpsServerMetrics } from './collectors';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APIs to retrieves metrics gathered and exposed by the core platform.
|
|
||||||
*
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export interface MetricsServiceSetup {
|
|
||||||
/** Interval metrics are collected in milliseconds */
|
|
||||||
readonly collectionInterval: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve an observable emitting the {@link OpsMetrics} gathered.
|
|
||||||
* The observable will emit an initial value during core's `start` phase, and a new value every fixed interval of time,
|
|
||||||
* based on the `opts.interval` configuration property.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```ts
|
|
||||||
* core.metrics.getOpsMetrics$().subscribe(metrics => {
|
|
||||||
* // do something with the metrics
|
|
||||||
* })
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
getOpsMetrics$: () => Observable<OpsMetrics>;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* {@inheritdoc MetricsServiceSetup}
|
|
||||||
*
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export type MetricsServiceStart = MetricsServiceSetup;
|
|
||||||
|
|
||||||
export type InternalMetricsServiceSetup = MetricsServiceSetup;
|
|
||||||
export type InternalMetricsServiceStart = MetricsServiceStart;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
/**
|
|
||||||
* Process related metrics.
|
|
||||||
* @deprecated use the processes field instead.
|
|
||||||
* @removeBy 8.8.0
|
|
||||||
*/
|
|
||||||
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'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* an IntervalHistogram object that samples and reports the event loop delay over time.
|
|
||||||
* The delays will be reported in milliseconds.
|
|
||||||
*
|
|
||||||
* @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;
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -21,6 +21,7 @@ import { prebootServiceMock } from '@kbn/core-preboot-server-mocks';
|
||||||
import { contextServiceMock } from '@kbn/core-http-context-server-mocks';
|
import { contextServiceMock } from '@kbn/core-http-context-server-mocks';
|
||||||
import { httpServiceMock } from '@kbn/core-http-server-mocks';
|
import { httpServiceMock } from '@kbn/core-http-server-mocks';
|
||||||
import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
|
import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
|
||||||
|
import { metricsServiceMock } from '@kbn/core-metrics-server-mocks';
|
||||||
import { capabilitiesServiceMock } from '@kbn/core-capabilities-server-mocks';
|
import { capabilitiesServiceMock } from '@kbn/core-capabilities-server-mocks';
|
||||||
import type {
|
import type {
|
||||||
PluginInitializerContext,
|
PluginInitializerContext,
|
||||||
|
@ -37,7 +38,6 @@ import { typeRegistryMock as savedObjectsTypeRegistryMock } from './saved_object
|
||||||
import { renderingMock } from './rendering/rendering_service.mock';
|
import { renderingMock } from './rendering/rendering_service.mock';
|
||||||
import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
|
import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
|
||||||
import { SharedGlobalConfig } from './plugins';
|
import { SharedGlobalConfig } from './plugins';
|
||||||
import { metricsServiceMock } from './metrics/metrics_service.mock';
|
|
||||||
import { statusServiceMock } from './status/status_service.mock';
|
import { statusServiceMock } from './status/status_service.mock';
|
||||||
import { coreUsageDataServiceMock } from './core_usage_data/core_usage_data_service.mock';
|
import { coreUsageDataServiceMock } from './core_usage_data/core_usage_data_service.mock';
|
||||||
import { i18nServiceMock } from './i18n/i18n_service.mock';
|
import { i18nServiceMock } from './i18n/i18n_service.mock';
|
||||||
|
@ -54,7 +54,7 @@ export { savedObjectsClientMock } from './saved_objects/service/saved_objects_cl
|
||||||
export { migrationMocks } from './saved_objects/migrations/mocks';
|
export { migrationMocks } from './saved_objects/migrations/mocks';
|
||||||
export { typeRegistryMock as savedObjectsTypeRegistryMock } from './saved_objects/saved_objects_type_registry.mock';
|
export { typeRegistryMock as savedObjectsTypeRegistryMock } from './saved_objects/saved_objects_type_registry.mock';
|
||||||
export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
|
export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
|
||||||
export { metricsServiceMock } from './metrics/metrics_service.mock';
|
export { metricsServiceMock } from '@kbn/core-metrics-server-mocks';
|
||||||
export { renderingMock } from './rendering/rendering_service.mock';
|
export { renderingMock } from './rendering/rendering_service.mock';
|
||||||
export { statusServiceMock } from './status/status_service.mock';
|
export { statusServiceMock } from './status/status_service.mock';
|
||||||
export { contextServiceMock } from '@kbn/core-http-context-server-mocks';
|
export { contextServiceMock } from '@kbn/core-http-context-server-mocks';
|
||||||
|
|
|
@ -82,10 +82,10 @@ jest.doMock('@kbn/core-node-server-internal', () => ({
|
||||||
NodeService: jest.fn(() => mockNodeService),
|
NodeService: jest.fn(() => mockNodeService),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { metricsServiceMock } from './metrics/metrics_service.mock';
|
import { metricsServiceMock } from '@kbn/core-metrics-server-mocks';
|
||||||
|
|
||||||
export const mockMetricsService = metricsServiceMock.create();
|
export const mockMetricsService = metricsServiceMock.create();
|
||||||
jest.doMock('./metrics/metrics_service', () => ({
|
jest.doMock('@kbn/core-metrics-server-internal', () => ({
|
||||||
MetricsService: jest.fn(() => mockMetricsService),
|
MetricsService: jest.fn(() => mockMetricsService),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import {
|
||||||
ElasticsearchService,
|
ElasticsearchService,
|
||||||
config as elasticsearchConfig,
|
config as elasticsearchConfig,
|
||||||
} from '@kbn/core-elasticsearch-server-internal';
|
} from '@kbn/core-elasticsearch-server-internal';
|
||||||
|
import { MetricsService, opsConfig } from '@kbn/core-metrics-server-internal';
|
||||||
import { CapabilitiesService } from '@kbn/core-capabilities-server-internal';
|
import { CapabilitiesService } from '@kbn/core-capabilities-server-internal';
|
||||||
import { CoreApp } from './core_app';
|
import { CoreApp } from './core_app';
|
||||||
import { I18nService } from './i18n';
|
import { I18nService } from './i18n';
|
||||||
|
@ -49,7 +50,6 @@ import { RenderingService } from './rendering';
|
||||||
import { UiSettingsService } from './ui_settings';
|
import { UiSettingsService } from './ui_settings';
|
||||||
import { PluginsService, config as pluginsConfig } from './plugins';
|
import { PluginsService, config as pluginsConfig } from './plugins';
|
||||||
import { SavedObjectsService, SavedObjectsServiceStart } from './saved_objects';
|
import { SavedObjectsService, SavedObjectsServiceStart } from './saved_objects';
|
||||||
import { MetricsService, opsConfig } from './metrics';
|
|
||||||
// do not try to shorten the import to `./status`, it will break server test mocking
|
// do not try to shorten the import to `./status`, it will break server test mocking
|
||||||
import { StatusService } from './status/status_service';
|
import { StatusService } from './status/status_service';
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { PackageInfo } from '@kbn/config';
|
||||||
|
|
||||||
import type { PluginName } from '@kbn/core-base-common';
|
import type { PluginName } from '@kbn/core-base-common';
|
||||||
import type { IRouter } from '@kbn/core-http-server';
|
import type { IRouter } from '@kbn/core-http-server';
|
||||||
import { MetricsServiceSetup } from '../../metrics';
|
import type { MetricsServiceSetup } from '@kbn/core-metrics-server';
|
||||||
import type { CoreIncrementUsageCounter } from '../../core_usage_data/types';
|
import type { CoreIncrementUsageCounter } from '../../core_usage_data/types';
|
||||||
import { ServiceStatus, CoreStatus, ServiceStatusLevels } from '../types';
|
import { ServiceStatus, CoreStatus, ServiceStatusLevels } from '../types';
|
||||||
import { calculateLegacyStatus, LegacyStatusInfo } from '../legacy_status';
|
import { calculateLegacyStatus, LegacyStatusInfo } from '../legacy_status';
|
||||||
|
|
|
@ -21,7 +21,7 @@ import { environmentServiceMock } from '@kbn/core-environment-server-mocks';
|
||||||
import { mockRouter, RouterMock } from '@kbn/core-http-router-server-mocks';
|
import { mockRouter, RouterMock } from '@kbn/core-http-router-server-mocks';
|
||||||
import { httpServiceMock } from '@kbn/core-http-server-mocks';
|
import { httpServiceMock } from '@kbn/core-http-server-mocks';
|
||||||
import { ServiceStatusLevelSnapshotSerializer } from './test_utils';
|
import { ServiceStatusLevelSnapshotSerializer } from './test_utils';
|
||||||
import { metricsServiceMock } from '../metrics/metrics_service.mock';
|
import { metricsServiceMock } from '@kbn/core-metrics-server-mocks';
|
||||||
import { configServiceMock } from '@kbn/config-mocks';
|
import { configServiceMock } from '@kbn/config-mocks';
|
||||||
import { coreUsageDataServiceMock } from '../core_usage_data/core_usage_data_service.mock';
|
import { coreUsageDataServiceMock } from '../core_usage_data/core_usage_data_service.mock';
|
||||||
import { analyticsServiceMock } from '@kbn/core-analytics-server-mocks';
|
import { analyticsServiceMock } from '@kbn/core-analytics-server-mocks';
|
||||||
|
|
|
@ -26,8 +26,8 @@ import type { AnalyticsServiceSetup } from '@kbn/core-analytics-server';
|
||||||
import type { InternalEnvironmentServiceSetup } from '@kbn/core-environment-server-internal';
|
import type { InternalEnvironmentServiceSetup } from '@kbn/core-environment-server-internal';
|
||||||
import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
|
import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
|
||||||
import type { InternalElasticsearchServiceSetup } from '@kbn/core-elasticsearch-server-internal';
|
import type { InternalElasticsearchServiceSetup } from '@kbn/core-elasticsearch-server-internal';
|
||||||
|
import type { InternalMetricsServiceSetup } from '@kbn/core-metrics-server-internal';
|
||||||
import { InternalSavedObjectsServiceSetup } from '../saved_objects';
|
import { InternalSavedObjectsServiceSetup } from '../saved_objects';
|
||||||
import { InternalMetricsServiceSetup } from '../metrics';
|
|
||||||
import { registerStatusRoute } from './routes';
|
import { registerStatusRoute } from './routes';
|
||||||
import type { InternalCoreUsageDataSetup } from '../core_usage_data';
|
import type { InternalCoreUsageDataSetup } from '../core_usage_data';
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import { takeUntil, finalize, map } from 'rxjs/operators';
|
import { takeUntil, finalize, map } from 'rxjs/operators';
|
||||||
import { Observable, timer } from 'rxjs';
|
import { Observable, timer } from 'rxjs';
|
||||||
import type { ISavedObjectsRepository } from '@kbn/core/server';
|
import type { ISavedObjectsRepository } from '@kbn/core/server';
|
||||||
import type { EventLoopDelaysMonitor } from '@kbn/core/server';
|
import type { IEventLoopDelaysMonitor, IntervalHistogram } from '@kbn/core/server';
|
||||||
import {
|
import {
|
||||||
MONITOR_EVENT_LOOP_DELAYS_START,
|
MONITOR_EVENT_LOOP_DELAYS_START,
|
||||||
MONITOR_EVENT_LOOP_DELAYS_INTERVAL,
|
MONITOR_EVENT_LOOP_DELAYS_INTERVAL,
|
||||||
|
@ -27,7 +27,7 @@ export function startTrackingEventLoopDelaysUsage(
|
||||||
internalRepository: ISavedObjectsRepository,
|
internalRepository: ISavedObjectsRepository,
|
||||||
instanceUuid: string,
|
instanceUuid: string,
|
||||||
stopMonitoringEventLoop$: Observable<void>,
|
stopMonitoringEventLoop$: Observable<void>,
|
||||||
eventLoopDelaysMonitor: EventLoopDelaysMonitor,
|
eventLoopDelaysMonitor: IEventLoopDelaysMonitor<IntervalHistogram>,
|
||||||
configs: {
|
configs: {
|
||||||
collectionStartDelay?: number;
|
collectionStartDelay?: number;
|
||||||
collectionInterval?: number;
|
collectionInterval?: number;
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { takeUntil, finalize } from 'rxjs/operators';
|
||||||
import { Observable, timer } from 'rxjs';
|
import { Observable, timer } from 'rxjs';
|
||||||
import type { Logger } from '@kbn/core/server';
|
import type { Logger } from '@kbn/core/server';
|
||||||
import type { UsageCounter } from '@kbn/usage-collection-plugin/server';
|
import type { UsageCounter } from '@kbn/usage-collection-plugin/server';
|
||||||
import type { EventLoopDelaysMonitor } from '@kbn/core/server';
|
import type { IEventLoopDelaysMonitor, IntervalHistogram } from '@kbn/core/server';
|
||||||
import {
|
import {
|
||||||
MONITOR_EVENT_LOOP_THRESHOLD_START,
|
MONITOR_EVENT_LOOP_THRESHOLD_START,
|
||||||
MONITOR_EVENT_LOOP_THRESHOLD_INTERVAL,
|
MONITOR_EVENT_LOOP_THRESHOLD_INTERVAL,
|
||||||
|
@ -27,7 +27,7 @@ export function startTrackingEventLoopDelaysThreshold(
|
||||||
eventLoopCounter: UsageCounter,
|
eventLoopCounter: UsageCounter,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
stopMonitoringEventLoop$: Observable<void>,
|
stopMonitoringEventLoop$: Observable<void>,
|
||||||
eventLoopDelaysMonitor: EventLoopDelaysMonitor,
|
eventLoopDelaysMonitor: IEventLoopDelaysMonitor<IntervalHistogram>,
|
||||||
configs: {
|
configs: {
|
||||||
warnThreshold?: number;
|
warnThreshold?: number;
|
||||||
collectionStartDelay?: number;
|
collectionStartDelay?: number;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import {
|
import {
|
||||||
IRouter,
|
IRouter,
|
||||||
ISavedObjectsRepository,
|
ISavedObjectsRepository,
|
||||||
MetricsServiceSetup,
|
type MetricsServiceSetup,
|
||||||
ServiceStatus,
|
ServiceStatus,
|
||||||
} from '@kbn/core/server';
|
} from '@kbn/core/server';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import { BehaviorSubject } from 'rxjs';
|
import { BehaviorSubject } from 'rxjs';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MetricsServiceSetup,
|
type MetricsServiceSetup,
|
||||||
RequestHandlerContext,
|
RequestHandlerContext,
|
||||||
ServiceStatus,
|
ServiceStatus,
|
||||||
ServiceStatusLevels,
|
ServiceStatusLevels,
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { firstValueFrom, Observable } from 'rxjs';
|
||||||
import {
|
import {
|
||||||
ElasticsearchClient,
|
ElasticsearchClient,
|
||||||
IRouter,
|
IRouter,
|
||||||
MetricsServiceSetup,
|
type MetricsServiceSetup,
|
||||||
SavedObjectsClientContract,
|
SavedObjectsClientContract,
|
||||||
ServiceStatus,
|
ServiceStatus,
|
||||||
ServiceStatusLevels,
|
ServiceStatusLevels,
|
||||||
|
|
40
yarn.lock
40
yarn.lock
|
@ -3299,6 +3299,26 @@
|
||||||
version "0.0.0"
|
version "0.0.0"
|
||||||
uid ""
|
uid ""
|
||||||
|
|
||||||
|
"@kbn/core-metrics-collectors-server-internal@link:bazel-bin/packages/core/metrics/core-metrics-collectors-server-internal":
|
||||||
|
version "0.0.0"
|
||||||
|
uid ""
|
||||||
|
|
||||||
|
"@kbn/core-metrics-collectors-server-mocks@link:bazel-bin/packages/core/metrics/core-metrics-collectors-server-mocks":
|
||||||
|
version "0.0.0"
|
||||||
|
uid ""
|
||||||
|
|
||||||
|
"@kbn/core-metrics-server-internal@link:bazel-bin/packages/core/metrics/core-metrics-server-internal":
|
||||||
|
version "0.0.0"
|
||||||
|
uid ""
|
||||||
|
|
||||||
|
"@kbn/core-metrics-server-mocks@link:bazel-bin/packages/core/metrics/core-metrics-server-mocks":
|
||||||
|
version "0.0.0"
|
||||||
|
uid ""
|
||||||
|
|
||||||
|
"@kbn/core-metrics-server@link:bazel-bin/packages/core/metrics/core-metrics-server":
|
||||||
|
version "0.0.0"
|
||||||
|
uid ""
|
||||||
|
|
||||||
"@kbn/core-node-server-internal@link:bazel-bin/packages/core/node/core-node-server-internal":
|
"@kbn/core-node-server-internal@link:bazel-bin/packages/core/node/core-node-server-internal":
|
||||||
version "0.0.0"
|
version "0.0.0"
|
||||||
uid ""
|
uid ""
|
||||||
|
@ -7019,6 +7039,26 @@
|
||||||
version "0.0.0"
|
version "0.0.0"
|
||||||
uid ""
|
uid ""
|
||||||
|
|
||||||
|
"@types/kbn__core-metrics-collectors-server-internal@link:bazel-bin/packages/core/metrics/core-metrics-collectors-server-internal/npm_module_types":
|
||||||
|
version "0.0.0"
|
||||||
|
uid ""
|
||||||
|
|
||||||
|
"@types/kbn__core-metrics-collectors-server-mocks@link:bazel-bin/packages/core/metrics/core-metrics-collectors-server-mocks/npm_module_types":
|
||||||
|
version "0.0.0"
|
||||||
|
uid ""
|
||||||
|
|
||||||
|
"@types/kbn__core-metrics-server-internal@link:bazel-bin/packages/core/metrics/core-metrics-server-internal/npm_module_types":
|
||||||
|
version "0.0.0"
|
||||||
|
uid ""
|
||||||
|
|
||||||
|
"@types/kbn__core-metrics-server-mocks@link:bazel-bin/packages/core/metrics/core-metrics-server-mocks/npm_module_types":
|
||||||
|
version "0.0.0"
|
||||||
|
uid ""
|
||||||
|
|
||||||
|
"@types/kbn__core-metrics-server@link:bazel-bin/packages/core/metrics/core-metrics-server/npm_module_types":
|
||||||
|
version "0.0.0"
|
||||||
|
uid ""
|
||||||
|
|
||||||
"@types/kbn__core-node-server-internal@link:bazel-bin/packages/core/node/core-node-server-internal/npm_module_types":
|
"@types/kbn__core-node-server-internal@link:bazel-bin/packages/core/node/core-node-server-internal/npm_module_types":
|
||||||
version "0.0.0"
|
version "0.0.0"
|
||||||
uid ""
|
uid ""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue