-
Notifications
You must be signed in to change notification settings - Fork 646
feat(instr-runtime-node): add configurable gcDurationBuckets option #3328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lukeramsden
wants to merge
2
commits into
open-telemetry:main
Choose a base branch
from
lukeramsden:claude/configurable-bucket-boundaries-yBSUx
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,132 @@ | ||
| /* | ||
| * 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 { MeterProvider, DataPointType } from '@opentelemetry/sdk-metrics'; | ||
| import { RuntimeNodeInstrumentation } from '../src'; | ||
| import { TestMetricReader } from './testMetricsReader'; | ||
| import { METRIC_V8JS_GC_DURATION } from '../src/semconv'; | ||
|
|
||
| const MEASUREMENT_INTERVAL = 10; | ||
|
|
||
| // Helper to trigger GC by allocating memory | ||
| function triggerGC() { | ||
| const arrays = []; | ||
| for (let i = 0; i < 100; i++) { | ||
| arrays.push(new Array(10000).fill(i)); | ||
| } | ||
| // Allow garbage collection by clearing references | ||
| arrays.length = 0; | ||
| if (global.gc) { | ||
| global.gc(); | ||
| } | ||
| } | ||
|
|
||
| describe('v8js.gc.duration', function () { | ||
| let metricReader: TestMetricReader; | ||
| let meterProvider: MeterProvider; | ||
| let instrumentation: RuntimeNodeInstrumentation; | ||
|
|
||
| beforeEach(() => { | ||
| metricReader = new TestMetricReader(); | ||
| meterProvider = new MeterProvider({ | ||
| readers: [metricReader], | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| instrumentation.disable(); | ||
| }); | ||
|
|
||
| it('should create histogram with default gcDurationBuckets', async function () { | ||
| // arrange | ||
| instrumentation = new RuntimeNodeInstrumentation({ | ||
| monitoringPrecision: MEASUREMENT_INTERVAL, | ||
| }); | ||
| instrumentation.setMeterProvider(meterProvider); | ||
|
|
||
| // act - trigger GC | ||
| triggerGC(); | ||
| await new Promise(resolve => | ||
| setTimeout(resolve, MEASUREMENT_INTERVAL * 10) | ||
| ); | ||
| triggerGC(); | ||
| 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_GC_DURATION | ||
| ); | ||
|
|
||
| assert.notEqual(metric, undefined, `${METRIC_V8JS_GC_DURATION} not found`); | ||
| assert.strictEqual( | ||
| metric!.dataPointType, | ||
| DataPointType.HISTOGRAM, | ||
| 'expected histogram' | ||
| ); | ||
| assert.strictEqual( | ||
| metric!.descriptor.unit, | ||
| 's', | ||
| 'expected unit to be seconds' | ||
| ); | ||
| }); | ||
|
|
||
| it('should allow custom gcDurationBuckets configuration', async function () { | ||
| // arrange | ||
| const customBuckets = [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1]; | ||
| instrumentation = new RuntimeNodeInstrumentation({ | ||
| monitoringPrecision: MEASUREMENT_INTERVAL, | ||
| gcDurationBuckets: customBuckets, | ||
| }); | ||
| instrumentation.setMeterProvider(meterProvider); | ||
|
|
||
| // act - trigger GC | ||
| triggerGC(); | ||
| await new Promise(resolve => | ||
| setTimeout(resolve, MEASUREMENT_INTERVAL * 10) | ||
| ); | ||
| triggerGC(); | ||
| 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_GC_DURATION | ||
| ); | ||
|
|
||
| assert.notEqual(metric, undefined, `${METRIC_V8JS_GC_DURATION} not found`); | ||
| assert.strictEqual( | ||
| metric!.dataPointType, | ||
| DataPointType.HISTOGRAM, | ||
| 'expected histogram' | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the test failures might be related to this change, what this parameter does? does it need some extra info to find specific files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exposes the ability to trigger GC which is what the test uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how it would be possible to test this instrumentation collector without this flag which is I assume why there were no tests in the first place
I believe that v18 and v20 of Node that your CI tests with do not have this flag and therefore I do not know how one would test this collector on those versions. Up to you how to proceed, we could:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a script that can be used to skip tests given a certain major version (only major). A possible solution is to:
global.gc()method is not avaiableExample of how the scripts would look like.
WDYT?