-
Notifications
You must be signed in to change notification settings - Fork 873
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
add file descriptor metrics #11876
Open
xiangtianyu
wants to merge
10
commits into
open-telemetry:main
Choose a base branch
from
xiangtianyu:file-metrics
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.
+189
−26
Open
add file descriptor metrics #11876
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a68a8d7
add file descriptor metrics
xiangtianyu ee39c6b
fix code style
xiangtianyu 5dc42b3
fix some desciption and name and some test
xiangtianyu df6fc6c
fix tests
xiangtianyu 4f70a6e
Merge branch 'main' into file-metrics
xiangtianyu 752143d
add comment relate to issue
xiangtianyu 71e5ccd
fix
xiangtianyu 6ea98ec
fix
xiangtianyu 298eb0c
code style
xiangtianyu cc4fb9b
modify metrics name
xiangtianyu 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 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 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 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 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
74 changes: 74 additions & 0 deletions
74
...entelemetry/instrumentation/runtimemetrics/java8/internal/ExperimentalFileDescriptor.java
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,74 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.runtimemetrics.java8.internal; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Registers measurements that generate experimental metrics about file descriptor. These metrics | ||
* are experimental, see <a | ||
* href="https://github.com/open-telemetry/semantic-conventions/issues/1275">File Descriptor metrics | ||
* semantic conventions</a>. | ||
* | ||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
* at any time. | ||
*/ | ||
public class ExperimentalFileDescriptor { | ||
/** Register observers for java runtime experimental file descriptor metrics. */ | ||
public static List<AutoCloseable> registerObservers(OpenTelemetry openTelemetry) { | ||
return registerObservers( | ||
openTelemetry, | ||
OperatingSystemMethods.openFileDescriptorCount(), | ||
OperatingSystemMethods.maxFileDescriptorCount()); | ||
} | ||
|
||
// Visible for testing | ||
static List<AutoCloseable> registerObservers( | ||
OpenTelemetry openTelemetry, | ||
Supplier<Long> openFileDescriptorCount, | ||
Supplier<Long> maxFileDescriptorCount) { | ||
Meter meter = JmxRuntimeMetricsUtil.getMeter(openTelemetry); | ||
List<AutoCloseable> observables = new ArrayList<>(); | ||
|
||
if (openFileDescriptorCount != null) { | ||
observables.add( | ||
meter | ||
.upDownCounterBuilder("process.open_file_descriptor.count") | ||
.setDescription("Number of file descriptors in use by the process.") | ||
.setUnit("{count}") | ||
.buildWithCallback( | ||
observableMeasurement -> { | ||
Long openCount = openFileDescriptorCount.get(); | ||
if (openCount != null && openCount > 0) { | ||
observableMeasurement.record(openCount); | ||
} | ||
})); | ||
} | ||
|
||
if (maxFileDescriptorCount != null) { | ||
observables.add( | ||
meter | ||
.upDownCounterBuilder("process.open_file_descriptor.limit") | ||
xiangtianyu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.setDescription("Measure of max file descriptors.") | ||
.setUnit("{count}") | ||
.buildWithCallback( | ||
observableMeasurement -> { | ||
Long maxCount = maxFileDescriptorCount.get(); | ||
if (maxCount != null && maxCount >= 0) { | ||
observableMeasurement.record(maxCount); | ||
} | ||
})); | ||
} | ||
|
||
return observables; | ||
} | ||
|
||
private ExperimentalFileDescriptor() {} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...lemetry/instrumentation/runtimemetrics/java8/internal/ExperimentalFileDescriptorTest.java
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,54 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.runtimemetrics.java8.internal; | ||
|
||
import static io.opentelemetry.instrumentation.runtimemetrics.java8.ScopeUtil.EXPECTED_SCOPE; | ||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; | ||
|
||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; | ||
import java.util.function.Supplier; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class ExperimentalFileDescriptorTest { | ||
@RegisterExtension | ||
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); | ||
|
||
@Test | ||
void registerObservers() { | ||
Supplier<Long> openFileDescriptor = () -> 10L; | ||
Supplier<Long> maxFileDescriptor = () -> 10000L; | ||
|
||
ExperimentalFileDescriptor.registerObservers( | ||
testing.getOpenTelemetry(), openFileDescriptor, maxFileDescriptor); | ||
|
||
testing.waitAndAssertMetrics( | ||
"io.opentelemetry.runtime-telemetry-java8", | ||
"process.open_file_descriptor.count", | ||
metrics -> | ||
metrics.anySatisfy( | ||
metricData -> | ||
assertThat(metricData) | ||
.hasInstrumentationScope(EXPECTED_SCOPE) | ||
.hasDescription("Number of file descriptors in use by the process.") | ||
.hasUnit("{count}") | ||
.hasLongSumSatisfying( | ||
sum -> sum.hasPointsSatisfying(point -> point.hasValue(10L))))); | ||
testing.waitAndAssertMetrics( | ||
"io.opentelemetry.runtime-telemetry-java8", | ||
"process.open_file_descriptor.limit", | ||
metrics -> | ||
metrics.anySatisfy( | ||
metricData -> | ||
assertThat(metricData) | ||
.hasInstrumentationScope(EXPECTED_SCOPE) | ||
.hasDescription("Measure of max file descriptors.") | ||
.hasUnit("{count}") | ||
.hasLongSumSatisfying( | ||
sum -> sum.hasPointsSatisfying(point -> point.hasValue(10000L))))); | ||
} | ||
} |
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.
Since this name isn't exactly the same as
process.open_file_descriptors
that is used by the host metric receiver we might as well go with a different name. I think it would be best to discuss these names and descriptions at the SIG meeting.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.
Ok, how can i propose this as a topic?
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.
based on https://github.com/open-telemetry/semantic-conventions/pull/1618/files
I'd suggest using
jvm.open_file_descriptor.count
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.
@trask do you also have suggestions for the metric descriptions and unit. Currently the unit is
{count}
.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.
good catch: open-telemetry/semantic-conventions#1662
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.
for description, I think we can use
from https://github.com/open-telemetry/semantic-conventions/blob/373a69574ec9605895102205d561b2476972e20c/model/process/metrics.yaml#L82