Skip to content

Commit

Permalink
Merge pull request #23494 from gsmet/2.7.1-backports-4
Browse files Browse the repository at this point in the history
2.7.1 backports 4
  • Loading branch information
gsmet authored Feb 8, 2022
2 parents 5c94181 + cd20197 commit bf67d84
Show file tree
Hide file tree
Showing 24 changed files with 830 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void run() {
}
}, "Console Shutdown Hook"));
prompt = registerStatusLine(0);

}

private void updatePromptOnChange(StringBuilder buffer, int newLines) {
Expand Down Expand Up @@ -222,6 +223,26 @@ public void run() {
});
// Keyboard handling
conn.setStdinHandler(keys -> {

QuarkusConsole.StateChangeInputStream redirectIn = QuarkusConsole.REDIRECT_IN;
//see if the users application wants to read the keystrokes:
int pos = 0;
while (pos < keys.length) {
if (!redirectIn.acceptInput(keys[pos])) {
break;
}
++pos;
}
if (pos > 0) {
if (pos == keys.length) {
return;
}
//the app only consumed some keys
//stick the rest in a new array
int[] newKeys = new int[keys.length - pos];
System.arraycopy(keys, pos, newKeys, 0, newKeys.length);
keys = newKeys;
}
try {
if (delegateConnection != null) {
//console mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ public void accept(Connection connection) {
connection.setStdinHandler(new Consumer<int[]>() {
@Override
public void accept(int[] ints) {
QuarkusConsole.StateChangeInputStream redirectIn = QuarkusConsole.REDIRECT_IN;
for (int i : ints) {
queue.add(i);
if (redirectIn != null && !redirectIn.acceptInput(i)) {
queue.add(i);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.quarkus.dev.console;

import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.PrintStream;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.function.BiPredicate;
import java.util.function.Consumer;

Expand Down Expand Up @@ -52,9 +56,12 @@ public abstract class QuarkusConsole {

public final static PrintStream ORIGINAL_OUT = System.out;
public final static PrintStream ORIGINAL_ERR = System.err;
public final static InputStream ORIGINAL_IN = System.in;

public static PrintStream REDIRECT_OUT = null;
public static PrintStream REDIRECT_ERR = null;
public static StateChangeInputStream REDIRECT_IN;
protected volatile boolean userReadInProgress;

public synchronized static void installRedirects() {
if (redirectsInstalled) {
Expand All @@ -67,8 +74,10 @@ public synchronized static void installRedirects() {
QuarkusConsole.INSTANCE.isInputSupported();
REDIRECT_OUT = new RedirectPrintStream(false);
REDIRECT_ERR = new RedirectPrintStream(true);
REDIRECT_IN = new StateChangeInputStream();
System.setOut(REDIRECT_OUT);
System.setErr(REDIRECT_ERR);
System.setIn(REDIRECT_IN);
}

public synchronized static void uninstallRedirects() {
Expand All @@ -86,8 +95,10 @@ public synchronized static void uninstallRedirects() {
REDIRECT_ERR.close();
REDIRECT_ERR = null;
}
REDIRECT_IN = null;
System.setOut(ORIGINAL_OUT);
System.setErr(ORIGINAL_ERR);
System.setIn(ORIGINAL_IN);

redirectsInstalled = false;
}
Expand Down Expand Up @@ -176,4 +187,69 @@ public boolean isAnsiSupported() {
return false;
}

protected void userReadStart() {

}

protected void userReadStop() {

}

public static class StateChangeInputStream extends InputStream {

private final LinkedBlockingDeque<Integer> queue = new LinkedBlockingDeque<>();

private volatile boolean reading;

public synchronized boolean acceptInput(int input) {
if (reading) {
queue.add(input);
notifyAll();
return true;
}
return false;
}

@Override
public synchronized int read() throws IOException {
reading = true;
try {
while (queue.isEmpty()) {
try {
wait();
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
}
return queue.pollFirst();
} finally {
reading = false;
}
}

@Override
public synchronized int read(byte[] b, int off, int len) throws IOException {
reading = true;
int read = 0;
try {
while (read < len) {
while (queue.isEmpty()) {
try {
wait();
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
}
byte byteValue = queue.poll().byteValue();
b[read++] = byteValue;
if (byteValue == '\n' || byteValue == '\r') {
return read;
}
}
return read;
} finally {
reading = false;
}
}
}
}
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/container-image.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ or for native:

[source,properties]
----
quarkus.buildpack.jvm-builder-image=<native builder image>
quarkus.buildpack.native-builder-image=<native builder image>
----

To use this feature, add the following extension to your project.
Expand Down
4 changes: 4 additions & 0 deletions docs/src/main/asciidoc/includes/devtools/prerequisites.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ endif::[]
* An IDE
ifdef::prerequisites-ide[{prerequisites-ide}]
* JDK 11+ installed with `JAVA_HOME` configured appropriately
ifndef::prerequisites-no-maven[]
* Apache Maven {maven-version}
endif::[]
ifdef::prerequisites-docker[]
* A working container runtime (Docker or Podman)
endif::[]
ifdef::prerequisites-docker-compose[]
* Docker and Docker Compose
endif::[]
ifndef::prerequisites-no-cli[]
* Optionally the xref:cli-tooling.adoc[Quarkus CLI] if you want to use it
endif::[]
ifndef::prerequisites-no-graalvm[]
ifndef::prerequisites-graalvm-mandatory[]
* Optionally Mandrel or GraalVM installed and xref:building-native-image.adoc#configuring-graalvm[configured appropriately] if you want to build a native executable (or Docker if you use a native container build)
Expand Down
76 changes: 39 additions & 37 deletions docs/src/main/asciidoc/opentelemetry.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ distributed tracing for interactive web applications.

== Prerequisites

To complete this guide, you need:

* less than 15 minutes
* an IDE
* JDK 11+ installed with `JAVA_HOME` configured appropriately
* Apache Maven {maven-version}
* Docker


:prerequisites-docker-compose:
include::includes/devtools/prerequisites.adoc[]

== Architecture

Expand All @@ -39,42 +32,40 @@ The solution is located in the `opentelemetry-quickstart` {quickstarts-tree-url}

First, we need a new project. Create a new project with the following command:

[source,bash,subs=attributes+]
----
mvn io.quarkus.platform:quarkus-maven-plugin:{quarkus-version}:create \
-DprojectGroupId=org.acme \
-DprojectArtifactId=opentelemetry-quickstart \
-DclassName="org.acme.opentelemetry.TracedResource" \
-Dpath="/hello" \
-Dextensions="resteasy,quarkus-opentelemetry-exporter-otlp"
cd opentelemetry-quickstart
----
:create-app-artifact-id: opentelemetry-quickstart
:create-app-extensions: resteasy,quarkus-opentelemetry-exporter-otlp
include::includes/devtools/create-app.adoc[]

This command generates the Maven project with a REST endpoint and imports the `quarkus-opentelemetry-exporter-otlp` extension,
This command generates the Maven project and imports the `quarkus-opentelemetry-exporter-otlp` extension,
which includes the OpenTelemetry support,
and a gRPC span exporter for https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md[OTLP].

If you already have your Quarkus project configured, you can add the `quarkus-opentelemetry-exporter-otlp` extension
to your project by running the following command in your project base directory:

[source,bash]
----
./mvnw quarkus:add-extension -Dextensions="opentelemetry-otlp-exporter"
----
:add-extension-extensions: opentelemetry-otlp-exporter
include::includes/devtools/extension-add.adoc[]

This will add the following to your `pom.xml`:
This will add the following to your build file:

[source,xml]
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-exporter-otlp</artifactId>
</dependency>
----

[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
implementation("io.quarkus:quarkus-opentelemetry-exporter-otlp")
----

=== Examine the JAX-RS resource

Open the `src/main/java/org/acme/opentelemetry/TracedResource.java` file and see the following content:
Create a `src/main/java/org/acme/opentelemetry/TracedResource.java` file with the following content:

[source,java]
----
Expand Down Expand Up @@ -194,17 +185,13 @@ services:

Now we are ready to run our application. If using `application.properties` to configure the tracer:

[source,bash]
----
./mvnw compile quarkus:dev
----
include::includes/devtools/dev.adoc[]

or if configuring the OTLP gRPC endpoint via JVM arguments:

[source,bash]
----
./mvnw compile quarkus:dev -Djvm.args="-Dquarkus.opentelemetry.tracer.exporter.otlp.endpoint=http://localhost:55680"
----
:dev-additional-parameters: -Djvm.args="-Dquarkus.opentelemetry.tracer.exporter.otlp.endpoint=http://localhost:55680"
include::includes/devtools/dev.adoc[]
:!dev-additional-parameters:

With the OpenTelemetry Collector, Jaeger system and application running, you can make a request to the provided endpoint:

Expand Down Expand Up @@ -255,22 +242,37 @@ propagators, you can however choose any of the supported OpenTelemetry propagato
The `b3`, `b3multi`, `jaeger` and `ottrace` propagators will need the https://github.com/open-telemetry/opentelemetry-java/tree/main/extensions/trace-propagators[trace-propagators]
extension to be added as a dependency to your project.
[source,xml]
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-extension-trace-propagators</artifactId>
</dependency>
----
[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
implementation("io.opentelemetry:opentelemetry-extension-trace-propagators")
----
The `xray` propagator will need the https://github.com/open-telemetry/opentelemetry-java/tree/main/extensions/aws[aws] extension to be added as a dependency to your project.
[source,xml]
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-extension-aws</artifactId>
</dependency>
----
[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
implementation("io.opentelemetry:opentelemetry-extension-aws")
----
====

=== Resource
Expand Down
Loading

0 comments on commit bf67d84

Please sign in to comment.