-
Notifications
You must be signed in to change notification settings - Fork 130
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
Reuse JMX Insights in Scraper + Tomcat support #1485
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5948f57
add snapshot dependency
SylvainJuge 7f7681b
first working poc with tomcat
SylvainJuge 93bf770
add comments for future config enhancement
SylvainJuge ac67d0f
fix typo
SylvainJuge 97038df
add tomcat yaml config
SylvainJuge 67a50a0
fix test logging + fail on unsupported system
SylvainJuge edb3d6e
plug things together + test JVM & Tomcat
SylvainJuge 3a36466
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-c…
SylvainJuge 70d0bb0
change case of exceptions msg
SylvainJuge 95c0b59
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-c…
SylvainJuge 69f0fd1
log received metrics at debug level
SylvainJuge 3362166
mapped port not mapped anymore
SylvainJuge 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ public void start() { | |
// for now only configure through JVM args | ||
List<String> arguments = new ArrayList<>(); | ||
arguments.add("java"); | ||
arguments.add("-Dotel.metrics.exporter=otlp"); | ||
SylvainJuge marked this conversation as resolved.
Show resolved
Hide resolved
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. I think it makes sense to align (long-term) if possible with the autoconfigure SDK defaults |
||
arguments.add("-Dotel.exporter.otlp.endpoint=" + endpoint); | ||
|
||
if (!targetSystems.isEmpty()) { | ||
|
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
126 changes: 126 additions & 0 deletions
126
...grationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/MetricAssertions.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,126 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.jmxscraper.target_systems; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.entry; | ||
|
||
import io.opentelemetry.proto.common.v1.KeyValue; | ||
import io.opentelemetry.proto.metrics.v1.Metric; | ||
import io.opentelemetry.proto.metrics.v1.NumberDataPoint; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Collectors; | ||
import org.assertj.core.api.MapAssert; | ||
|
||
/** Metrics assertions */ | ||
class MetricAssertions { | ||
|
||
private MetricAssertions() {} | ||
|
||
static void assertGauge(Metric metric, String name, String description, String unit) { | ||
assertThat(metric.getName()).isEqualTo(name); | ||
assertThat(metric.getDescription()).isEqualTo(description); | ||
assertThat(metric.getUnit()).isEqualTo(unit); | ||
assertThat(metric.hasGauge()).isTrue(); | ||
assertThat(metric.getGauge().getDataPointsList()) | ||
.satisfiesExactly(point -> assertThat(point.getAttributesList()).isEmpty()); | ||
} | ||
|
||
static void assertSum(Metric metric, String name, String description, String unit) { | ||
assertSum(metric, name, description, unit, /* isMonotonic= */ true); | ||
} | ||
|
||
static void assertSum( | ||
Metric metric, String name, String description, String unit, boolean isMonotonic) { | ||
assertThat(metric.getName()).isEqualTo(name); | ||
assertThat(metric.getDescription()).isEqualTo(description); | ||
assertThat(metric.getUnit()).isEqualTo(unit); | ||
assertThat(metric.hasSum()).isTrue(); | ||
assertThat(metric.getSum().getDataPointsList()) | ||
.satisfiesExactly(point -> assertThat(point.getAttributesList()).isEmpty()); | ||
assertThat(metric.getSum().getIsMonotonic()).isEqualTo(isMonotonic); | ||
} | ||
|
||
static void assertTypedGauge( | ||
Metric metric, String name, String description, String unit, List<String> types) { | ||
assertThat(metric.getName()).isEqualTo(name); | ||
assertThat(metric.getDescription()).isEqualTo(description); | ||
assertThat(metric.getUnit()).isEqualTo(unit); | ||
assertThat(metric.hasGauge()).isTrue(); | ||
assertTypedPoints(metric.getGauge().getDataPointsList(), types); | ||
} | ||
|
||
static void assertTypedSum( | ||
Metric metric, String name, String description, String unit, List<String> types) { | ||
assertThat(metric.getName()).isEqualTo(name); | ||
assertThat(metric.getDescription()).isEqualTo(description); | ||
assertThat(metric.getUnit()).isEqualTo(unit); | ||
assertThat(metric.hasSum()).isTrue(); | ||
assertTypedPoints(metric.getSum().getDataPointsList(), types); | ||
} | ||
|
||
@SafeVarargs | ||
static void assertSumWithAttributes( | ||
Metric metric, | ||
String name, | ||
String description, | ||
String unit, | ||
Consumer<MapAssert<String, String>>... attributeGroupAssertions) { | ||
assertThat(metric.getName()).isEqualTo(name); | ||
assertThat(metric.getDescription()).isEqualTo(description); | ||
assertThat(metric.getUnit()).isEqualTo(unit); | ||
assertThat(metric.hasSum()).isTrue(); | ||
assertAttributedPoints(metric.getSum().getDataPointsList(), attributeGroupAssertions); | ||
} | ||
|
||
@SafeVarargs | ||
static void assertGaugeWithAttributes( | ||
Metric metric, | ||
String name, | ||
String description, | ||
String unit, | ||
Consumer<MapAssert<String, String>>... attributeGroupAssertions) { | ||
assertThat(metric.getName()).isEqualTo(name); | ||
assertThat(metric.getDescription()).isEqualTo(description); | ||
assertThat(metric.getUnit()).isEqualTo(unit); | ||
assertThat(metric.hasGauge()).isTrue(); | ||
assertAttributedPoints(metric.getGauge().getDataPointsList(), attributeGroupAssertions); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static void assertTypedPoints(List<NumberDataPoint> points, List<String> types) { | ||
Consumer<MapAssert<String, String>>[] assertions = | ||
types.stream() | ||
.map( | ||
type -> | ||
(Consumer<MapAssert<String, String>>) | ||
attrs -> attrs.containsOnly(entry("name", type))) | ||
.toArray(Consumer[]::new); | ||
|
||
assertAttributedPoints(points, assertions); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static void assertAttributedPoints( | ||
List<NumberDataPoint> points, | ||
Consumer<MapAssert<String, String>>... attributeGroupAssertions) { | ||
Consumer<Map<String, String>>[] assertions = | ||
Arrays.stream(attributeGroupAssertions) | ||
.map(assertion -> (Consumer<Map<String, String>>) m -> assertion.accept(assertThat(m))) | ||
.toArray(Consumer[]::new); | ||
assertThat(points) | ||
.extracting( | ||
numberDataPoint -> | ||
numberDataPoint.getAttributesList().stream() | ||
.collect( | ||
Collectors.toMap( | ||
KeyValue::getKey, keyValue -> keyValue.getValue().getStringValue()))) | ||
.satisfiesExactlyInAnyOrder(assertions); | ||
} | ||
} |
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
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.
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'm merging anyways since
jmx-scraper
artifact isn't published yet so no worries about relying on snapshot repo from maven central