-
Notifications
You must be signed in to change notification settings - Fork 150
[jmx-scraper] Assertions refactoring - Tomcat integration test converted #1589
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
Changes from 55 commits
c3deb51
fcf2bf8
d833450
8cb96ad
f3bac7e
c9eb0a7
2c85c38
bd1947f
1e64f80
f7c6373
b10a340
65ddfb3
db54835
1bdf694
9f8a394
6fb7960
a458c1c
b9f054c
cf72d19
eab7c69
9c3390c
9392780
5ae735d
2c65318
a670561
df09034
06a968f
0e5fd2c
8062a96
ba95efa
4bed658
fddc5fc
fd82042
80994f2
b26cf42
0bf10f5
9f47ef6
2971ef7
7d7e504
19f5d4c
6431feb
ba0f900
fdc64e3
7754e3a
7b7f0d0
cdf4c74
b170021
59a7dfc
34b3ab3
45ba126
5e69a82
dfe3af3
159cb5f
036ea99
687002c
cf0a17a
ebedd5f
d286b7a
014d7c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,9 +5,9 @@ | |||||
|
||||||
package io.opentelemetry.contrib.jmxscraper.target_systems; | ||||||
|
||||||
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertGaugeWithAttributes; | ||||||
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes; | ||||||
import static org.assertj.core.api.Assertions.entry; | ||||||
import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attribute; | ||||||
import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attributeGroup; | ||||||
import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attributeWithAnyValue; | ||||||
|
||||||
import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; | ||||||
import java.nio.file.Path; | ||||||
|
@@ -46,67 +46,76 @@ protected JmxScraperContainer customizeScraperContainer( | |||||
} | ||||||
|
||||||
@Override | ||||||
protected void verifyMetrics() { | ||||||
waitAndAssertMetrics( | ||||||
metric -> | ||||||
assertGaugeWithAttributes( | ||||||
metric, | ||||||
"tomcat.sessions", | ||||||
"The number of active sessions", | ||||||
"sessions", | ||||||
attrs -> attrs.containsKey("context")), | ||||||
metric -> | ||||||
assertSumWithAttributes( | ||||||
metric, | ||||||
"tomcat.errors", | ||||||
"The number of errors encountered", | ||||||
"errors", | ||||||
attrs -> attrs.containsOnly(entry("proto_handler", "\"http-nio-8080\""))), | ||||||
metric -> | ||||||
assertSumWithAttributes( | ||||||
metric, | ||||||
"tomcat.processing_time", | ||||||
"The total processing time", | ||||||
"ms", | ||||||
attrs -> attrs.containsOnly(entry("proto_handler", "\"http-nio-8080\""))), | ||||||
metric -> | ||||||
assertSumWithAttributes( | ||||||
metric, | ||||||
"tomcat.traffic", | ||||||
"The number of bytes transmitted and received", | ||||||
"by", | ||||||
attrs -> | ||||||
attrs.containsOnly( | ||||||
entry("proto_handler", "\"http-nio-8080\""), entry("direction", "sent")), | ||||||
attrs -> | ||||||
attrs.containsOnly( | ||||||
entry("proto_handler", "\"http-nio-8080\""), | ||||||
entry("direction", "received"))), | ||||||
metric -> | ||||||
assertGaugeWithAttributes( | ||||||
metric, | ||||||
"tomcat.threads", | ||||||
"The number of threads", | ||||||
"threads", | ||||||
attrs -> | ||||||
attrs.containsOnly( | ||||||
entry("proto_handler", "\"http-nio-8080\""), entry("state", "idle")), | ||||||
attrs -> | ||||||
attrs.containsOnly( | ||||||
entry("proto_handler", "\"http-nio-8080\""), entry("state", "busy"))), | ||||||
metric -> | ||||||
assertGaugeWithAttributes( | ||||||
metric, | ||||||
"tomcat.max_time", | ||||||
"Maximum time to process a request", | ||||||
"ms", | ||||||
attrs -> attrs.containsOnly(entry("proto_handler", "\"http-nio-8080\""))), | ||||||
metric -> | ||||||
assertSumWithAttributes( | ||||||
metric, | ||||||
"tomcat.request_count", | ||||||
"The total requests", | ||||||
"requests", | ||||||
attrs -> attrs.containsOnly(entry("proto_handler", "\"http-nio-8080\"")))); | ||||||
protected MetricsVerifier createMetricsVerifier() { | ||||||
return MetricsVerifier.create() | ||||||
.add( | ||||||
"tomcat.sessions", | ||||||
metric -> | ||||||
metric | ||||||
.hasDescription("The number of active sessions") | ||||||
.hasUnit("sessions") // TODO: not aligned with semconv. Should be "{session}" | ||||||
.isGauge() | ||||||
.hasDataPointsWithOneAttribute(attributeWithAnyValue("context"))) | ||||||
.add( | ||||||
"tomcat.errors", | ||||||
metric -> | ||||||
metric | ||||||
.hasDescription("The number of errors encountered") | ||||||
.hasUnit("errors") // TODO: not aligned with semconv. Should be "{error}" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as previous comment. |
||||||
.isCounter() | ||||||
.hasDataPointsWithOneAttribute(attribute("proto_handler", "\"http-nio-8080\""))) | ||||||
.add( | ||||||
"tomcat.processing_time", | ||||||
metric -> | ||||||
metric | ||||||
.hasDescription("The total processing time") | ||||||
.hasUnit("ms") | ||||||
.isCounter() | ||||||
.hasDataPointsWithOneAttribute(attribute("proto_handler", "\"http-nio-8080\""))) | ||||||
.add( | ||||||
"tomcat.traffic", | ||||||
metric -> | ||||||
metric | ||||||
.hasDescription("The number of bytes transmitted and received") | ||||||
.hasUnit("by") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
See https://opentelemetry.io/docs/specs/semconv/general/metrics/#instrument-units https://unitsofmeasure.org/ucum#para-48 and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, however the same doubts apply here |
||||||
.isCounter() | ||||||
.hasDataPointsWithAttributes( | ||||||
attributeGroup( | ||||||
attribute("direction", "sent"), | ||||||
attribute("proto_handler", "\"http-nio-8080\"")), | ||||||
attributeGroup( | ||||||
attribute("direction", "received"), | ||||||
attribute("proto_handler", "\"http-nio-8080\"")))) | ||||||
.add( | ||||||
"tomcat.threads", | ||||||
metric -> | ||||||
metric | ||||||
.hasDescription("The number of threads") | ||||||
.hasUnit("threads") // TODO: not aligned with semconv. Should be "{thread}" | ||||||
.isGauge() | ||||||
.hasDataPointsWithAttributes( | ||||||
attributeGroup( | ||||||
attribute("state", "idle"), | ||||||
attribute("proto_handler", "\"http-nio-8080\"")), | ||||||
attributeGroup( | ||||||
attribute("state", "busy"), | ||||||
attribute("proto_handler", "\"http-nio-8080\"")))) | ||||||
.add( | ||||||
"tomcat.max_time", | ||||||
metric -> | ||||||
metric | ||||||
.hasDescription("Maximum time to process a request") | ||||||
.hasUnit("ms") | ||||||
.isGauge() | ||||||
.hasDataPointsWithOneAttribute(attribute("proto_handler", "\"http-nio-8080\""))) | ||||||
.add( | ||||||
"tomcat.request_count", | ||||||
metric -> | ||||||
metric | ||||||
.hasDescription("The total requests") | ||||||
.hasUnit("requests") // TODO: not aligned with semconv. Should be "{request}" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as previous, we'd better fix those units inconsistencies when we find them. |
||||||
.isCounter() | ||||||
.hasDataPointsWithOneAttribute( | ||||||
attribute("proto_handler", "\"http-nio-8080\""))); | ||||||
} | ||||||
} |
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.
Like in the previous PRs where such units inconsistencies were found I think it's worth fixing them straight away as they aren't "breaking changes" most of the time and we will have to fix it at some point because it's now part of the stable semantic conventtions.
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.
So my understanding is that in this case it may be a kind of breaking change. This is not the annotation in curly braces that is supposed to be skipped by parser.
I've been hesitating if I should update it or not and finally decided to leave it, but if reviewers agree that it should be changed then I'll gladly update it.
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 think it's ok to update it since we are updating units elsewhere (in OTel we've said changing units is breaking whether they're curly braces or not)
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.
Great! I'll make the fix then