Skip to content

Commit 35ae192

Browse files
authored
Merge branch 'master' into fix/scope-signed-url-token
2 parents e935088 + d2e814b commit 35ae192

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

src/internal/monitoring/otel-metrics.test.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,112 @@ describe('otel metrics', () => {
173173
)
174174
})
175175

176+
test('registers a view overriding v8js.gc.duration buckets on the runtime-node meter', async () => {
177+
delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT
178+
delete process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
179+
180+
const registerInstrumentations = vi.fn(() => vi.fn())
181+
const HostMetrics = vi.fn(function () {
182+
return {
183+
start: vi.fn(),
184+
}
185+
})
186+
const MeterProvider = vi.fn(function () {
187+
return {
188+
shutdown: vi.fn().mockResolvedValue(undefined),
189+
getMeter: vi.fn(() => ({})),
190+
}
191+
})
192+
const PrometheusExporter = vi.fn(function () {
193+
return {
194+
getMetricsRequestHandler: vi.fn(),
195+
}
196+
})
197+
const RuntimeNodeInstrumentation = vi.fn(function () {
198+
return {}
199+
})
200+
const StorageNodeInstrumentation = vi.fn(function () {
201+
return {}
202+
})
203+
204+
vi.doMock('../../config', () => ({
205+
getConfig: vi.fn(() => ({
206+
version: 'test-version',
207+
otelMetricsExportIntervalMs: 1000,
208+
otelMetricsEnabled: true,
209+
otelMetricsTemporality: 'CUMULATIVE',
210+
prometheusMetricsEnabled: false,
211+
region: 'local',
212+
})),
213+
}))
214+
vi.doMock('@internal/monitoring/logger', () => ({
215+
logger: { info: vi.fn() },
216+
logSchema: { error: vi.fn(), info: vi.fn() },
217+
}))
218+
vi.doMock('@internal/monitoring/system', () => ({
219+
StorageNodeInstrumentation,
220+
}))
221+
vi.doMock('@opentelemetry/api', () => ({
222+
metrics: {
223+
setGlobalMeterProvider: vi.fn(),
224+
},
225+
}))
226+
vi.doMock('@opentelemetry/exporter-metrics-otlp-grpc', () => ({
227+
OTLPMetricExporter: vi.fn(function () {
228+
return {}
229+
}),
230+
}))
231+
vi.doMock('@opentelemetry/exporter-prometheus', () => ({
232+
PrometheusExporter,
233+
}))
234+
vi.doMock('@opentelemetry/host-metrics', () => ({
235+
HostMetrics,
236+
}))
237+
vi.doMock('@opentelemetry/instrumentation', () => ({
238+
registerInstrumentations,
239+
}))
240+
vi.doMock('@opentelemetry/instrumentation-runtime-node', () => ({
241+
RuntimeNodeInstrumentation,
242+
}))
243+
vi.doMock('@opentelemetry/resources', () => ({
244+
resourceFromAttributes: vi.fn(() => ({})),
245+
}))
246+
vi.doMock('@opentelemetry/sdk-metrics', () => ({
247+
AggregationTemporality: {
248+
CUMULATIVE: 'CUMULATIVE',
249+
DELTA: 'DELTA',
250+
},
251+
AggregationType: {
252+
DROP: 'DROP',
253+
EXPLICIT_BUCKET_HISTOGRAM: 'EXPLICIT_BUCKET_HISTOGRAM',
254+
},
255+
MeterProvider,
256+
PeriodicExportingMetricReader: vi.fn(),
257+
}))
258+
259+
await importOtelMetricsModule()
260+
261+
expect(MeterProvider).toHaveBeenCalledWith(
262+
expect.objectContaining({
263+
views: expect.arrayContaining([
264+
{
265+
meterName: '@opentelemetry/instrumentation-runtime-node',
266+
instrumentName: 'v8js.gc.duration',
267+
aggregation: {
268+
type: 'EXPLICIT_BUCKET_HISTOGRAM',
269+
options: {
270+
boundaries: [
271+
0.0001, 0.00025, 0.0005, 0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5,
272+
1, 2.5, 5, 10, 30,
273+
],
274+
},
275+
},
276+
},
277+
]),
278+
})
279+
)
280+
})
281+
176282
test('does not create a Prometheus reader when Prometheus metrics are disabled', async () => {
177283
delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT
178284
delete process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT

0 commit comments

Comments
 (0)