-
Notifications
You must be signed in to change notification settings - Fork 917
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
Spring boot runtime metrics naive reduced multi config #13236
Closed
zeitlinger
wants to merge
36
commits into
open-telemetry:main
from
zeitlinger:spring-boot-runtime-metrics-naive-reduced-multi-config
Closed
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
f93d7bb
spring boot runtime metrics for java 17+
zeitlinger fb54edc
spring boot runtime metrics for java 8
zeitlinger 34d761e
spring boot runtime metrics for java 8
zeitlinger 71643b2
fix native
zeitlinger 526f6c4
use spring shutdown hook
zeitlinger 4b9a290
disable threads
zeitlinger e64008a
disable threads
zeitlinger 97d9910
test more metric types
zeitlinger b40bbfd
add metadata
zeitlinger 34ca187
fix jfr and native image
zeitlinger 1610fef
fix jfr and native image
zeitlinger 45897c1
review
zeitlinger ff4f83b
test more metrics
zeitlinger 7a9f89d
improve assertions by showing the last result on a timeout
zeitlinger 04bfdb1
test more metrics
zeitlinger 2da5ece
format
zeitlinger 1033068
use newer graalvm
zeitlinger 3101320
Revert "improve assertions by showing the last result on a timeout"
zeitlinger beb4d9a
init at build time
zeitlinger 0785e1f
init at build time
zeitlinger 6850c88
disable jfr for native for now
zeitlinger b2e74cb
fix jfr
zeitlinger 530ee61
fix buffer pools
zeitlinger 7c68b99
fix buffer pools
zeitlinger 4e4e550
extract metrics providers
zeitlinger 7bd27d7
exclude JFR from native image at build time
zeitlinger f6cb08e
format
zeitlinger a348fed
Update instrumentation/spring/spring-boot-autoconfigure/src/main/java…
zeitlinger fcdc4df
format
zeitlinger 8823ffc
try out using multiple configurations
zeitlinger 09105bf
use spring conditions
zeitlinger 355b253
use spring conditions
zeitlinger 2f9edc8
use spring conditions
zeitlinger ca201d4
Update instrumentation/spring/spring-boot-autoconfigure/src/main/java…
zeitlinger 77e61d7
format
zeitlinger b85a04e
use spring conditions
zeitlinger 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
4 changes: 3 additions & 1 deletion
4
...o.opentelemetry.instrumentation/opentelemetry-instrumentation-api/native-image.properties
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Args=\ | ||
--initialize-at-build-time=io.opentelemetry.instrumentation.api.internal.cache.concurrentlinkedhashmap.ConcurrentLinkedHashMap | ||
--initialize-at-build-time=io.opentelemetry.instrumentation.api.internal.cache.concurrentlinkedhashmap.ConcurrentLinkedHashMap \ | ||
--initialize-at-build-time=io.opentelemetry.instrumentation.api.internal.cache.MapBackedCache \ | ||
--initialize-at-build-time=io.opentelemetry.api.internal.InternalAttributeKeyImpl |
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
60 changes: 60 additions & 0 deletions
60
...y/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java8/RuntimeMetrics.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,60 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.runtimemetrics.java8; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.runtimemetrics.java8.internal.JmxRuntimeMetricsUtil; | ||
import java.io.Closeable; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** The entry point class for runtime metrics support using JMX. */ | ||
public final class RuntimeMetrics implements Closeable { | ||
|
||
private static final Logger logger = Logger.getLogger(RuntimeMetrics.class.getName()); | ||
|
||
private final AtomicBoolean isClosed = new AtomicBoolean(); | ||
private final List<AutoCloseable> observables; | ||
|
||
RuntimeMetrics(List<AutoCloseable> observables) { | ||
this.observables = Collections.unmodifiableList(observables); | ||
} | ||
|
||
/** | ||
* Create and start {@link RuntimeMetrics}. | ||
* | ||
* <p>Listens for select JMX beans, extracts data, and records to various metrics. Recording will | ||
* continue until {@link #close()} is called. | ||
* | ||
* @param openTelemetry the {@link OpenTelemetry} instance used to record telemetry | ||
*/ | ||
public static RuntimeMetrics create(OpenTelemetry openTelemetry) { | ||
return new RuntimeMetricsBuilder(openTelemetry).build(); | ||
} | ||
|
||
/** | ||
* Create a builder for configuring {@link RuntimeMetrics}. | ||
* | ||
* @param openTelemetry the {@link OpenTelemetry} instance used to record telemetry | ||
*/ | ||
public static RuntimeMetricsBuilder builder(OpenTelemetry openTelemetry) { | ||
return new RuntimeMetricsBuilder(openTelemetry); | ||
} | ||
|
||
/** Stop recording JMX metrics. */ | ||
@Override | ||
public void close() { | ||
if (!isClosed.compareAndSet(false, true)) { | ||
logger.log(Level.WARNING, "RuntimeMetrics is already closed"); | ||
return; | ||
} | ||
|
||
JmxRuntimeMetricsUtil.closeObservers(observables); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ain/java/io/opentelemetry/instrumentation/runtimemetrics/java8/RuntimeMetricsBuilder.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,67 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.runtimemetrics.java8; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.incubator.config.internal.InstrumentationConfig; | ||
import io.opentelemetry.instrumentation.runtimemetrics.java8.internal.JmxRuntimeMetricsFactory; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
/** Builder for {@link RuntimeMetrics}. */ | ||
public final class RuntimeMetricsBuilder { | ||
|
||
private final OpenTelemetry openTelemetry; | ||
|
||
private boolean enableExperimentalJmxTelemetry = false; | ||
private Consumer<Runnable> shutdownHook = | ||
runnable -> { | ||
Runtime.getRuntime() | ||
.addShutdownHook(new Thread(runnable, "OpenTelemetry RuntimeMetricsShutdownHook")); | ||
}; | ||
|
||
RuntimeMetricsBuilder(OpenTelemetry openTelemetry) { | ||
this.openTelemetry = openTelemetry; | ||
} | ||
|
||
/** Enable all JMX telemetry collection. */ | ||
@CanIgnoreReturnValue | ||
public RuntimeMetricsBuilder enableExperimentalJmxTelemetry() { | ||
enableExperimentalJmxTelemetry = true; | ||
return this; | ||
} | ||
|
||
/** Build and start an {@link RuntimeMetrics} with the config from this builder. */ | ||
public RuntimeMetrics build() { | ||
List<AutoCloseable> observables = | ||
JmxRuntimeMetricsFactory.buildObservables(openTelemetry, enableExperimentalJmxTelemetry); | ||
return new RuntimeMetrics(observables); | ||
} | ||
|
||
/** Set a custom shutdown hook for the {@link RuntimeMetrics}. */ | ||
@CanIgnoreReturnValue | ||
public RuntimeMetricsBuilder setShutdownHook(Consumer<Runnable> shutdownHook) { | ||
this.shutdownHook = shutdownHook; | ||
return this; | ||
} | ||
|
||
public void startFromInstrumentationConfig(InstrumentationConfig config) { | ||
boolean defaultEnabled = config.getBoolean("otel.instrumentation.common.default-enabled", true); | ||
if (!config.getBoolean("otel.instrumentation.runtime-telemetry.enabled", defaultEnabled)) { | ||
// nothing is enabled | ||
return; | ||
} | ||
|
||
if (config.getBoolean( | ||
"otel.instrumentation.runtime-telemetry.emit-experimental-telemetry", false)) { | ||
this.enableExperimentalJmxTelemetry(); | ||
} | ||
|
||
RuntimeMetrics runtimeMetrics = this.build(); | ||
shutdownHook.accept(runtimeMetrics::close); | ||
} | ||
} |
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.
(minor)
Having two
RuntimeMetrics
classes (Java 8 and Java 17) has confused me.Perhaps renamed this one into
Java8RuntimeMetrics
?Same comment for
RuntimeMetricsBuilder
.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.
these classes were not introduced by this PR - let's do it separately
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 PR adds
RuntimeMetrics
andRuntimeMetricsBuilder
classes for Java 17. So, these class names exist both for the Java 8 and Java 17 runtime metrics implementations.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 - renamed (in #13173)