-
Notifications
You must be signed in to change notification settings - Fork 1k
Jmx unit semconv alignment - Tomcat #13650
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
Merged
trask
merged 31 commits into
open-telemetry:main
from
robsunday:jmx-unit-semconv-alignment
May 29, 2025
Merged
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d081c29
add test code to test yaml jmx metrics
SylvainJuge e1f60cd
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 02e8a41
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday dfae1ac
Tomcat metrics updated
robsunday e272d84
Tomcat test added
robsunday 2d2c264
tomcat.active_session.count support added in test
robsunday 15ad839
Comment added to test
robsunday 297fb6b
Checkstyle error fix
robsunday e8fdc29
Attr name fixed
robsunday 185e60d
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 8a9bb0f
Test fixed.
robsunday 1cc4080
Test fixed.
robsunday 747ec32
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 816b9ed
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 910e837
Thread count related metrics fixed after code review
robsunday 0dc6775
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 1dcd568
Readme updates
robsunday 38fb785
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 99104ee
Update instrumentation/jmx-metrics/library/src/main/resources/jmx/rul…
robsunday f8cc647
Update instrumentation/jmx-metrics/library/src/main/resources/jmx/rul…
robsunday 299b35c
Code review changes
robsunday ee7faec
Fixed tomcat.md
robsunday 5bdbabd
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday b5fdd29
tomcat.request.duration.total -> tomcat.request.duration.sum
robsunday 6f69f76
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday c3248f1
Update instrumentation/jmx-metrics/library/tomcat.md
robsunday 7c4afcb
tomcat.request_processor.name -> tomcat.request.processor.name
robsunday aee5f06
Merge branch 'main' into jmx-unit-semconv-alignment
robsunday 616014e
Update instrumentation/jmx-metrics/library/tomcat.md
robsunday 8ad8974
Indentation fixed
robsunday 9f07105
Unit descriptions tuning
robsunday 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
79 changes: 0 additions & 79 deletions
79
instrumentation/jmx-metrics/javaagent/src/main/resources/jmx/rules/tomcat.yaml
This file was deleted.
Oops, something went wrong.
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
82 changes: 82 additions & 0 deletions
82
instrumentation/jmx-metrics/library/src/main/resources/jmx/rules/tomcat.yaml
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,82 @@ | ||
| --- | ||
| # For Tomcat, the default JMX domain is "Catalina:", however with some deployments like embedded in spring-boot | ||
| # we can have the "Tomcat:" domain used, thus we use both MBean names for the metrics. | ||
|
|
||
| rules: | ||
| - beans: | ||
| - Catalina:type=GlobalRequestProcessor,name=* | ||
| - Tomcat:type=GlobalRequestProcessor,name=* | ||
| prefix: tomcat. | ||
| metricAttribute: | ||
| tomcat.request_processor.name: param(name) | ||
| mapping: | ||
| errorCount: | ||
| metric: error.count | ||
| type: counter | ||
| unit: "{error}" | ||
| desc: The number of errors. | ||
| requestCount: | ||
| metric: request.count | ||
| type: counter | ||
| unit: "{request}" | ||
| desc: The number of requests processed. | ||
| maxTime: | ||
| metric: request.duration.max | ||
| type: gauge | ||
robsunday marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sourceUnit: ms | ||
| unit: s | ||
| desc: The longest request processing time. | ||
| processingTime: | ||
robsunday marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| metric: request.processing_time | ||
| type: counter | ||
| sourceUnit: ms | ||
| unit: s | ||
| desc: Total time for processing all requests. | ||
| bytesReceived: | ||
| metric: &metric network.io | ||
| type: &type counter | ||
| unit: &unit By | ||
| desc: &desc The number of bytes transmitted. | ||
| metricAttribute: | ||
| tomcat.network.io.direction: const(received) | ||
| bytesSent: | ||
| metric: *metric | ||
| type: *type | ||
| unit: *unit | ||
| desc: *desc | ||
| metricAttribute: | ||
| tomcat.network.io.direction: const(sent) | ||
robsunday marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - beans: | ||
| - Catalina:type=Manager,host=localhost,context=* | ||
| - Tomcat:type=Manager,host=localhost,context=* | ||
| prefix: tomcat. | ||
| metricAttribute: | ||
| tomcat.web_app_context: param(context) | ||
robsunday marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mapping: | ||
| activeSessions: | ||
| metric: active_session.count | ||
robsunday marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type: updowncounter | ||
| unit: "{session}" | ||
| desc: The number of active sessions. | ||
|
|
||
| - beans: | ||
| - Catalina:type=ThreadPool,name=* | ||
| - Tomcat:type=ThreadPool,name=* | ||
| unit: "{thread}" | ||
| prefix: tomcat. | ||
| type: updowncounter | ||
| metricAttribute: | ||
| tomcat.thread_pool.name: param(name) | ||
robsunday marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mapping: | ||
robsunday marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| currentThreadCount: | ||
| metric: &metric thread.count | ||
| desc: &desc Thread count of the thread pool. | ||
| metricAttribute: | ||
| tomcat.thread.state: const(idle) | ||
| currentThreadsBusy: | ||
| metric: *metric | ||
| desc: *desc | ||
| metricAttribute: | ||
| tomcat.thread.state: const(busy) | ||
|
|
||
SylvainJuge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
124 changes: 124 additions & 0 deletions
124
...ics/library/src/test/java/io/opentelemetry/instrumentation/jmx/rules/MetricsVerifier.java
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,124 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.jmx.rules; | ||
|
|
||
| import static io.opentelemetry.instrumentation.jmx.rules.assertions.JmxAssertj.assertThat; | ||
| import static org.assertj.core.api.Assertions.fail; | ||
|
|
||
| import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
| import io.opentelemetry.instrumentation.jmx.rules.assertions.MetricAssert; | ||
| import io.opentelemetry.proto.metrics.v1.Metric; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.function.Consumer; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class MetricsVerifier { | ||
|
|
||
| private final Map<String, Consumer<Metric>> assertions = new HashMap<>(); | ||
| private boolean strictMode = true; | ||
|
|
||
| private MetricsVerifier() {} | ||
|
|
||
| /** | ||
| * Create instance of MetricsVerifier configured to fail verification if any metric was not | ||
| * verified because there is no assertion defined for it. This behavior can be changed by calling | ||
| * {@link #disableStrictMode()} method. | ||
| * | ||
| * @return new instance of MetricsVerifier | ||
| * @see #disableStrictMode() | ||
| */ | ||
| public static MetricsVerifier create() { | ||
| return new MetricsVerifier(); | ||
| } | ||
|
|
||
| /** | ||
| * Disable strict checks of metric assertions. It means that all metrics checks added after | ||
| * calling this method will not enforce asserting all metric properties and will not detect | ||
| * duplicate property assertions. Also, there will be no error reported if any of metrics was | ||
| * skipped because no assertion was added for it. | ||
| * | ||
| * @return this | ||
| * @see #verify(List) | ||
| * @see #add(String, Consumer) | ||
| */ | ||
| @CanIgnoreReturnValue | ||
| public MetricsVerifier disableStrictMode() { | ||
| strictMode = false; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Add assertion for given metric | ||
| * | ||
| * @param metricName name of metric to be verified by provided assertion | ||
| * @param assertion an assertion to verify properties of the metric | ||
| * @return this | ||
| */ | ||
| @CanIgnoreReturnValue | ||
| public MetricsVerifier add(String metricName, Consumer<MetricAssert> assertion) { | ||
| if (assertions.containsKey(metricName)) { | ||
| throw new IllegalArgumentException("Duplicate assertion for metric " + metricName); | ||
| } | ||
| assertions.put( | ||
| metricName, | ||
| metric -> { | ||
| MetricAssert metricAssert = assertThat(metric); | ||
| metricAssert.setStrict(strictMode); | ||
| assertion.accept(metricAssert); | ||
| metricAssert.strictCheck(); | ||
| }); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Execute all defined assertions against provided list of metrics. Error is reported if any of | ||
| * defined assertions failed. Error is also reported if any of expected metrics was not present in | ||
| * the metrics list, unless strict mode is disabled with {@link #disableStrictMode()}. | ||
| * | ||
| * @param metrics list of metrics to be verified | ||
| * @see #add(String, Consumer) | ||
| * @see #disableStrictMode() | ||
| */ | ||
| public void verify(List<Metric> metrics) { | ||
| verifyAllExpectedMetricsWereReceived(metrics); | ||
|
|
||
| Set<String> unverifiedMetrics = new HashSet<>(); | ||
|
|
||
| for (Metric metric : metrics) { | ||
| String metricName = metric.getName(); | ||
| Consumer<Metric> assertion = assertions.get(metricName); | ||
|
|
||
| if (assertion != null) { | ||
| assertion.accept(metric); | ||
| } else { | ||
| unverifiedMetrics.add(metricName); | ||
| } | ||
| } | ||
|
|
||
| if (strictMode && !unverifiedMetrics.isEmpty()) { | ||
| fail("Metrics received but not verified because no assertion exists: " + unverifiedMetrics); | ||
| } | ||
| } | ||
|
|
||
| private void verifyAllExpectedMetricsWereReceived(List<Metric> metrics) { | ||
| Set<String> receivedMetricNames = | ||
| metrics.stream().map(Metric::getName).collect(Collectors.toSet()); | ||
| Set<String> assertionNames = new HashSet<>(assertions.keySet()); | ||
|
|
||
| assertionNames.removeAll(receivedMetricNames); | ||
| if (!assertionNames.isEmpty()) { | ||
| fail( | ||
| "Metrics expected but not received: " | ||
| + assertionNames | ||
| + "\nReceived only: " | ||
| + receivedMetricNames); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.