Skip to content

Commit

Permalink
Initial Observability extension - devservices, devresources, LGTM
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed Jan 29, 2024
1 parent 391ca5a commit 002fbba
Show file tree
Hide file tree
Showing 55 changed files with 2,045 additions and 17 deletions.
Binary file removed .idea/icon.png
Binary file not shown.
Binary file removed .idea/icon_dark.png
Binary file not shown.
15 changes: 0 additions & 15 deletions .idea/runConfigurations/mvnDebug.xml

This file was deleted.

44 changes: 44 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.0.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 @@ -481,6 +483,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 @@ -2962,6 +2976,36 @@
<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>
</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-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 @@ -68,6 +68,7 @@ public enum Feature {
NARAYANA_LRA,
NARAYANA_STM,
NEO4J,
OBSERVABILITY,
OIDC,
OIDC_CLIENT,
OIDC_CLIENT_FILTER,
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 @@ -1526,6 +1526,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 @@ -1542,6 +1542,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
4 changes: 2 additions & 2 deletions docs/src/main/asciidoc/validation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public class BookResource {
----
<1> The `Validator` instance is injected via CDI.

Yes it does not compile, `Result` is missing, but we will add it very soon.
Yes it does not compile, `QueryResult` is missing, but we will add it very soon.

The method parameter (`book`) is created from the JSON payload automatically.

Expand All @@ -139,7 +139,7 @@ It returns a set of violations.
If this set is empty, it means the object is valid.
In case of failures, the messages are concatenated and sent back to the browser.

Let's now create the `Result` class as an inner class:
Let's now create the `QueryResult` class as an inner class:

[source, java]
----
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.quarkus.devservices.common;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;

import org.jboss.logging.Logger;
Expand Down Expand Up @@ -61,6 +63,30 @@ public Optional<ContainerAddress> locateContainer(String serviceName, boolean sh
}
}

/**
* @return container id, if exists
*/
public Optional<String> locateContainer(String serviceName, boolean shared, LaunchMode launchMode,
BiConsumer<Integer, ContainerAddress> consumer) {
if (shared && launchMode == LaunchMode.DEVELOPMENT) {
return lookup(serviceName)
.map(container -> {
Arrays.stream(container.getPorts())
.filter(cp -> Objects.nonNull(cp.getPublicPort()) && Objects.nonNull(cp.getPrivatePort()))
.forEach(cp -> {
ContainerAddress containerAddress = new ContainerAddress(
container.getId(),
DockerClientFactory.instance().dockerHostIpAddress(),
cp.getPublicPort());
consumer.accept(cp.getPrivatePort(), containerAddress);
});
return container.getId();
});
} else {
return Optional.empty();
}
}

public Optional<Integer> locatePublicPort(String serviceName, boolean shared, LaunchMode launchMode, int privatePort) {
if (shared && launchMode == LaunchMode.DEVELOPMENT) {
return lookup(serviceName)
Expand Down
27 changes: 27 additions & 0 deletions extensions/observability-devservices/common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>quarkus-observability-devservices-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>quarkus-observability-devservices-common</artifactId>
<name>Quarkus - Observability Devservices - Common</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-core</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.observability.common;

public final class ContainerConstants {

// Images

public static final String LGTM = "docker.io/grafana/otel-lgtm:0.2.0";

// Ports

public static final int GRAFANA_PORT = 3000;

public static final int OTEL_GRPC_EXPORTER_PORT = 4317;
public static final int OTEL_HTTP_EXPORTER_PORT = 4318;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.quarkus.observability.common.config;

import java.util.Locale;
import java.util.Optional;
import java.util.Set;

public abstract class AbstractContainerConfig implements ContainerConfig {

private final String imageName;
private final boolean shared;

public AbstractContainerConfig(String imageName) {
this(imageName, true);
}

public AbstractContainerConfig(String imageName, boolean shared) {
this.imageName = imageName;
this.shared = shared;
}

@Override
public boolean enabled() {
return true;
}

@Override
public String imageName() {
return imageName;
}

@Override
public boolean shared() {
return shared;
}

@Override
public Optional<Set<String>> networkAliases() {
return Optional.empty();
}

@Override
public String label() {
String sn = getClass().getSimpleName().toLowerCase(Locale.ROOT);
return "quarkus-dev-resource-" + sn;
}

@Override
public String serviceName() {
return "quarkus";
}
}
Loading

0 comments on commit 002fbba

Please sign in to comment.