Skip to content

Commit

Permalink
Merge pull request #22752 from gsmet/2.6.2-backports-2
Browse files Browse the repository at this point in the history
2.6.2 backports 2
  • Loading branch information
gsmet authored Jan 9, 2022
2 parents 10c72be + f60dc73 commit a24bf61
Show file tree
Hide file tree
Showing 20 changed files with 252 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.quarkus.deployment;

import org.objectweb.asm.ClassVisitor;

/**
* A subclass of {@link ClassVisitor} that allows carrying around data
* that are useful in the context of Quarkus bytecode transformations.
* Class visitors that require access to these data should extend this class.
*/
public abstract class QuarkusClassVisitor extends ClassVisitor {
public QuarkusClassVisitor(int api) {
super(api);
}

public QuarkusClassVisitor(int api, ClassVisitor classVisitor) {
super(api, classVisitor);
}

// ---

// this could possibly be a Map<String, Object> or something like that,
// but there's no need at the moment
private int originalClassReaderOptions;

public int getOriginalClassReaderOptions() {
return originalClassReaderOptions;
}

public void setOriginalClassReaderOptions(int originalClassReaderOptions) {
this.originalClassReaderOptions = originalClassReaderOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.quarkus.bootstrap.BootstrapDebug;
import io.quarkus.bootstrap.classloading.ClassPathElement;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.QuarkusClassVisitor;
import io.quarkus.deployment.QuarkusClassWriter;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
Expand Down Expand Up @@ -313,6 +314,9 @@ private byte[] transformClass(String className, List<BiFunction<String, ClassVis
ClassVisitor visitor = writer;
for (BiFunction<String, ClassVisitor, ClassVisitor> i : visitors) {
visitor = i.apply(className, visitor);
if (visitor instanceof QuarkusClassVisitor) {
((QuarkusClassVisitor) visitor).setOriginalClassReaderOptions(classReaderOptions);
}
}
cr.accept(visitor, classReaderOptions);
data = writer.toByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -253,12 +255,13 @@ public void watchConfigFiles(BuildProducer<HotDeploymentWatchedFileBuildItem> wa
configWatchedFiles.add(
Paths.get(userDir, "config", String.format("application-%s.properties", profile)).toAbsolutePath().toString());

Optional<List<String>> optionalLocations = config.getOptionalValues(SMALLRYE_CONFIG_LOCATIONS, String.class);
Optional<List<URI>> optionalLocations = config.getOptionalValues(SMALLRYE_CONFIG_LOCATIONS, URI.class);
optionalLocations.ifPresent(locations -> {
for (String location : locations) {
if (!Files.isDirectory(Paths.get(location))) {
configWatchedFiles.add(location);
configWatchedFiles.add(appendProfileToFilename(location, profile));
for (URI location : locations) {
Path path = location.getScheme() != null ? Paths.get(location) : Paths.get(location.getPath());
if (!Files.isDirectory(path)) {
configWatchedFiles.add(location.toString());
configWatchedFiles.add(appendProfileToFilename(location.toString(), profile));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.runtime;

import java.net.URI;
import java.util.List;
import java.util.Optional;

Expand All @@ -21,7 +22,7 @@ public class ConfigConfig {
* separated by a comma and each must represent a valid {@link java.net.URI}.
*/
@ConfigItem(name = "config.locations")
public Optional<List<String>> locations;
public Optional<List<URI>> locations;

/**
* Accepts a single configuration profile name. If a configuration property cannot be found in the current active
Expand Down
19 changes: 8 additions & 11 deletions devtools/cli/src/main/java/io/quarkus/cli/RegistryAddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ public Integer call() throws Exception {
existingConfig = Files.exists(configYaml);
}

registryClient.refreshRegistryCache(output);
final RegistriesConfig.Mutable config;
if (existingConfig) {
registryClient.refreshRegistryCache(output);
config = registryClient.resolveConfig().mutable();
if (config.getSource().getFilePath() == null) {
output.error("Can only modify file-based configuration. Config source is " + config.getSource().describe());
return CommandLine.ExitCode.SOFTWARE;
}
} else {
if (configYaml != null && !existingConfig) {
// we're creating a new configuration for a new file
config = RegistriesConfig.builder();
} else {
config = registryClient.resolveConfig().mutable();
}

boolean persist = false;
Expand All @@ -48,10 +45,10 @@ public Integer call() throws Exception {
}

if (persist) {
if (existingConfig) {
config.persist();
} else {
if (configYaml != null) {
config.persist(configYaml);
} else {
config.persist();
}
}
return CommandLine.ExitCode.OK;
Expand Down
3 changes: 2 additions & 1 deletion docs/src/main/asciidoc/kogito-dmn.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ First, we need a new project. Create a new project with the following command:
mvn io.quarkus.platform:quarkus-maven-plugin:{quarkus-version}:create \
-DprojectGroupId=org.acme \
-DprojectArtifactId=kogito-dmn-quickstart \
-Dextensions="dmn" \
-Dextensions="dmn,resteasy-jackson" \
-DnoExamples
cd kogito-dmn-quickstart
----

This command generates a Maven project, importing the `kogito-quarkus-decisions` extension
that comes with all needed dependencies and configuration to equip your application
with business automation.
It also imports the `resteasy-jackson` extension that is needed for Kogito to expose REST services.

The `kogito-quarkus-decisions` is a specialized extension of the Kogito project focusing only on DMN support; if you want to
make use of the full capabilities offered by the Kogito platform, you can reference the generic Kogito extension of Quarkus.
Expand Down
3 changes: 2 additions & 1 deletion docs/src/main/asciidoc/kogito-drl.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ First, we need a new project. Create a new project with the following command:
mvn io.quarkus.platform:quarkus-maven-plugin:{quarkus-version}:create \
-DprojectGroupId=org.acme \
-DprojectArtifactId=kogito-drl-quickstart \
-Dextensions="kogito-quarkus-rules" \
-Dextensions="kogito-quarkus-rules,resteasy-jackson" \
-DnoExamples
cd kogito-drl-quickstart
----

This command generates a Maven project, importing the `kogito-quarkus-rules` extension
that comes with all needed dependencies and configuration to equip your application
with business automation.
It also imports the `resteasy-jackson` extension that is needed for Kogito to expose REST services.

If you already have your Quarkus project configured, you can add the `kogito-quarkus-rules` extension
to your project by running the following command in your project base directory:
Expand Down
3 changes: 2 additions & 1 deletion docs/src/main/asciidoc/kogito-pmml.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ First, we need a new project. Create a new project with the following command:
mvn io.quarkus.platform:quarkus-maven-plugin:{quarkus-version}:create \
-DprojectGroupId=org.acme \
-DprojectArtifactId=kogito-pmml-quickstart \
-Dextensions="kogito" \
-Dextensions="kogito,resteasy-jackson" \
-DnoExamples
cd kogito-pmml-quickstart
----

This command generates a Maven project, importing the `kogito` extension
that comes with all needed dependencies and configuration to equip your application
with business automation.
It also imports the `resteasy-jackson` extension that is needed for Kogito to expose REST services.

If you already have your Quarkus project configured, you can add the `kogito` extension
to your project by running the following command in your project base directory:
Expand Down
3 changes: 2 additions & 1 deletion docs/src/main/asciidoc/kogito.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ First, we need a new project. Create a new project with the following command:
mvn io.quarkus.platform:quarkus-maven-plugin:{quarkus-version}:create \
-DprojectGroupId=org.acme \
-DprojectArtifactId=kogito-quickstart \
-Dextensions="kogito" \
-Dextensions="kogito,resteasy-jackson" \
-DnoExamples
cd kogito-quickstart
----

This command generates a Maven project, importing the `kogito` extension
that comes with all needed dependencies and configuration to equip your application
with business automation.
It also imports the `resteasy-jackson` extension that is needed for Kogito to expose REST services.

If you already have your Quarkus project configured, you can add the `kogito` extension
to your project by running the following command in your project base directory:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;

import io.quarkus.deployment.QuarkusClassVisitor;
import io.quarkus.deployment.QuarkusClassWriter;
import io.quarkus.gizmo.Gizmo;
import net.bytebuddy.ClassFileVersion;
Expand All @@ -36,7 +37,7 @@ public ClassVisitor apply(String className, ClassVisitor outputClassVisitor) {
return new HibernateEnhancingClassVisitor(className, outputClassVisitor);
}

private static class HibernateEnhancingClassVisitor extends ClassVisitor {
private static class HibernateEnhancingClassVisitor extends QuarkusClassVisitor {

private final String className;
private final ClassVisitor outputClassVisitor;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void visitEnd() {
final byte[] transformedBytes = hibernateEnhancement(className, inputBytes);
//Then re-convert the transformed bytecode to not interrupt the visitor chain:
ClassReader cr = new ClassReader(transformedBytes);
cr.accept(outputClassVisitor, 0);
cr.accept(outputClassVisitor, super.getOriginalClassReaderOptions());
}

private byte[] hibernateEnhancement(final String className, final byte[] originalBytes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.quarkus.opentelemetry.deployment;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

import javax.inject.Inject;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class NonAppEndpointsDisabledWithRootPathTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClass(TracerRouter.class)
.addClass(TestSpanExporter.class))
.overrideConfigKey("quarkus.http.root-path", "/app")
.overrideConfigKey("quarkus.http.non-application-root-path", "quarkus");

@Inject
TestSpanExporter testSpanExporter;

@Test
void testHealthEndpointNotTraced() {
RestAssured.when().get("/quarkus/health").then()
.statusCode(200)
.body(containsString("\"status\": \"UP\""));

RestAssured.when().get("/quarkus/health/live").then()
.statusCode(200)
.body(containsString("\"status\": \"UP\""));

RestAssured.when().get("/quarkus/health/ready").then()
.statusCode(200)
.body(containsString("\"status\": \"UP\""));

RestAssured.when().get("/tracer").then()
.statusCode(200)
.body(is("Hello Tracer!"));

testSpanExporter.assertSpanCount(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,47 @@

import java.util.List;

import org.eclipse.microprofile.config.ConfigProvider;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.trace.data.LinkData;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
import io.quarkus.runtime.configuration.NormalizeRootHttpPathConverter;
import io.smallrye.config.SmallRyeConfig;

public class NonApplicationEndpointSampler implements Sampler {
private static final SamplingResult NEGATIVE_SAMPLING_RESULT = SamplingResult.create(SamplingDecision.DROP);

private final Sampler root;
private final Sampler sampler;
private final String namePattern;

public NonApplicationEndpointSampler(Sampler sampler) {
this.sampler = sampler;

public NonApplicationEndpointSampler(Sampler root) {
this.root = root;
// We don't use the HttpBuildTimeConfig because we don't want to add a dependency to vertx-http and vertx-http
// may not even be available.
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
if (config.isPropertyPresent("quarkus.http.root-path")) {
String rootPath = config.getValue("quarkus.http.root-path", new NormalizeRootHttpPathConverter());
String nonApplicationRootPath = config.getRawValue("quarkus.http.non-application-root-path");
// span names don't include the leading slash
this.namePattern = rootPath.substring(1) + nonApplicationRootPath;
} else {
this.namePattern = null;
}
}

@Override
public SamplingResult shouldSample(Context parentContext, String traceId, String name, SpanKind spanKind,
Attributes attributes, List<LinkData> parentLinks) {
if (name.startsWith("q/") && spanKind == SpanKind.SERVER) {
if (namePattern != null && name.startsWith(namePattern) && spanKind == SpanKind.SERVER) {
return NEGATIVE_SAMPLING_RESULT;
}
return root.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks);
return sampler.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks);
}

@Override
Expand Down
Loading

0 comments on commit a24bf61

Please sign in to comment.