From dbb34ff415193278983b995f6a670e86e7462a37 Mon Sep 17 00:00:00 2001 From: pikalovArtemN Date: Fri, 17 May 2024 15:17:50 +0300 Subject: [PATCH] lint(instrumentation-runtime-node): lint --- .../src/consts/attributes.ts | 17 +++- .../src/instrumentation.ts | 23 ++++-- .../src/metrics/baseCollector.ts | 16 ++-- .../src/metrics/eventLoopDelayCollector.ts | 80 +++++++++---------- .../src/metrics/gcCollector.ts | 18 +++-- .../src/metrics/heapSizeAndUsedCollector.ts | 43 +++++----- .../metrics/heapSpacesSizeAndUsedCollector.ts | 67 +++++++--------- .../src/types/ConventionalNamePrefix.ts | 19 ++++- .../src/types/heapSizes.ts | 19 ++++- .../src/types/heapSpaces.ts | 21 ++++- .../test/event_loop_delay.test.ts | 20 +++-- .../test/event_loop_utilization.test.ts | 18 +++-- .../test/heap_size_and_used.test.ts | 64 +++++++++------ .../test/heap_space_and_used.test.ts | 42 +++++++--- 14 files changed, 292 insertions(+), 175 deletions(-) diff --git a/plugins/node/instrumentation-runtime-node/src/consts/attributes.ts b/plugins/node/instrumentation-runtime-node/src/consts/attributes.ts index 4d46289a10..cf304a8765 100644 --- a/plugins/node/instrumentation-runtime-node/src/consts/attributes.ts +++ b/plugins/node/instrumentation-runtime-node/src/consts/attributes.ts @@ -1,3 +1,18 @@ -export const NODE_JS_VERSION_ATTRIBUTE = "nodejsruntime.version" +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const NODE_JS_VERSION_ATTRIBUTE = 'nodejsruntime.version'; export const V8_HEAP_SIZE_STATE_ATTRIBUTE = 'heap.size.state'; export const V8_HEAP_SIZE = 'heap.size'; diff --git a/plugins/node/instrumentation-runtime-node/src/instrumentation.ts b/plugins/node/instrumentation-runtime-node/src/instrumentation.ts index 621b132cc1..0e382c9bb9 100644 --- a/plugins/node/instrumentation-runtime-node/src/instrumentation.ts +++ b/plugins/node/instrumentation-runtime-node/src/instrumentation.ts @@ -23,13 +23,12 @@ import { EventLoopDelayCollector } from './metrics/eventLoopDelayCollector'; import { GCCollector } from './metrics/gcCollector'; import { HeapSizeAndUsedCollector } from './metrics/heapSizeAndUsedCollector'; import { HeapSpacesSizeAndUsedCollector } from './metrics/heapSpacesSizeAndUsedCollector'; -import {ConventionalNamePrefix} from "./types/ConventionalNamePrefix"; +import { ConventionalNamePrefix } from './types/ConventionalNamePrefix'; const DEFAULT_CONFIG: RuntimeNodeInstrumentationConfig = { monitoringPrecision: 5000, }; - export class RuntimeNodeInstrumentation extends InstrumentationBase { private _collectors: MetricCollector[] = []; @@ -40,11 +39,23 @@ export class RuntimeNodeInstrumentation extends InstrumentationBase { Object.assign({}, DEFAULT_CONFIG, config) ); this._collectors = [ - new EventLoopUtilizationCollector(this._config, ConventionalNamePrefix.NodeJsRuntime), - new EventLoopDelayCollector(this._config, ConventionalNamePrefix.NodeJsRuntime), + new EventLoopUtilizationCollector( + this._config, + ConventionalNamePrefix.NodeJsRuntime + ), + new EventLoopDelayCollector( + this._config, + ConventionalNamePrefix.NodeJsRuntime + ), new GCCollector(this._config, ConventionalNamePrefix.V8EnjineRuntime), - new HeapSizeAndUsedCollector(this._config, ConventionalNamePrefix.V8EnjineRuntime), - new HeapSpacesSizeAndUsedCollector(this._config, ConventionalNamePrefix.V8EnjineRuntime), + new HeapSizeAndUsedCollector( + this._config, + ConventionalNamePrefix.V8EnjineRuntime + ), + new HeapSpacesSizeAndUsedCollector( + this._config, + ConventionalNamePrefix.V8EnjineRuntime + ), ]; if (this._config.enabled) { for (const collector of this._collectors) { diff --git a/plugins/node/instrumentation-runtime-node/src/metrics/baseCollector.ts b/plugins/node/instrumentation-runtime-node/src/metrics/baseCollector.ts index 917c89435b..d0155f1c62 100644 --- a/plugins/node/instrumentation-runtime-node/src/metrics/baseCollector.ts +++ b/plugins/node/instrumentation-runtime-node/src/metrics/baseCollector.ts @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {MetricCollector} from '../types/metricCollector'; -import {Meter} from '@opentelemetry/api'; -import {clearInterval} from 'node:timers'; -import {RuntimeNodeInstrumentationConfig} from '../types'; -import {NODE_JS_VERSION_ATTRIBUTE} from "../consts/attributes"; +import { MetricCollector } from '../types/metricCollector'; +import { Meter } from '@opentelemetry/api'; +import { clearInterval } from 'node:timers'; +import { RuntimeNodeInstrumentationConfig } from '../types'; +import { NODE_JS_VERSION_ATTRIBUTE } from '../consts/attributes'; -type VersionAttribute = { [NODE_JS_VERSION_ATTRIBUTE]: string } +type VersionAttribute = { [NODE_JS_VERSION_ATTRIBUTE]: string }; export abstract class BaseCollector implements MetricCollector { protected _config: RuntimeNodeInstrumentationConfig = {}; @@ -27,7 +27,7 @@ export abstract class BaseCollector implements MetricCollector { protected namePrefix: string; private _interval: NodeJS.Timeout | undefined; protected _scrapeQueue: T[] = []; - protected versionAttribute: VersionAttribute + protected versionAttribute: VersionAttribute; protected constructor( config: RuntimeNodeInstrumentationConfig = {}, @@ -35,7 +35,7 @@ export abstract class BaseCollector implements MetricCollector { ) { this._config = config; this.namePrefix = namePrefix; - this.versionAttribute = {[NODE_JS_VERSION_ATTRIBUTE]: process.version} + this.versionAttribute = { [NODE_JS_VERSION_ATTRIBUTE]: process.version }; } public disable(): void { diff --git a/plugins/node/instrumentation-runtime-node/src/metrics/eventLoopDelayCollector.ts b/plugins/node/instrumentation-runtime-node/src/metrics/eventLoopDelayCollector.ts index 8922e50d4d..2bed451922 100644 --- a/plugins/node/instrumentation-runtime-node/src/metrics/eventLoopDelayCollector.ts +++ b/plugins/node/instrumentation-runtime-node/src/metrics/eventLoopDelayCollector.ts @@ -15,9 +15,9 @@ */ import {RuntimeNodeInstrumentationConfig} from '../types'; import {Meter} from '@opentelemetry/api'; +import * as perf_hooks from 'node:perf_hooks'; import {IntervalHistogram} from 'node:perf_hooks'; import {BaseCollector} from './baseCollector'; -import * as perf_hooks from 'node:perf_hooks'; enum NodeJsEventLoopDelay { delay = 'eventloop.delay', @@ -27,48 +27,37 @@ enum NodeJsEventLoopDelay { stddev = 'eventloop.delay.stddev', p50 = 'eventloop.delay.p50', p90 = 'eventloop.delay.p90', - p99 = 'eventloop.delay.p99' + p99 = 'eventloop.delay.p99', } -export const metricNames: Record = { +export const metricNames: Record< + NodeJsEventLoopDelay, + { description: string } +> = { [NodeJsEventLoopDelay.delay]: { - description: - 'Lag of event loop in seconds.' - }, + description: 'Lag of event loop in seconds.', + }, [NodeJsEventLoopDelay.min]: { - description: - 'The minimum recorded event loop delay.', - }, + description: 'The minimum recorded event loop delay.', + }, [NodeJsEventLoopDelay.max]: { - description: - 'The maximum recorded event loop delay.', - } - , + description: 'The maximum recorded event loop delay.', + }, [NodeJsEventLoopDelay.mean]: { - description: - 'The mean of the recorded event loop delays.', - } - , + description: 'The mean of the recorded event loop delays.', + }, [NodeJsEventLoopDelay.stddev]: { - description: - 'The standard deviation of the recorded event loop delays.', - } - , + description: 'The standard deviation of the recorded event loop delays.', + }, [NodeJsEventLoopDelay.p50]: { - description: - 'The 50th percentile of the recorded event loop delays.', - } - , + description: 'The 50th percentile of the recorded event loop delays.', + }, [NodeJsEventLoopDelay.p90]: { - description: - 'The 90th percentile of the recorded event loop delays.', - } - , + description: 'The 90th percentile of the recorded event loop delays.', + }, [NodeJsEventLoopDelay.p99]: { - description: - 'The 99th percentile of the recorded event loop delays.', - } - , + description: 'The 99th percentile of the recorded event loop delays.', + }, }; export interface EventLoopLagInformation { @@ -84,7 +73,6 @@ export interface EventLoopLagInformation { export class EventLoopDelayCollector extends BaseCollector { private _histogram: IntervalHistogram; - constructor( config: RuntimeNodeInstrumentationConfig = {}, namePrefix: string @@ -160,25 +148,38 @@ export class EventLoopDelayCollector extends BaseCollector(res => { setImmediate((start: [number, number]) => { res(this._reportEventloopLag(start)); - }, start); + }, startHrTime); }); observableResult.observe(delay, delayResult, this.versionAttribute); observableResult.observe(delayMin, data.min, this.versionAttribute); observableResult.observe(delayMax, data.max, this.versionAttribute); observableResult.observe(delayMean, data.mean, this.versionAttribute); - observableResult.observe(delayStddev, data.stddev, this.versionAttribute); + observableResult.observe( + delayStddev, + data.stddev, + this.versionAttribute + ); observableResult.observe(delayp50, data.p50, this.versionAttribute); observableResult.observe(delayp90, data.p90, this.versionAttribute); observableResult.observe(delayp99, data.p99, this.versionAttribute); this._histogram.reset(); }, - [delay, delayMin, delayMax, delayMean, delayStddev, delayp50, delayp90, delayp99] + [ + delay, + delayMin, + delayMax, + delayMean, + delayStddev, + delayp50, + delayp90, + delayp99, + ] ); } @@ -205,8 +206,7 @@ export class EventLoopDelayCollector extends BaseCollector { // Node < 16 uses entry.kind // Node >= 16 uses entry.detail.kind // See: https://nodejs.org/docs/latest-v16.x/api/deprecations.html#deprecations_dep0152_extension_performanceentry_properties + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const kind = entry.detail ? kinds[entry.detail.kind] : kinds[entry.kind]; this._gcDurationByKindHistogram?.record( entry.duration / 1000, - Object.assign({ [`${this.namePrefix}.gc.type`]: kind }, this.versionAttribute) + Object.assign( + { [`${this.namePrefix}.gc.type`]: kind }, + this.versionAttribute + ) ); }); } @@ -68,7 +72,7 @@ export class GCCollector extends BaseCollector { } internalEnable(): void { - this._observer.observe({entryTypes: ['gc']}); + this._observer.observe({ entryTypes: ['gc'] }); } internalDisable(): void { diff --git a/plugins/node/instrumentation-runtime-node/src/metrics/heapSizeAndUsedCollector.ts b/plugins/node/instrumentation-runtime-node/src/metrics/heapSizeAndUsedCollector.ts index 92b4bfb2d7..f17e0acb18 100644 --- a/plugins/node/instrumentation-runtime-node/src/metrics/heapSizeAndUsedCollector.ts +++ b/plugins/node/instrumentation-runtime-node/src/metrics/heapSizeAndUsedCollector.ts @@ -16,9 +16,11 @@ import { RuntimeNodeInstrumentationConfig } from '../types'; import { Meter } from '@opentelemetry/api'; import { BaseCollector } from './baseCollector'; -import {HeapSizes} from "../types/heapSizes"; -import {V8_HEAP_SIZE, V8_HEAP_SIZE_STATE_ATTRIBUTE} from "../consts/attributes"; - +import { HeapSizes } from '../types/heapSizes'; +import { + V8_HEAP_SIZE, + V8_HEAP_SIZE_STATE_ATTRIBUTE, +} from '../consts/attributes'; export class HeapSizeAndUsedCollector extends BaseCollector { constructor( @@ -29,26 +31,27 @@ export class HeapSizeAndUsedCollector extends BaseCollector } updateMetricInstruments(meter: Meter): void { - meter.createObservableGauge( - `${this.namePrefix}.${V8_HEAP_SIZE}`, - { - description: "Process heap size from Node.js in bytes.", + meter + .createObservableGauge(`${this.namePrefix}.${V8_HEAP_SIZE}`, { + description: 'Process heap size from Node.js in bytes.', unit: 'By', - } - ).addCallback(async observableResult => { - if (this._scrapeQueue.length === 0) return; + }) + .addCallback(async observableResult => { + if (this._scrapeQueue.length === 0) return; - const data = this._scrapeQueue.shift(); - if (data === undefined) return; - observableResult.observe(data.heapTotal, { - [`${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`]: HeapSizes.Total, - ...this.versionAttribute - }); - observableResult.observe(data.heapUsed, { - [`${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`]: HeapSizes.Used, - ...this.versionAttribute + const data = this._scrapeQueue.shift(); + if (data === undefined) return; + observableResult.observe(data.heapTotal, { + [`${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`]: + HeapSizes.Total, + ...this.versionAttribute, + }); + observableResult.observe(data.heapUsed, { + [`${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`]: + HeapSizes.Used, + ...this.versionAttribute, + }); }); - }); } internalEnable(): void {} diff --git a/plugins/node/instrumentation-runtime-node/src/metrics/heapSpacesSizeAndUsedCollector.ts b/plugins/node/instrumentation-runtime-node/src/metrics/heapSpacesSizeAndUsedCollector.ts index 779dabec41..2f51cf3e23 100644 --- a/plugins/node/instrumentation-runtime-node/src/metrics/heapSpacesSizeAndUsedCollector.ts +++ b/plugins/node/instrumentation-runtime-node/src/metrics/heapSpacesSizeAndUsedCollector.ts @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {RuntimeNodeInstrumentationConfig} from '../types'; -import {Meter} from '@opentelemetry/api'; -import {BaseCollector} from './baseCollector'; +import { RuntimeNodeInstrumentationConfig } from '../types'; +import { Meter } from '@opentelemetry/api'; +import { BaseCollector } from './baseCollector'; import * as v8 from 'node:v8'; -import {HeapSpaceInfo} from 'v8'; -import {V8_HEAP_SIZE_STATE_ATTRIBUTE} from "../consts/attributes"; - +import { HeapSpaceInfo } from 'v8'; +import { V8_HEAP_SIZE_STATE_ATTRIBUTE } from '../consts/attributes'; export enum V8HeapSpaceMetrics { spaceSize = 'heap.space_size', @@ -28,26 +27,21 @@ export enum V8HeapSpaceMetrics { physical = 'heap.physical_space_size', } - - -export const metricNames: Record = { - [V8HeapSpaceMetrics.spaceSize]: { - description: - 'Process heap space size total from Node.js in bytes.', - }, - [V8HeapSpaceMetrics.used]: { - description: - 'Process heap space size used from Node.js in bytes.', - }, - [V8HeapSpaceMetrics.available]: { - description: - 'Process heap space size available from Node.js in bytes.', - }, - [V8HeapSpaceMetrics.physical]: { - description: - 'Process heap space size available from Node.js in bytes.', - }, -} +export const metricNames: Record = + { + [V8HeapSpaceMetrics.spaceSize]: { + description: 'Process heap space size total from Node.js in bytes.', + }, + [V8HeapSpaceMetrics.used]: { + description: 'Process heap space size used from Node.js in bytes.', + }, + [V8HeapSpaceMetrics.available]: { + description: 'Process heap space size available from Node.js in bytes.', + }, + [V8HeapSpaceMetrics.physical]: { + description: 'Process heap space size available from Node.js in bytes.', + }, + }; export class HeapSpacesSizeAndUsedCollector extends BaseCollector< HeapSpaceInfo[] @@ -88,7 +82,7 @@ export class HeapSpacesSizeAndUsedCollector extends BaseCollector< unit: 'bytes', } ); - const heapSpaceNameAttributeName = `${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}` + const heapSpaceNameAttributeName = `${this.namePrefix}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`; meter.addBatchObservableCallback( observableResult => { @@ -97,8 +91,7 @@ export class HeapSpacesSizeAndUsedCollector extends BaseCollector< const data = this._scrapeQueue.shift(); if (data === undefined) return; for (const space of data) { - - const spaceName = space.space_name + const spaceName = space.space_name; observableResult.observe(heapSpaceSize, space.space_size, { [heapSpaceNameAttributeName]: spaceName, @@ -116,20 +109,22 @@ export class HeapSpacesSizeAndUsedCollector extends BaseCollector< } ); - observableResult.observe(heapSpacePhysical, space.physical_space_size, { - [heapSpaceNameAttributeName]: spaceName, - }); + observableResult.observe( + heapSpacePhysical, + space.physical_space_size, + { + [heapSpaceNameAttributeName]: spaceName, + } + ); } }, [heapSpaceSize, heapSpaceUsed, heapSpaceAvailable, heapSpacePhysical] ); } - internalEnable(): void { - } + internalEnable(): void {} - internalDisable(): void { - } + internalDisable(): void {} protected scrape(): HeapSpaceInfo[] { return v8.getHeapSpaceStatistics(); diff --git a/plugins/node/instrumentation-runtime-node/src/types/ConventionalNamePrefix.ts b/plugins/node/instrumentation-runtime-node/src/types/ConventionalNamePrefix.ts index e11eea72e8..f90ac9de1c 100644 --- a/plugins/node/instrumentation-runtime-node/src/types/ConventionalNamePrefix.ts +++ b/plugins/node/instrumentation-runtime-node/src/types/ConventionalNamePrefix.ts @@ -1,4 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ export enum ConventionalNamePrefix { - NodeJsRuntime = "nodejsruntime", - V8EnjineRuntime = "v8jsengineruntime", + NodeJsRuntime = 'nodejsruntime', + V8EnjineRuntime = 'v8jsengineruntime', } diff --git a/plugins/node/instrumentation-runtime-node/src/types/heapSizes.ts b/plugins/node/instrumentation-runtime-node/src/types/heapSizes.ts index 36fccdf1d9..59cd766294 100644 --- a/plugins/node/instrumentation-runtime-node/src/types/heapSizes.ts +++ b/plugins/node/instrumentation-runtime-node/src/types/heapSizes.ts @@ -1,4 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ export enum HeapSizes { - Total = "total", - Used = "used", + Total = 'total', + Used = 'used', } diff --git a/plugins/node/instrumentation-runtime-node/src/types/heapSpaces.ts b/plugins/node/instrumentation-runtime-node/src/types/heapSpaces.ts index af9f843607..41e1d606c1 100644 --- a/plugins/node/instrumentation-runtime-node/src/types/heapSpaces.ts +++ b/plugins/node/instrumentation-runtime-node/src/types/heapSpaces.ts @@ -1,5 +1,20 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ export enum HeapSpaces { - Total = "total", - Used = "used", - Availabe = "available" + Total = 'total', + Used = 'used', + Availabe = 'available', } diff --git a/plugins/node/instrumentation-runtime-node/test/event_loop_delay.test.ts b/plugins/node/instrumentation-runtime-node/test/event_loop_delay.test.ts index 1a9acf85a2..b70cab872d 100644 --- a/plugins/node/instrumentation-runtime-node/test/event_loop_delay.test.ts +++ b/plugins/node/instrumentation-runtime-node/test/event_loop_delay.test.ts @@ -19,8 +19,8 @@ import { RuntimeNodeInstrumentation } from '../src'; import * as assert from 'assert'; import { TestMetricReader } from './testMetricsReader'; import { metricNames } from '../src/metrics/eventLoopDelayCollector'; -import {ConventionalNamePrefix} from "../src/types/ConventionalNamePrefix"; -import {NODE_JS_VERSION_ATTRIBUTE} from "../src/consts/attributes"; +import { ConventionalNamePrefix } from '../src/types/ConventionalNamePrefix'; +import { NODE_JS_VERSION_ATTRIBUTE } from '../src/consts/attributes'; const MEASUREMENT_INTERVAL = 10; @@ -56,10 +56,16 @@ describe(`${ConventionalNamePrefix.NodeJsRuntime}.eventloop`, function () { ); const scopeMetrics = resourceMetrics.scopeMetrics; const metric = scopeMetrics[0].metrics.find( - x => x.descriptor.name === `${ConventionalNamePrefix.NodeJsRuntime}.${ metricName}` + x => + x.descriptor.name === + `${ConventionalNamePrefix.NodeJsRuntime}.${metricName}` ); - assert.notEqual(metric, undefined, `${ConventionalNamePrefix.NodeJsRuntime}.${metricName} not found`); + assert.notEqual( + metric, + undefined, + `${ConventionalNamePrefix.NodeJsRuntime}.${metricName} not found` + ); assert.strictEqual( metric!.dataPointType, @@ -69,7 +75,7 @@ describe(`${ConventionalNamePrefix.NodeJsRuntime}.eventloop`, function () { assert.strictEqual( metric!.descriptor.name, - `${ConventionalNamePrefix.NodeJsRuntime}.${ metricName}`, + `${ConventionalNamePrefix.NodeJsRuntime}.${metricName}`, 'descriptor.name' ); }); @@ -95,7 +101,9 @@ describe(`${ConventionalNamePrefix.NodeJsRuntime}.eventloop`, function () { ); const scopeMetrics = resourceMetrics.scopeMetrics; const metric = scopeMetrics[0].metrics.find( - x => x.descriptor.name === `${ConventionalNamePrefix.NodeJsRuntime}.${ metricName}` + x => + x.descriptor.name === + `${ConventionalNamePrefix.NodeJsRuntime}.${metricName}` ); assert.strictEqual( diff --git a/plugins/node/instrumentation-runtime-node/test/event_loop_utilization.test.ts b/plugins/node/instrumentation-runtime-node/test/event_loop_utilization.test.ts index 6274f2c097..c90c8ebd5f 100644 --- a/plugins/node/instrumentation-runtime-node/test/event_loop_utilization.test.ts +++ b/plugins/node/instrumentation-runtime-node/test/event_loop_utilization.test.ts @@ -18,9 +18,9 @@ import { MeterProvider, DataPointType } from '@opentelemetry/sdk-metrics'; import { RuntimeNodeInstrumentation } from '../src'; import * as assert from 'assert'; import { TestMetricReader } from './testMetricsReader'; -import {ConventionalNamePrefix} from "../src/types/ConventionalNamePrefix"; -import {NODEJS_EVENT_LOOP_UTILIZATION} from "../src/metrics/eventLoopUtilizationCollector"; -import {NODE_JS_VERSION_ATTRIBUTE} from "../src/consts/attributes"; +import { ConventionalNamePrefix } from '../src/types/ConventionalNamePrefix'; +import { NODEJS_EVENT_LOOP_UTILIZATION } from '../src/metrics/eventLoopUtilizationCollector'; +import { NODE_JS_VERSION_ATTRIBUTE } from '../src/consts/attributes'; const MEASUREMENT_INTERVAL = 10; @@ -71,7 +71,9 @@ describe(`${ConventionalNamePrefix.NodeJsRuntime}.${NODEJS_EVENT_LOOP_UTILIZATIO ); const scopeMetrics = resourceMetrics.scopeMetrics; const utilizationMetric = scopeMetrics[0].metrics.find( - x => x.descriptor.name === `${ConventionalNamePrefix.NodeJsRuntime}.${NODEJS_EVENT_LOOP_UTILIZATION}` + x => + x.descriptor.name === + `${ConventionalNamePrefix.NodeJsRuntime}.${NODEJS_EVENT_LOOP_UTILIZATION}` ); assert.notEqual(utilizationMetric, undefined, 'metric not found'); @@ -118,9 +120,7 @@ describe(`${ConventionalNamePrefix.NodeJsRuntime}.${NODEJS_EVENT_LOOP_UTILIZATIO instrumentation.setMeterProvider(meterProvider); // act - await new Promise(resolve => - setTimeout(resolve, MEASUREMENT_INTERVAL * 5) - ); + await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 5)); const { resourceMetrics, errors } = await metricReader.collect(); // assert @@ -131,7 +131,9 @@ describe(`${ConventionalNamePrefix.NodeJsRuntime}.${NODEJS_EVENT_LOOP_UTILIZATIO ); const scopeMetrics = resourceMetrics.scopeMetrics; const metric = scopeMetrics[0].metrics.find( - x => x.descriptor.name === `${ConventionalNamePrefix.NodeJsRuntime}.${NODEJS_EVENT_LOOP_UTILIZATION}` + x => + x.descriptor.name === + `${ConventionalNamePrefix.NodeJsRuntime}.${NODEJS_EVENT_LOOP_UTILIZATION}` ); assert.strictEqual( diff --git a/plugins/node/instrumentation-runtime-node/test/heap_size_and_used.test.ts b/plugins/node/instrumentation-runtime-node/test/heap_size_and_used.test.ts index 50f80b2784..d03602fc4c 100644 --- a/plugins/node/instrumentation-runtime-node/test/heap_size_and_used.test.ts +++ b/plugins/node/instrumentation-runtime-node/test/heap_size_and_used.test.ts @@ -13,14 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {MeterProvider, DataPointType} from '@opentelemetry/sdk-metrics'; +import { MeterProvider, DataPointType } from '@opentelemetry/sdk-metrics'; -import {RuntimeNodeInstrumentation} from '../src'; +import { RuntimeNodeInstrumentation } from '../src'; import * as assert from 'assert'; -import {TestMetricReader} from './testMetricsReader'; -import {ConventionalNamePrefix} from "../src/types/ConventionalNamePrefix"; -import {NODE_JS_VERSION_ATTRIBUTE, V8_HEAP_SIZE, V8_HEAP_SIZE_STATE_ATTRIBUTE} from "../src/consts/attributes"; -import {HeapSizes} from "../src/types/heapSizes"; +import { TestMetricReader } from './testMetricsReader'; +import { ConventionalNamePrefix } from '../src/types/ConventionalNamePrefix'; +import { + NODE_JS_VERSION_ATTRIBUTE, + V8_HEAP_SIZE, + V8_HEAP_SIZE_STATE_ATTRIBUTE, +} from '../src/consts/attributes'; +import { HeapSizes } from '../src/types/heapSizes'; const MEASUREMENT_INTERVAL = 10; @@ -42,10 +46,8 @@ describe(`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}`, function ( instrumentation.setMeterProvider(meterProvider); // act - await new Promise(resolve => - setTimeout(resolve, MEASUREMENT_INTERVAL * 5) - ); - const {resourceMetrics, errors} = await metricReader.collect(); + await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 5)); + const { resourceMetrics, errors } = await metricReader.collect(); // assert assert.deepEqual( @@ -55,10 +57,16 @@ describe(`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}`, function ( ); const scopeMetrics = resourceMetrics.scopeMetrics; const metric = scopeMetrics[0].metrics.find( - x => x.descriptor.name === `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}` + x => + x.descriptor.name === + `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}` ); - assert.notEqual(metric, undefined, `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE} not found`); + assert.notEqual( + metric, + undefined, + `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE} not found` + ); assert.strictEqual( metric!.dataPointType, @@ -81,9 +89,7 @@ describe(`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}`, function ( instrumentation.setMeterProvider(meterProvider); // act - await new Promise(resolve => - setTimeout(resolve, MEASUREMENT_INTERVAL * 5) - ); + await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 5)); const { resourceMetrics, errors } = await metricReader.collect(); // assert @@ -94,7 +100,9 @@ describe(`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}`, function ( ); const scopeMetrics = resourceMetrics.scopeMetrics; const metric = scopeMetrics[0].metrics.find( - x => x.descriptor.name === `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}` + x => + x.descriptor.name === + `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}` ); assert.strictEqual( @@ -112,9 +120,7 @@ describe(`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}`, function ( instrumentation.setMeterProvider(meterProvider); // act - await new Promise(resolve => - setTimeout(resolve, MEASUREMENT_INTERVAL * 5) - ); + await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 5)); const { resourceMetrics, errors } = await metricReader.collect(); // assert @@ -125,11 +131,15 @@ describe(`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}`, function ( ); const scopeMetrics = resourceMetrics.scopeMetrics; const metric = scopeMetrics[0].metrics.find( - x => x.descriptor.name === `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}` + x => + x.descriptor.name === + `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}` ); assert.strictEqual( - metric!.dataPoints[0].attributes[`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`], + metric!.dataPoints[0].attributes[ + `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}` + ], HeapSizes.Total, `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE_STATE_ATTRIBUTE} attribute ${NODE_JS_VERSION_ATTRIBUTE} not found` ); @@ -143,9 +153,7 @@ describe(`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}`, function ( instrumentation.setMeterProvider(meterProvider); // act - await new Promise(resolve => - setTimeout(resolve, MEASUREMENT_INTERVAL * 5) - ); + await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 5)); const { resourceMetrics, errors } = await metricReader.collect(); // assert @@ -156,11 +164,15 @@ describe(`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}`, function ( ); const scopeMetrics = resourceMetrics.scopeMetrics; const metric = scopeMetrics[0].metrics.find( - x => x.descriptor.name === `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}` + x => + x.descriptor.name === + `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE}` ); assert.strictEqual( - metric!.dataPoints[1].attributes[`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`], + metric!.dataPoints[1].attributes[ + `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}` + ], HeapSizes.Used, `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE_STATE_ATTRIBUTE} attribute not found` ); diff --git a/plugins/node/instrumentation-runtime-node/test/heap_space_and_used.test.ts b/plugins/node/instrumentation-runtime-node/test/heap_space_and_used.test.ts index b8199faa53..71bc89046b 100644 --- a/plugins/node/instrumentation-runtime-node/test/heap_space_and_used.test.ts +++ b/plugins/node/instrumentation-runtime-node/test/heap_space_and_used.test.ts @@ -19,8 +19,8 @@ import { RuntimeNodeInstrumentation } from '../src'; import * as assert from 'assert'; import { TestMetricReader } from './testMetricsReader'; import { metricNames } from '../src/metrics/heapSpacesSizeAndUsedCollector'; -import {ConventionalNamePrefix} from "../src/types/ConventionalNamePrefix"; -import {V8_HEAP_SIZE_STATE_ATTRIBUTE} from "../src/consts/attributes"; +import { ConventionalNamePrefix } from '../src/types/ConventionalNamePrefix'; +import { V8_HEAP_SIZE_STATE_ATTRIBUTE } from '../src/consts/attributes'; const MEASUREMENT_INTERVAL = 10; @@ -56,10 +56,16 @@ describe('nodejs.heap_space', function () { ); const scopeMetrics = resourceMetrics.scopeMetrics; const metric = scopeMetrics[0].metrics.find( - x => x.descriptor.name === `${ConventionalNamePrefix.V8EnjineRuntime}.${metricName}` + x => + x.descriptor.name === + `${ConventionalNamePrefix.V8EnjineRuntime}.${metricName}` ); - assert.notEqual(metric, undefined, `${ConventionalNamePrefix.V8EnjineRuntime}.${metricName} not found`); + assert.notEqual( + metric, + undefined, + `${ConventionalNamePrefix.V8EnjineRuntime}.${metricName} not found` + ); assert.strictEqual( metric!.dataPointType, @@ -74,15 +80,20 @@ describe('nodejs.heap_space', function () { ); }); - for (const space of ["new_space", "old_space", "code_space", "large_object_space"]) { + for (const space of [ + 'new_space', + 'old_space', + 'code_space', + 'large_object_space', + ]) { it(`should write ${ConventionalNamePrefix.V8EnjineRuntime}.${metricName} ${space} attribute`, async function () { // arrange const instrumentation = new RuntimeNodeInstrumentation({ monitoringPrecision: MEASUREMENT_INTERVAL, }); instrumentation.setMeterProvider(meterProvider); - const map = [...Array(10).keys()].map(x => x + 10) - map.indexOf(1) + const map = [...Array(10).keys()].map(x => x + 10); + map.indexOf(1); // act await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 5) @@ -97,11 +108,22 @@ describe('nodejs.heap_space', function () { ); const scopeMetrics = resourceMetrics.scopeMetrics; const metric = scopeMetrics[0].metrics.find( - x => x.descriptor.name === `${ConventionalNamePrefix.V8EnjineRuntime}.${metricName}` + x => + x.descriptor.name === + `${ConventionalNamePrefix.V8EnjineRuntime}.${metricName}` + ); + const spaceAttribute = metric!.dataPoints.find( + x => + x.attributes[ + `${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}` + ] === space ); - const spaceAttribute = metric!.dataPoints.find(x => x.attributes[`${ConventionalNamePrefix.V8EnjineRuntime}.${V8_HEAP_SIZE_STATE_ATTRIBUTE}`] === space) - assert.notEqual(spaceAttribute, undefined, `${ConventionalNamePrefix.V8EnjineRuntime}.${metricName} space: ${space} not found`); + assert.notEqual( + spaceAttribute, + undefined, + `${ConventionalNamePrefix.V8EnjineRuntime}.${metricName} space: ${space} not found` + ); }); } }