-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(prom-client) add tests for check implementation
- Loading branch information
1 parent
ed6596f
commit 046072e
Showing
6 changed files
with
378 additions
and
56 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
plugins/node/instrumentation-runtime-node/test/event_loop_lag.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 { MeterProvider, DataPointType } from '@opentelemetry/sdk-metrics'; | ||
|
||
import { RuntimeNodeInstrumentation } from '../src'; | ||
import * as assert from 'assert'; | ||
import { TestMetricReader } from './testMetricsReader'; | ||
import { metricNames } from '../src/metrics/eventLoopLagCollector'; | ||
|
||
const MEASUREMENT_INTERVAL = 10; | ||
|
||
describe('nodejs.event_loop.lag', function () { | ||
let metricReader: TestMetricReader; | ||
let meterProvider: MeterProvider; | ||
|
||
beforeEach(() => { | ||
metricReader = new TestMetricReader(); | ||
meterProvider = new MeterProvider(); | ||
meterProvider.addMetricReader(metricReader); | ||
}); | ||
|
||
for (const metricName of metricNames) { | ||
it(`should write nodejs.${metricName.name} 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 === 'nodejs.' + metricName.name | ||
); | ||
|
||
assert.notEqual(metric, undefined, `nodejs.${metricName.name} not found`); | ||
|
||
assert.strictEqual( | ||
metric!.dataPointType, | ||
DataPointType.GAUGE, | ||
'expected gauge' | ||
); | ||
|
||
assert.strictEqual( | ||
metric!.descriptor.name, | ||
'nodejs.' + metricName.name, | ||
'descriptor.name' | ||
); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
plugins/node/instrumentation-runtime-node/test/heap_size_and_used.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 { MeterProvider, DataPointType } from '@opentelemetry/sdk-metrics'; | ||
|
||
import { RuntimeNodeInstrumentation } from '../src'; | ||
import * as assert from 'assert'; | ||
import { TestMetricReader } from './testMetricsReader'; | ||
import { metricNames } from '../src/metrics/heapSizeAndUsedCollector'; | ||
|
||
const MEASUREMENT_INTERVAL = 10; | ||
|
||
describe('nodejs.heap_size', function () { | ||
let metricReader: TestMetricReader; | ||
let meterProvider: MeterProvider; | ||
|
||
beforeEach(() => { | ||
metricReader = new TestMetricReader(); | ||
meterProvider = new MeterProvider(); | ||
meterProvider.addMetricReader(metricReader); | ||
}); | ||
|
||
for (const metricName of metricNames) { | ||
it(`should write nodejs.${metricName.name} 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 === 'nodejs.' + metricName.name | ||
); | ||
|
||
assert.notEqual(metric, undefined, `nodejs.${metricName.name} not found`); | ||
|
||
assert.strictEqual( | ||
metric!.dataPointType, | ||
DataPointType.GAUGE, | ||
'expected gauge' | ||
); | ||
|
||
assert.strictEqual( | ||
metric!.descriptor.name, | ||
'nodejs.' + metricName.name, | ||
'descriptor.name' | ||
); | ||
}); | ||
} | ||
}); |
75 changes: 75 additions & 0 deletions
75
plugins/node/instrumentation-runtime-node/test/heap_space_and_used.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 { MeterProvider, DataPointType } from '@opentelemetry/sdk-metrics'; | ||
|
||
import { RuntimeNodeInstrumentation } from '../src'; | ||
import * as assert from 'assert'; | ||
import { TestMetricReader } from './testMetricsReader'; | ||
import { metricNames } from '../src/metrics/heapSpacesSizeAndUsedCollector'; | ||
|
||
const MEASUREMENT_INTERVAL = 10; | ||
|
||
describe('nodejs.heap_space', function () { | ||
let metricReader: TestMetricReader; | ||
let meterProvider: MeterProvider; | ||
|
||
beforeEach(() => { | ||
metricReader = new TestMetricReader(); | ||
meterProvider = new MeterProvider(); | ||
meterProvider.addMetricReader(metricReader); | ||
}); | ||
|
||
for (const metricName of metricNames) { | ||
it(`should write nodejs.${metricName.name} 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 === 'nodejs.' + metricName.name | ||
); | ||
|
||
assert.notEqual(metric, undefined, `nodejs.${metricName.name} not found`); | ||
|
||
assert.strictEqual( | ||
metric!.dataPointType, | ||
DataPointType.GAUGE, | ||
'expected gauge' | ||
); | ||
|
||
assert.strictEqual( | ||
metric!.descriptor.name, | ||
'nodejs.' + metricName.name, | ||
'descriptor.name' | ||
); | ||
}); | ||
} | ||
}); |
Oops, something went wrong.