From a8f94bf5cd6afcbd8c6e71ad9923aea05b09c3c3 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Wed, 10 Nov 2021 17:28:24 -0700 Subject: [PATCH 1/7] Handles ns to ms conversion for event loop delay metrics --- .../event_loop_delays_monitor.mocks.ts | 39 ++++++++++++--- .../event_loop_delays_monitor.test.ts | 16 +++++-- .../event_loop_delays_monitor.ts | 47 ++++++++++++++----- src/core/server/metrics/types.ts | 2 +- .../collectors/event_loop_delays/constants.ts | 2 +- .../event_loop_delays/track_delays.ts | 1 + .../event_loop_delays/track_threshold.ts | 6 +-- .../application/pages/kibana/instance.tsx | 3 ++ .../public/components/chart/get_units.js | 1 + 9 files changed, 91 insertions(+), 26 deletions(-) diff --git a/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.mocks.ts b/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.mocks.ts index 691bfc5030c93..5559a2be5b8d2 100644 --- a/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.mocks.ts +++ b/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.mocks.ts @@ -9,15 +9,17 @@ import moment from 'moment'; import type { EventLoopDelaysMonitor } from './event_loop_delays_monitor'; import type { IntervalHistogram } from '../types'; -function createMockHistogram(overwrites: Partial = {}): IntervalHistogram { +function createMockRawNsDataHistogram( + overwrites: Partial = {} +): IntervalHistogram { const now = Date.now(); - return { + const mockedRawCollectedDataInNs = { min: 9093120, max: 53247999, - mean: 11993238.600747818, + mean: 11993238, exceeds: 0, - stddev: 1168191.9357543814, + stddev: 1168191, fromTimestamp: moment(now).toISOString(), lastUpdatedAt: moment(now).toISOString(), percentiles: { @@ -28,6 +30,31 @@ function createMockHistogram(overwrites: Partial = {}): Inter }, ...overwrites, }; + return mockedRawCollectedDataInNs; +} + +function createMockMonitorDataMsHistogram( + overwrites: Partial = {} +): 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() { @@ -40,12 +67,12 @@ function createMockEventLoopDelaysMonitor() { stop: jest.fn(), }); - mockCollect.mockReturnValue(createMockHistogram()); + mockCollect.mockReturnValue(createMockMonitorDataMsHistogram()); // this must mock the return value of the public collect method from this monitor. return new MockEventLoopDelaysMonitor(); } export const mocked = { - createHistogram: createMockHistogram, + createHistogram: createMockRawNsDataHistogram, // raw data as received from Node.js perf_hooks.monitorEventLoopDelay([options]) createEventLoopDelaysMonitor: createMockEventLoopDelaysMonitor, }; diff --git a/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.test.ts b/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.test.ts index 3e88dbca8f4e7..052f291f76889 100644 --- a/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.test.ts +++ b/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.test.ts @@ -9,7 +9,7 @@ /* eslint-disable dot-notation */ jest.mock('perf_hooks'); import { monitorEventLoopDelay } from 'perf_hooks'; -import { EventLoopDelaysMonitor } from './event_loop_delays_monitor'; +import { EventLoopDelaysMonitor, nsToMs } from './event_loop_delays_monitor'; import { mocked } from './event_loop_delays_monitor.mocks'; describe('EventLoopDelaysMonitor', () => { @@ -39,10 +39,20 @@ describe('EventLoopDelaysMonitor', () => { expect(eventLoopDelaysMonitor['loopMonitor'].percentile).toHaveBeenNthCalledWith(3, 95); expect(eventLoopDelaysMonitor['loopMonitor'].percentile).toHaveBeenNthCalledWith(4, 99); - // mocked perf_hook returns `mocked.createHistogram()`. + // mocked perf_hook returns `mocked.createNsHistogram()` that returns data in ns. + // The `collect` function returns the data in ms. // This ensures that the wiring of the `collect` function is correct. const mockedHistogram = mocked.createHistogram(); - expect(histogramData).toEqual(mockedHistogram); + + expect(histogramData.min).toEqual(nsToMs(mockedHistogram.min)); + expect(histogramData.max).toEqual(nsToMs(mockedHistogram.max)); + expect(histogramData.mean).toEqual(nsToMs(mockedHistogram.mean)); + expect(histogramData.stddev).toEqual(nsToMs(mockedHistogram.stddev)); + expect(histogramData.exceeds).toEqual(nsToMs(mockedHistogram.exceeds)); + expect(histogramData.percentiles['50']).toEqual(nsToMs(mockedHistogram.percentiles['50'])); + expect(histogramData.percentiles['75']).toEqual(nsToMs(mockedHistogram.percentiles['75'])); + expect(histogramData.percentiles['95']).toEqual(nsToMs(mockedHistogram.percentiles['95'])); + expect(histogramData.percentiles['99']).toEqual(nsToMs(mockedHistogram.percentiles['99'])); }); test('#reset resets histogram data', () => { diff --git a/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts b/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts index 0f3035c14a923..dcbff5cd5f5c2 100644 --- a/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts +++ b/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts @@ -6,10 +6,23 @@ * Side Public License, v 1. */ +import moment from 'moment'; import type { IntervalHistogram as PerfIntervalHistogram } from 'perf_hooks'; import { monitorEventLoopDelay } from 'perf_hooks'; import type { IntervalHistogram } from '../types'; +/** + * Nanosecond to milisecond conversion unit + */ +export const ONE_MILLISECOND_AS_NANOSECONDS = 1000000; + +/** + * Converts time metric from ns to ms + **/ +export function nsToMs(metric: number) { + return moment.duration(metric / ONE_MILLISECOND_AS_NANOSECONDS).asMilliseconds(); +} + export class EventLoopDelaysMonitor { private readonly loopMonitor: PerfIntervalHistogram; private fromTimestamp: Date; @@ -28,31 +41,41 @@ export class EventLoopDelaysMonitor { * 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. + * + * Node's native monitorEventLoopDelay returns the data in nanoseconds and we convert to ms. + * @returns {IntervalHistogram} */ + public collect(): IntervalHistogram { const lastUpdated = new Date(); this.loopMonitor.disable(); - const { min, max, mean, exceeds, stddev } = this.loopMonitor; + const { + min: minNs, + max: maxNs, + mean: meanNs, + exceeds: exceedsNs, + stddev: stddevNs, + } = this.loopMonitor; - const collectedData: IntervalHistogram = { - min, - max, - mean, - exceeds, - stddev, + const collectedDataMs: IntervalHistogram = { + min: nsToMs(minNs), + max: nsToMs(maxNs), + mean: nsToMs(meanNs), + exceeds: nsToMs(exceedsNs), + stddev: nsToMs(stddevNs), fromTimestamp: this.fromTimestamp.toISOString(), lastUpdatedAt: lastUpdated.toISOString(), percentiles: { - 50: this.loopMonitor.percentile(50), - 75: this.loopMonitor.percentile(75), - 95: this.loopMonitor.percentile(95), - 99: this.loopMonitor.percentile(99), + 50: nsToMs(this.loopMonitor.percentile(50)), + 75: nsToMs(this.loopMonitor.percentile(75)), + 95: nsToMs(this.loopMonitor.percentile(95)), + 99: nsToMs(this.loopMonitor.percentile(99)), }, }; this.loopMonitor.enable(); - return collectedData; + return collectedDataMs; } /** diff --git a/src/core/server/metrics/types.ts b/src/core/server/metrics/types.ts index 550a60d0d295a..20594f5122f08 100644 --- a/src/core/server/metrics/types.ts +++ b/src/core/server/metrics/types.ts @@ -70,7 +70,7 @@ export interface OpsMetrics { /** * an IntervalHistogram object that samples and reports the event loop delay over time. - * The delays will be reported in nanoseconds. + * The delays will be reported in milliseconds. * * @public */ diff --git a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/constants.ts b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/constants.ts index 4661441a15a6b..99586f7612b01 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/constants.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/constants.ts @@ -32,7 +32,7 @@ export const MONITOR_EVENT_LOOP_DELAYS_RESET = 24 * 60 * 60 * 1000; export const MONITOR_EVENT_LOOP_DELAYS_START = 1 * 60 * 1000; /** - * Mean event loop delay threshold for logging a warning. + * Mean event loop delay threshold in ms for logging a warning. */ export const MONITOR_EVENT_LOOP_WARN_THRESHOLD = 350; diff --git a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_delays.ts b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_delays.ts index 33266cdbd9792..39d4cbcb84824 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_delays.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_delays.ts @@ -21,6 +21,7 @@ import { storeHistogram } from './saved_objects'; * The monitoring of the event loop starts immediately. * The first collection of the histogram happens after 1 minute. * The daily histogram data is updated every 1 hour. + * The histogram metrics are in milliseconds. */ export function startTrackingEventLoopDelaysUsage( internalRepository: ISavedObjectsRepository, diff --git a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts index ba4e12a7bfced..e7f6e84ff884b 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts @@ -48,12 +48,12 @@ export function startTrackingEventLoopDelaysThreshold( finalize(() => eventLoopDelaysMonitor.stop()) ) .subscribe(async () => { - const { mean } = eventLoopDelaysMonitor.collect(); + const { mean: meanMS } = eventLoopDelaysMonitor.collect(); const meanDurationMs = moment - .duration(mean / ONE_MILLISECOND_AS_NANOSECONDS) + .duration(meanMS / ONE_MILLISECOND_AS_NANOSECONDS) // this will now be in ms .asMilliseconds(); - if (meanDurationMs > warnThreshold) { + if (meanMS > warnThreshold) { logger.warn( `Average event loop delay threshold exceeded ${warnThreshold}ms. Received ${meanDurationMs}ms. ` + `See https://ela.st/kibana-scaling-considerations for more information about scaling Kibana.` diff --git a/x-pack/plugins/monitoring/public/application/pages/kibana/instance.tsx b/x-pack/plugins/monitoring/public/application/pages/kibana/instance.tsx index 262590b6806af..d56815a84737a 100644 --- a/x-pack/plugins/monitoring/public/application/pages/kibana/instance.tsx +++ b/x-pack/plugins/monitoring/public/application/pages/kibana/instance.tsx @@ -36,6 +36,8 @@ import { RULE_KIBANA_VERSION_MISMATCH } from '../../../../common/constants'; const KibanaInstance = ({ data, alerts }: { data: any; alerts: any }) => { const { zoomInfo, onBrush } = useCharts(); + console.log('do we interpret the data correctly here? I think we do', data); + console.log('--------->>>>>data.metrics.kibana_process_delay', data.metrics.kibana_process_delay); return ( @@ -148,6 +150,7 @@ export const KibanaInstancePage: React.FC = ({ clusters }) => { }, }), }); + console.log('what is the raw response to the http call in monitoring public post?', response); setData(response); setInstanceName(response.kibanaSummary.name); const alertsResponse = await fetchAlerts({ diff --git a/x-pack/plugins/monitoring/public/components/chart/get_units.js b/x-pack/plugins/monitoring/public/components/chart/get_units.js index 6f7c2b61c99d9..698eb774e47f8 100644 --- a/x-pack/plugins/monitoring/public/components/chart/get_units.js +++ b/x-pack/plugins/monitoring/public/components/chart/get_units.js @@ -10,6 +10,7 @@ import numeral from '@elastic/numeral'; export function getUnits(series) { let units = get(series, '[0].metric.units'); + console.log('the units in monitoring:', units); // For Bytes, find the largest unit from any data set's _last_ item if (units === 'B') { From 5d7e2b7533ee687948cd01c2009c6652f0d8c80d Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Thu, 11 Nov 2021 18:54:34 -0700 Subject: [PATCH 2/7] removes debugging logs --- .../monitoring/public/application/pages/kibana/instance.tsx | 3 --- x-pack/plugins/monitoring/public/components/chart/get_units.js | 1 - 2 files changed, 4 deletions(-) diff --git a/x-pack/plugins/monitoring/public/application/pages/kibana/instance.tsx b/x-pack/plugins/monitoring/public/application/pages/kibana/instance.tsx index d56815a84737a..262590b6806af 100644 --- a/x-pack/plugins/monitoring/public/application/pages/kibana/instance.tsx +++ b/x-pack/plugins/monitoring/public/application/pages/kibana/instance.tsx @@ -36,8 +36,6 @@ import { RULE_KIBANA_VERSION_MISMATCH } from '../../../../common/constants'; const KibanaInstance = ({ data, alerts }: { data: any; alerts: any }) => { const { zoomInfo, onBrush } = useCharts(); - console.log('do we interpret the data correctly here? I think we do', data); - console.log('--------->>>>>data.metrics.kibana_process_delay', data.metrics.kibana_process_delay); return ( @@ -150,7 +148,6 @@ export const KibanaInstancePage: React.FC = ({ clusters }) => { }, }), }); - console.log('what is the raw response to the http call in monitoring public post?', response); setData(response); setInstanceName(response.kibanaSummary.name); const alertsResponse = await fetchAlerts({ diff --git a/x-pack/plugins/monitoring/public/components/chart/get_units.js b/x-pack/plugins/monitoring/public/components/chart/get_units.js index 698eb774e47f8..6f7c2b61c99d9 100644 --- a/x-pack/plugins/monitoring/public/components/chart/get_units.js +++ b/x-pack/plugins/monitoring/public/components/chart/get_units.js @@ -10,7 +10,6 @@ import numeral from '@elastic/numeral'; export function getUnits(series) { let units = get(series, '[0].metric.units'); - console.log('the units in monitoring:', units); // For Bytes, find the largest unit from any data set's _last_ item if (units === 'B') { From 150c75e42a3a6843064459b555f148c22844a32f Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 12 Nov 2021 16:05:47 -0700 Subject: [PATCH 3/7] Removes ns -> ms conversion factor from kibana_usage_collection --- .../metrics/event_loop_delays/event_loop_delays_monitor.ts | 2 +- .../server/collectors/event_loop_delays/track_threshold.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts b/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts index dcbff5cd5f5c2..21e711261f974 100644 --- a/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts +++ b/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts @@ -42,7 +42,7 @@ export class EventLoopDelaysMonitor { * the histogram calculations start from the last time `reset` was called or this * EventLoopDelaysMonitor instance was created. * - * Node's native monitorEventLoopDelay returns the data in nanoseconds and we convert to ms. + * Returns metrics in milliseconds. * @returns {IntervalHistogram} */ diff --git a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts index e7f6e84ff884b..408d76df782f8 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts @@ -49,13 +49,10 @@ export function startTrackingEventLoopDelaysThreshold( ) .subscribe(async () => { const { mean: meanMS } = eventLoopDelaysMonitor.collect(); - const meanDurationMs = moment - .duration(meanMS / ONE_MILLISECOND_AS_NANOSECONDS) // this will now be in ms - .asMilliseconds(); if (meanMS > warnThreshold) { logger.warn( - `Average event loop delay threshold exceeded ${warnThreshold}ms. Received ${meanDurationMs}ms. ` + + `Average event loop delay threshold exceeded ${warnThreshold}ms. Received ${meanMS}ms. ` + `See https://ela.st/kibana-scaling-considerations for more information about scaling Kibana.` ); From 5ce71d48cebfd92a8cda05103b3d7c4fa5de6d7d Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 12 Nov 2021 16:32:05 -0700 Subject: [PATCH 4/7] removes unused import and constant --- .../server/collectors/event_loop_delays/constants.ts | 5 ----- .../server/collectors/event_loop_delays/track_threshold.ts | 2 -- 2 files changed, 7 deletions(-) diff --git a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/constants.ts b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/constants.ts index 99586f7612b01..c6e7604723a7a 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/constants.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/constants.ts @@ -45,8 +45,3 @@ export const MONITOR_EVENT_LOOP_THRESHOLD_START = 1 * 60 * 1000; * Check the event loop utilization every 30 seconds */ export const MONITOR_EVENT_LOOP_THRESHOLD_INTERVAL = 30 * 1000; - -/** - * Nanosecond to milisecond conversion unit - */ -export const ONE_MILLISECOND_AS_NANOSECONDS = 1000000; diff --git a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts index 408d76df782f8..d30db883cae60 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_threshold.ts @@ -9,13 +9,11 @@ import { takeUntil, finalize } from 'rxjs/operators'; import { Observable, timer } from 'rxjs'; import type { Logger } from 'kibana/server'; -import moment from 'moment'; import type { UsageCounter } from '../../../../usage_collection/server'; import { MONITOR_EVENT_LOOP_THRESHOLD_START, MONITOR_EVENT_LOOP_THRESHOLD_INTERVAL, MONITOR_EVENT_LOOP_WARN_THRESHOLD, - ONE_MILLISECOND_AS_NANOSECONDS, } from './constants'; import type { EventLoopDelaysMonitor } from '../../../../../core/server'; From f0ec458714351b3bf18ff6c322fc81a8a359fbd2 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 12 Nov 2021 16:33:41 -0700 Subject: [PATCH 5/7] Adds units to telemetry schema --- .../collectors/event_loop_delays/schema.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/schema.ts b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/schema.ts index 757e96e5602f0..7ac0bd408c49b 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/schema.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/schema.ts @@ -59,19 +59,19 @@ export const eventLoopDelaysUsageSchema: MakeSchemaFrom Date: Fri, 12 Nov 2021 17:05:58 -0700 Subject: [PATCH 6/7] updates telemetry schema --- src/plugins/telemetry/schema/oss_plugins.json | 18 +++++++++--------- .../schema/xpack_plugins.json | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/plugins/telemetry/schema/oss_plugins.json b/src/plugins/telemetry/schema/oss_plugins.json index 21273482dd2b8..55349b4df9fe9 100644 --- a/src/plugins/telemetry/schema/oss_plugins.json +++ b/src/plugins/telemetry/schema/oss_plugins.json @@ -6944,19 +6944,19 @@ "min": { "type": "long", "_meta": { - "description": "The minimum recorded event loop delay." + "description": "The minimum recorded event loop delay in ms." } }, "max": { "type": "long", "_meta": { - "description": "The maximum recorded event loop delay." + "description": "The maximum recorded event loop delay in ms." } }, "mean": { "type": "long", "_meta": { - "description": "The mean of the recorded event loop delays." + "description": "The mean of the recorded event loop delays in ms." } }, "exceeds": { @@ -6968,7 +6968,7 @@ "stddev": { "type": "long", "_meta": { - "description": "The standard deviation of the recorded event loop delays." + "description": "The standard deviation of the recorded event loop delays in ms." } }, "percentiles": { @@ -6976,25 +6976,25 @@ "50": { "type": "long", "_meta": { - "description": "The 50th accumulated percentile distribution" + "description": "The 50th accumulated percentile distribution in ms" } }, "75": { "type": "long", "_meta": { - "description": "The 75th accumulated percentile distribution" + "description": "The 75th accumulated percentile distribution in ms" } }, "95": { "type": "long", "_meta": { - "description": "The 95th accumulated percentile distribution" + "description": "The 95th accumulated percentile distribution in ms" } }, "99": { "type": "long", "_meta": { - "description": "The 99th accumulated percentile distribution" + "description": "The 99th accumulated percentile distribution in ms" } } } @@ -9170,4 +9170,4 @@ } } } -} \ No newline at end of file +} diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json index 13caed52ded84..55efcd4d15a33 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @@ -283,29 +283,29 @@ } } }, - "throttle_time_number_s": { + "schedule_time": { "properties": { "min": { - "type": "long" + "type": "keyword" }, "avg": { - "type": "float" + "type": "keyword" }, "max": { - "type": "long" + "type": "keyword" } } }, - "schedule_time": { + "throttle_time_number_s": { "properties": { "min": { - "type": "keyword" + "type": "long" }, "avg": { - "type": "keyword" + "type": "float" }, "max": { - "type": "keyword" + "type": "long" } } }, From 55a613af327afb0c06b2bc0c1ccea2d199870efc Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Mon, 15 Nov 2021 11:18:36 -0700 Subject: [PATCH 7/7] Addresses review comments --- .../event_loop_delays/event_loop_delays_monitor.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts b/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts index 21e711261f974..d36d5428be4d9 100644 --- a/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts +++ b/src/core/server/metrics/event_loop_delays/event_loop_delays_monitor.ts @@ -6,7 +6,6 @@ * Side Public License, v 1. */ -import moment from 'moment'; import type { IntervalHistogram as PerfIntervalHistogram } from 'perf_hooks'; import { monitorEventLoopDelay } from 'perf_hooks'; import type { IntervalHistogram } from '../types'; @@ -14,13 +13,13 @@ import type { IntervalHistogram } from '../types'; /** * Nanosecond to milisecond conversion unit */ -export const ONE_MILLISECOND_AS_NANOSECONDS = 1000000; +export const ONE_MILLISECOND_AS_NANOSECONDS = 1_000_000; /** * Converts time metric from ns to ms **/ export function nsToMs(metric: number) { - return moment.duration(metric / ONE_MILLISECOND_AS_NANOSECONDS).asMilliseconds(); + return metric / ONE_MILLISECOND_AS_NANOSECONDS; } export class EventLoopDelaysMonitor { @@ -58,7 +57,7 @@ export class EventLoopDelaysMonitor { stddev: stddevNs, } = this.loopMonitor; - const collectedDataMs: IntervalHistogram = { + const collectedData: IntervalHistogram = { min: nsToMs(minNs), max: nsToMs(maxNs), mean: nsToMs(meanNs), @@ -75,7 +74,7 @@ export class EventLoopDelaysMonitor { }; this.loopMonitor.enable(); - return collectedDataMs; + return collectedData; } /**