Skip to content

Commit

Permalink
Merge pull request quarkusio#38448 from alesj/obs_lgtm
Browse files Browse the repository at this point in the history
Initial Observability extension - devservices, devresources, LGTM
  • Loading branch information
brunobat authored Apr 19, 2024
2 parents dd3cd23 + 796348d commit b98e608
Show file tree
Hide file tree
Showing 62 changed files with 2,631 additions and 5 deletions.
50 changes: 50 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@
<mutiny-zero.version>1.1.0</mutiny-zero.version>
<pulsar-client.version>3.0.0</pulsar-client.version>
<async-http-client.version>2.12.3</async-http-client.version>
<!-- keep in-sync, if possible, with Micrometer registry Prometheus -->
<prometheus.version>0.16.0</prometheus.version>
<!-- Dev UI -->
<importmap.version>1.0.10</importmap.version>
</properties>
Expand Down Expand Up @@ -490,6 +492,18 @@
<scope>import</scope>
</dependency>

<!-- Prometheus -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>${prometheus.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_common</artifactId>
<version>${prometheus.version}</version>
</dependency>

<!-- Quarkus core -->

<dependency>
Expand Down Expand Up @@ -2991,6 +3005,42 @@
<artifactId>quarkus-virtual-threads-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devservices-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devservices</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devservices-lgtm</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-testcontainers</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devresource-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devresource-testcontainers</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devresource-lgtm</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Quarkus test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public enum Feature {
NARAYANA_LRA,
NARAYANA_STM,
NEO4J,
OBSERVABILITY,
OIDC,
OIDC_CLIENT,
RESTEASY_CLIENT_OIDC_FILTER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Closeable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiPredicate;
Expand All @@ -26,18 +27,28 @@ public class StartupLogCompressor implements Closeable, BiPredicate<String, Bool
final List<String> toDump = new ArrayList<>();
final AtomicInteger COUNTER = new AtomicInteger();
final Predicate<Thread> additionalThreadPredicate;
final Predicate<String> linePredicate; // test if we always print the line / log

public StartupLogCompressor(String name,
@SuppressWarnings("unused") Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem,
@SuppressWarnings("unused") LoggingSetupBuildItem loggingSetupBuildItem) {
this(name, consoleInstalledBuildItem, loggingSetupBuildItem, (s) -> false);
this(name, consoleInstalledBuildItem, loggingSetupBuildItem, s -> false);
}

public StartupLogCompressor(String name,
@SuppressWarnings("unused") Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem,
@SuppressWarnings("unused") LoggingSetupBuildItem loggingSetupBuildItem,
Predicate<Thread> additionalThreadPredicate) {
this.additionalThreadPredicate = additionalThreadPredicate;
this(name, consoleInstalledBuildItem, loggingSetupBuildItem, additionalThreadPredicate, s -> false);
}

public StartupLogCompressor(String name,
@SuppressWarnings("unused") Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem,
@SuppressWarnings("unused") LoggingSetupBuildItem loggingSetupBuildItem,
Predicate<Thread> additionalThreadPredicate,
Predicate<String> linePredicate) {
this.additionalThreadPredicate = Objects.requireNonNull(additionalThreadPredicate);
this.linePredicate = Objects.requireNonNull(linePredicate);
if (QuarkusConsole.INSTANCE.isAnsiSupported()) {
QuarkusConsole.installRedirects();
this.name = name;
Expand Down Expand Up @@ -74,8 +85,8 @@ public void closeAndDumpCaptured() {

@Override
public boolean test(String s, Boolean errorStream) {
if (thread == null) {
//not installed
if (thread == null || linePredicate.test(s)) {
//not installed or line predicate tested to true
return true;
}
Thread current = Thread.currentThread();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.quarkus.runtime.util;

import java.util.Enumeration;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.stream.Stream;

/**
* Transform to "old school" Enumeration from Iterator/Spliterator/Stream
*/
public class EnumerationUtil {
public static <T> Enumeration<T> from(Iterator<T> iterator) {
Objects.requireNonNull(iterator);

return new Enumeration<T>() {
@Override
public boolean hasMoreElements() {
return iterator.hasNext();
}

@Override
public T nextElement() {
return iterator.next();
}
};
}

public static <T> Enumeration<T> from(Spliterator<T> spliterator) {
Objects.requireNonNull(spliterator);

class Adapter implements Enumeration<T>, Consumer<T> {
boolean valueReady;
T nextElement;

public void accept(T t) {
this.valueReady = true;
this.nextElement = t;
}

public boolean hasMoreElements() {
if (!this.valueReady) {
spliterator.tryAdvance(this);
}

return this.valueReady;
}

public T nextElement() {
if (!this.valueReady && !this.hasMoreElements()) {
throw new NoSuchElementException();
} else {
this.valueReady = false;
T t = this.nextElement;
this.nextElement = null;
return t;
}
}
}

return new Adapter();
}

public static <T> Enumeration<T> from(Stream<T> stream) {
return from(stream.spliterator());
}
}
13 changes: 13 additions & 0 deletions devtools/bom-descriptor-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devservices</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-observability-devservices-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc-deployment</artifactId>
Expand Down
8 changes: 8 additions & 0 deletions docs/src/main/asciidoc/dev-services.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ More information can be found in the xref:elasticsearch-dev-services.adoc[Elasti

include::{generated-dir}/config/quarkus-elasticsearch-devservices-elasticsearch-dev-services-build-time-config.adoc[opts=optional, leveloffset=+1]

=== Observability

The Observability Dev Services will be enabled when the `quarkus-observability-devservices` extension is present in your application, and
there is at least one dev resource on the classpath. More information can be found in the
xref:observability-devservices.adoc[Observability Dev Services Guide].

include::{generated-dir}/config/quarkus-observability-config-observability-configuration.adoc[opts=optional, leveloffset=+1]

== Dev Services beyond the Quarkus Platform

Many Quarkiverse extensions which are not in the Quarkus Platform also offer Dev Services.
Expand Down
Loading

0 comments on commit b98e608

Please sign in to comment.