diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/NativeMonitoringBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/NativeMonitoringBuildItem.java new file mode 100644 index 0000000000000..a137322ab5ac5 --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/NativeMonitoringBuildItem.java @@ -0,0 +1,20 @@ +package io.quarkus.deployment.builditem; + +import io.quarkus.builder.item.MultiBuildItem; +import io.quarkus.deployment.pkg.NativeConfig; + +/** + * A build item that indicates whether native monitoring is enabled and which option from {@link NativeConfig.MonitoringOption}. + * To be used in the native image generation. + */ +public final class NativeMonitoringBuildItem extends MultiBuildItem { + private final NativeConfig.MonitoringOption option; + + public NativeMonitoringBuildItem(NativeConfig.MonitoringOption option) { + this.option = option; + } + + public NativeConfig.MonitoringOption getOption() { + return this.option; + } +} diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index fb8daf5b727cf..45cd6424d478a 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -11,10 +11,12 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Objects; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -24,6 +26,7 @@ import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.NativeImageFeatureBuildItem; +import io.quarkus.deployment.builditem.NativeMonitoringBuildItem; import io.quarkus.deployment.builditem.SuppressNonRuntimeConfigChangedWarningBuildItem; import io.quarkus.deployment.builditem.nativeimage.ExcludeConfigBuildItem; import io.quarkus.deployment.builditem.nativeimage.JPMSExportBuildItem; @@ -115,6 +118,7 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig, List nativeImageSecurityProviders, List nativeImageFeatures, NativeImageRunnerBuildItem nativeImageRunner, + List nativeMonitoringBuildItems, CurateOutcomeBuildItem curateOutcomeBuildItem) { Path outputDir; @@ -147,6 +151,7 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig, .setGraalVMVersion(GraalVM.Version.CURRENT) .setNativeImageFeatures(nativeImageFeatures) .setContainerBuild(nativeImageRunner.isContainerBuild()) + .setNativeMonitoringOptions(nativeMonitoringBuildItems) .build(); List command = nativeImageArgs.getArgs(); @@ -196,6 +201,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, LocalesBuildTimeCon Optional processInheritIODisabledBuildItem, List nativeImageFeatures, Optional nativeImageAgentConfigDirectoryBuildItem, + List nativeMonitoringItems, NativeImageRunnerBuildItem nativeImageRunner) { if (nativeConfig.debug().enabled()) { copyJarSourcesToLib(outputTargetBuildItem, curateOutcomeBuildItem); @@ -254,6 +260,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, LocalesBuildTimeCon .setBrokenClasspath(incompleteClassPathAllowed.isAllow()) .setNativeImageSecurityProviders(nativeImageSecurityProviders) .setJPMSExportBuildItems(jpmsExportBuildItems) + .setNativeMonitoringOptions(nativeMonitoringItems) .setEnableModules(enableModules) .setNativeMinimalJavaVersions(nativeMinimalJavaVersions) .setUnsupportedOSes(unsupportedOses) @@ -605,6 +612,7 @@ static class Builder { private List nativeMinimalJavaVersions; private List unsupportedOSes; private List nativeImageFeatures; + private List nativeMonitoringItems; private Path outputDir; private String runnerJarName; private String pie = ""; @@ -713,6 +721,11 @@ public Builder setNativeImageName(String nativeImageName) { return this; } + public Builder setNativeMonitoringOptions(List options) { + this.nativeMonitoringItems = options; + return this; + } + @SuppressWarnings("deprecation") public NativeImageInvokerInfo build() { List nativeImageArgs = new ArrayList<>(); @@ -932,17 +945,23 @@ public NativeImageInvokerInfo build() { nativeImageArgs.add("-march=" + nativeConfig.march().get()); } - List monitoringOptions = new ArrayList<>(); + Set monitoringOptions = new LinkedHashSet<>(); if (!OS.WINDOWS.isCurrent() || containerBuild) { // --enable-monitoring=heapdump is not supported on Windows monitoringOptions.add(NativeConfig.MonitoringOption.HEAPDUMP); } + + if (nativeMonitoringItems != null && !nativeMonitoringItems.isEmpty()) { + monitoringOptions.addAll(nativeMonitoringItems.stream() + .map(NativeMonitoringBuildItem::getOption) + .collect(Collectors.toSet())); + } + if (nativeConfig.monitoring().isPresent()) { monitoringOptions.addAll(nativeConfig.monitoring().get()); } if (!monitoringOptions.isEmpty()) { nativeImageArgs.add("--enable-monitoring=" + monitoringOptions.stream() - .distinct() .map(o -> o.name().toLowerCase(Locale.ROOT)).collect(Collectors.joining(","))); } diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/metric/MetricProcessor.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/metric/MetricProcessor.java index 1224d28e0c2c8..fcc57f9187165 100644 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/metric/MetricProcessor.java +++ b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/metric/MetricProcessor.java @@ -22,7 +22,9 @@ import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.BuildSteps; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; +import io.quarkus.deployment.builditem.NativeMonitoringBuildItem; import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; +import io.quarkus.deployment.pkg.NativeConfig; import io.quarkus.opentelemetry.runtime.config.build.OTelBuildConfig; import io.quarkus.opentelemetry.runtime.metrics.cdi.MetricsProducer; import io.quarkus.opentelemetry.runtime.metrics.instrumentation.JvmMetricsService; @@ -33,6 +35,11 @@ public class MetricProcessor { private static final DotName METRIC_READER = DotName.createSimple(MetricReader.class.getName()); private static final DotName METRIC_PROCESSOR = DotName.createSimple(MetricProcessor.class.getName()); + @BuildStep + void addNativeMonitoring(BuildProducer nativeMonitoring) { + nativeMonitoring.produce(new NativeMonitoringBuildItem(NativeConfig.MonitoringOption.JFR)); + } + @BuildStep UnremovableBeanBuildItem ensureProducersAreRetained( CombinedIndexBuildItem indexBuildItem, diff --git a/integration-tests/opentelemetry/src/main/resources/application.properties b/integration-tests/opentelemetry/src/main/resources/application.properties index 68c3b9664276b..1992d76c95677 100644 --- a/integration-tests/opentelemetry/src/main/resources/application.properties +++ b/integration-tests/opentelemetry/src/main/resources/application.properties @@ -21,4 +21,3 @@ quarkus.security.users.embedded.plain-text=true quarkus.security.users.embedded.enabled=true quarkus.http.auth.basic=true -quarkus.native.monitoring=jfr