Skip to content

Commit 6a84254

Browse files
committed
chore(instrumentation-runtime-node): remove scrape interval, remove unused variables
1 parent fdfea51 commit 6a84254

File tree

12 files changed

+79
-369
lines changed

12 files changed

+79
-369
lines changed

plugins/node/instrumentation-runtime-node/src/consts/attributes.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
export const NODE_JS_VERSION_ATTRIBUTE = 'nodejsruntime.version';
1716
export const V8_HEAP_SIZE_NAME_ATTRIBUTE = 'heap.space.name';
18-
export const V8_HEAP_SIZE = 'heap.size';

plugins/node/instrumentation-runtime-node/src/instrumentation.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { MetricCollector } from './types/metricCollector';
2121
import { EventLoopUtilizationCollector } from './metrics/eventLoopUtilizationCollector';
2222
import { EventLoopDelayCollector } from './metrics/eventLoopDelayCollector';
2323
import { GCCollector } from './metrics/gcCollector';
24-
import { HeapSizeAndUsedCollector } from './metrics/heapSizeAndUsedCollector';
2524
import { HeapSpacesSizeAndUsedCollector } from './metrics/heapSpacesSizeAndUsedCollector';
2625
import { ConventionalNamePrefix } from './types/ConventionalNamePrefix';
2726

@@ -48,10 +47,6 @@ export class RuntimeNodeInstrumentation extends InstrumentationBase {
4847
ConventionalNamePrefix.NodeJs
4948
),
5049
new GCCollector(this._config, ConventionalNamePrefix.V8js),
51-
new HeapSizeAndUsedCollector(
52-
this._config,
53-
ConventionalNamePrefix.V8js
54-
),
5550
new HeapSpacesSizeAndUsedCollector(
5651
this._config,
5752
ConventionalNamePrefix.V8js

plugins/node/instrumentation-runtime-node/src/metrics/baseCollector.ts

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
*/
1616
import { MetricCollector } from '../types/metricCollector';
1717
import { Meter } from '@opentelemetry/api';
18-
import { clearInterval } from 'node:timers';
1918
import { RuntimeNodeInstrumentationConfig } from '../types';
2019

2120

22-
export abstract class BaseCollector<T> implements MetricCollector {
21+
export abstract class BaseCollector implements MetricCollector {
2322
protected _config: RuntimeNodeInstrumentationConfig = {};
2423

2524
protected namePrefix: string;
26-
private _interval: NodeJS.Timeout | undefined;
27-
protected _scrapeQueue: T[] = [];
2825

2926
protected constructor(
3027
config: RuntimeNodeInstrumentationConfig = {},
@@ -35,43 +32,19 @@ export abstract class BaseCollector<T> implements MetricCollector {
3532
}
3633

3734
public disable(): void {
38-
this._clearQueue();
39-
clearInterval(this._interval);
40-
this._interval = undefined;
41-
35+
this._config.enabled = false;
4236
this.internalDisable();
4337
}
4438

4539
public enable(): void {
46-
this._clearQueue();
47-
clearInterval(this._interval);
48-
this._interval = setInterval(
49-
() => this._addTask(),
50-
this._config.monitoringPrecision
51-
);
52-
53-
// unref so that it does not keep the process running if disable() is never called
54-
this._interval?.unref();
55-
40+
this._config.enabled = true;
5641
this.internalEnable();
5742
}
5843

59-
private _clearQueue() {
60-
this._scrapeQueue.length = 0;
61-
}
62-
63-
private _addTask() {
64-
const taskResult = this.scrape();
65-
if (taskResult) {
66-
this._scrapeQueue.push(taskResult);
67-
}
68-
}
6944

7045
public abstract updateMetricInstruments(meter: Meter): void;
7146

7247
protected abstract internalEnable(): void;
7348

7449
protected abstract internalDisable(): void;
75-
76-
protected abstract scrape(): T;
7750
}

plugins/node/instrumentation-runtime-node/src/metrics/eventLoopDelayCollector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export interface EventLoopLagInformation {
6666
p99: number;
6767
}
6868

69-
export class EventLoopDelayCollector extends BaseCollector<EventLoopLagInformation> {
69+
export class EventLoopDelayCollector extends BaseCollector {
7070
private _histogram: IntervalHistogram;
7171

7272
constructor(
@@ -132,9 +132,9 @@ export class EventLoopDelayCollector extends BaseCollector<EventLoopLagInformati
132132

133133
meter.addBatchObservableCallback(
134134
async observableResult => {
135-
if (this._scrapeQueue.length === 0) return;
135+
if(!this._config.enabled) return
136136

137-
const data = this._scrapeQueue.shift();
137+
const data = this.scrape();
138138
if (data === undefined) return;
139139

140140
observableResult.observe(delayMin, data.min);

plugins/node/instrumentation-runtime-node/src/metrics/eventLoopUtilizationCollector.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const { eventLoopUtilization: eventLoopUtilizationCollector } = performance;
2222

2323
export const NODEJS_EVENT_LOOP_UTILIZATION = 'eventloop.utilization';
2424

25-
export class EventLoopUtilizationCollector extends BaseCollector<EventLoopUtilization> {
25+
export class EventLoopUtilizationCollector extends BaseCollector {
2626
constructor(
2727
config: RuntimeNodeInstrumentationConfig = {},
2828
namePrefix: string
@@ -40,15 +40,16 @@ export class EventLoopUtilizationCollector extends BaseCollector<EventLoopUtiliz
4040
}
4141
)
4242
.addCallback(async observableResult => {
43-
if (this._scrapeQueue.length === 0) {
44-
return;
45-
}
46-
const elu = eventLoopUtilizationCollector(this._scrapeQueue.shift());
43+
if(!this._config.enabled) return
44+
45+
const elu = eventLoopUtilizationCollector(this.scrape());
4746
observableResult.observe(elu.utilization);
4847
});
4948
}
5049

51-
protected internalDisable(): void {}
50+
protected internalDisable(): void {
51+
52+
}
5253

5354
protected internalEnable(): void {}
5455

plugins/node/instrumentation-runtime-node/src/metrics/gcCollector.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = 'minor';
2929
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental';
3030
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB] = 'weakcb';
3131

32-
export class GCCollector extends BaseCollector<null> {
32+
export class GCCollector extends BaseCollector {
3333
private _gcDurationByKindHistogram?: Histogram;
3434
private _observer: PerformanceObserver;
3535

@@ -39,6 +39,8 @@ export class GCCollector extends BaseCollector<null> {
3939
) {
4040
super(config, namePrefix);
4141
this._observer = new perf_hooks.PerformanceObserver(list => {
42+
if(!this._config.enabled) return
43+
4244
const entry = list.getEntries()[0];
4345
// Node < 16 uses entry.kind
4446
// Node >= 16 uses entry.detail.kind
@@ -77,8 +79,4 @@ export class GCCollector extends BaseCollector<null> {
7779
internalDisable(): void {
7880
this._observer.disconnect();
7981
}
80-
81-
protected scrape(): null {
82-
return null;
83-
}
8482
}

plugins/node/instrumentation-runtime-node/src/metrics/heapSizeAndUsedCollector.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

plugins/node/instrumentation-runtime-node/src/metrics/heapSpacesSizeAndUsedCollector.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ export const metricNames: Record<V8HeapSpaceMetrics, { description: string }> =
4343
},
4444
};
4545

46-
export class HeapSpacesSizeAndUsedCollector extends BaseCollector<
47-
HeapSpaceInfo[]
48-
> {
46+
export class HeapSpacesSizeAndUsedCollector extends BaseCollector {
4947
constructor(
5048
config: RuntimeNodeInstrumentationConfig = {},
5149
namePrefix: string
@@ -86,9 +84,9 @@ export class HeapSpacesSizeAndUsedCollector extends BaseCollector<
8684

8785
meter.addBatchObservableCallback(
8886
observableResult => {
89-
if (this._scrapeQueue.length === 0) return;
87+
if(!this._config.enabled) return
9088

91-
const data = this._scrapeQueue.shift();
89+
const data = this.scrape();
9290
if (data === undefined) return;
9391
for (const space of data) {
9492
const spaceName = space.space_name;

plugins/node/instrumentation-runtime-node/src/types/heapSpaces.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)