-
Notifications
You must be signed in to change notification settings - Fork 651
Expand file tree
/
Copy pathheap_size_limit.test.ts
More file actions
142 lines (122 loc) · 4.33 KB
/
heap_size_limit.test.ts
File metadata and controls
142 lines (122 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* 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.
*/
import * as assert from 'assert';
import { DataPointType, MeterProvider } from '@opentelemetry/sdk-metrics';
import { RuntimeNodeInstrumentation } from '../src';
import { TestMetricReader } from './testMetricsReader';
import { METRIC_V8JS_MEMORY_HEAP_MAX } from '../src/semconv';
const MEASUREMENT_INTERVAL = 10;
describe('v8js.memory.heap.max', function () {
let metricReader: TestMetricReader;
let meterProvider: MeterProvider;
beforeEach(() => {
metricReader = new TestMetricReader();
meterProvider = new MeterProvider({
readers: [metricReader],
});
});
it(`should write ${METRIC_V8JS_MEMORY_HEAP_MAX} after monitoringPrecision`, async function () {
// arrange
const instrumentation = new RuntimeNodeInstrumentation({
monitoringPrecision: MEASUREMENT_INTERVAL,
});
instrumentation.setMeterProvider(meterProvider);
// act
await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 5));
const { resourceMetrics, errors } = await metricReader.collect();
// assert
assert.deepEqual(
errors,
[],
'expected no errors from the callback during collection'
);
const scopeMetrics = resourceMetrics.scopeMetrics;
const metric = scopeMetrics[0].metrics.find(
x => x.descriptor.name === METRIC_V8JS_MEMORY_HEAP_MAX
);
assert.notEqual(
metric,
undefined,
`${METRIC_V8JS_MEMORY_HEAP_MAX} not found`
);
assert.strictEqual(
metric!.dataPointType,
DataPointType.GAUGE,
'expected gauge'
);
assert.strictEqual(
metric!.descriptor.name,
METRIC_V8JS_MEMORY_HEAP_MAX,
'descriptor.name'
);
});
it('should have a positive value representing the heap size limit', async function () {
// arrange
const instrumentation = new RuntimeNodeInstrumentation({
monitoringPrecision: MEASUREMENT_INTERVAL,
});
instrumentation.setMeterProvider(meterProvider);
// act
await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 5));
const { resourceMetrics, errors } = await metricReader.collect();
// assert
assert.deepEqual(errors, []);
const scopeMetrics = resourceMetrics.scopeMetrics;
const metric = scopeMetrics[0].metrics.find(
x => x.descriptor.name === METRIC_V8JS_MEMORY_HEAP_MAX
);
assert.notEqual(
metric,
undefined,
`${METRIC_V8JS_MEMORY_HEAP_MAX} not found`
);
if (metric!.dataPointType === DataPointType.GAUGE) {
assert.strictEqual(
metric!.dataPoints.length,
1,
'expected exactly one data point (global, not per-space)'
);
const value = metric!.dataPoints[0].value as number;
assert.ok(value > 0, `expected positive heap_size_limit, got ${value}`);
}
});
it('should not have v8js.heap.space.name attribute (global metric)', async function () {
// arrange
const instrumentation = new RuntimeNodeInstrumentation({
monitoringPrecision: MEASUREMENT_INTERVAL,
});
instrumentation.setMeterProvider(meterProvider);
// act
await new Promise(resolve => setTimeout(resolve, MEASUREMENT_INTERVAL * 5));
const { resourceMetrics, errors } = await metricReader.collect();
// assert
assert.deepEqual(errors, []);
const scopeMetrics = resourceMetrics.scopeMetrics;
const metric = scopeMetrics[0].metrics.find(
x => x.descriptor.name === METRIC_V8JS_MEMORY_HEAP_MAX
);
assert.notEqual(metric, undefined);
if (metric!.dataPointType === DataPointType.GAUGE) {
for (const dp of metric!.dataPoints) {
assert.strictEqual(
dp.attributes['v8js.heap.space.name'],
undefined,
'v8js.memory.heap.max should not have v8js.heap.space.name attribute'
);
}
}
});
});