Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.8] Backport for 3.8 branch 20.6.2024 #1849

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,13 @@ Module that covers the logging functionality using JBoss Logging Manager. The fo
- Inject a `Logger` instance using a custom category
- Setting up the log level property for logger instances
- Check default `quarkus.log.min-level` value
-
### `logging/thirdparty`

Module that covers, that logging works with various third-party solutions. The following scenarios are covered:
- Check default `quarkus.log.min-level` value
- Syslog-type log (syslog-ng is used)
- Option `quarkus.log.syslog.max-length` filters messages, which are too big

### `sql-db/hibernate`

Expand Down Expand Up @@ -865,7 +872,7 @@ Jaeger is deployed in an "all-in-one" configuration, and the OpenShift test veri
Testing OpenTelemetry with Jaeger components
- Extension `quarkus-opentelemetry` - responsible for traces generation in OpenTelemetry format and export into OpenTelemetry components (opentelemetry-agent, opentelemetry-collector)

Scenarios that test proper traces export to Jaeger components, context propagation, OpenTelemetry SDK Autoconfiguration and CDI injection of OpenTelemetry beans.
Scenarios that test proper traces export to Jaeger components, context propagation, OpenTelemetry SDK Autoconfiguration, OTLP Exporter proxy and CDI injection of OpenTelemetry beans.
See also `monitoring/opentelemetry/README.md`

### `micrometer/prometheus`
Expand Down
19 changes: 19 additions & 0 deletions logging/thirdparty/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus.ts.qe</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>logging-thridparty</artifactId>
<packaging>jar</packaging>
<name>Quarkus QE TS: Logging: Third party</name>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.quarkus.ts.logging.jboss;

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.QueryParam;

import org.jboss.logging.Logger;

import io.quarkus.arc.log.LoggerName;

@Path("/log")
public class LogResource {

public static final String CUSTOM_CATEGORY = "FOO";

private static final Logger LOG = Logger.getLogger(LogResource.class);

@Inject
Logger log;

@LoggerName(CUSTOM_CATEGORY)
Logger customCategoryLog;

@POST
@Path("/static/{level}")
public void addLogMessageInStaticLogger(@PathParam("level") String level, @QueryParam("message") String message) {
addLogMessage(LOG, level, message);
}

@POST
@Path("/field/{level}")
public void addLogMessageInFieldLogger(@PathParam("level") String level, @QueryParam("message") String message) {
addLogMessage(log, level, message);
}

@POST
@Path("/field-with-custom-category/{level}")
public void addLogMessageInFieldWithCustomCategoryLogger(@PathParam("level") String level,
@QueryParam("message") String message) {
addLogMessage(customCategoryLog, level, message);
}

@GET
public void logExample() {
LOG.fatal("Fatal log example");
LOG.error("Error log example");
LOG.warn("Warn log example");
LOG.info("Info log example");
LOG.debug("Debug log example");
LOG.trace("Trace log example");
}

private void addLogMessage(Logger logger, String level, String message) {
logger.log(Logger.Level.valueOf(level.toUpperCase()), message);
}
}
18 changes: 18 additions & 0 deletions logging/thirdparty/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#When you set the logging level below the minimum logging level, you must adjust the minimum logging level as well.
#Otherwise, the value of minimum logging level overrides the logging level.
# DOC:
# https://access.redhat.com/documentation/en-us/red_hat_build_of_quarkus/1.11/html-single/configuring_logging_with_quarkus/index#ref-example-logging-configuration_quarkus-configuring-logging
# https://quarkus.io/guides/logging
# https://quarkus.io/guides/all-config#quarkus-core_quarkus.log.min-level

# By default min-level is set to DEBUG
#quarkus.log.min-level=DEBUG
quarkus.log.level=INFO

%syslog.quarkus.log.syslog.enable=true
%syslog.quarkus.log.syslog.app-name=quarkus
%syslog.quarkus.log.syslog.format=%-5p %s%n
%syslog.quarkus.log.syslog.syslog-type=rfc3164
%syslog.quarkus.log.syslog.protocol=tcp
# the option below is overriden in @QuarkusScenario tests
%syslog.quarkus.log.syslog.endpoint=localhost:1514
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.quarkus.ts.logging.jboss;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.services.Container;
import io.quarkus.test.services.QuarkusApplication;

@QuarkusScenario
public class SyslogIT {

/*
* For manual testing:
* podman run -p 8514:514 \
* -v $(pwd)/src/test/resources/syslog-ng.conf:/etc/syslog-ng/syslog-ng.conf:z --rm -it balabit/syslog-ng
*/
@Container(image = "balabit/syslog-ng", port = 514, expectedLog = "syslog-ng")
static RestService syslog = new RestService()
.withProperty("_ignored", "resource_with_destination::/etc/syslog-ng/|syslog-ng.conf");

@QuarkusApplication
static RestService app = new RestService()
.withProperty("quarkus.profile", "syslog")
.withProperty("quarkus.log.syslog.max-length", "64")
.withProperty("quarkus.log.syslog.endpoint", () -> syslog.getURI().toString());

@Test
public void checkDefaultLogMinLevel() {
app.given().when().get("/log").then().statusCode(204);

syslog.logs().assertContains("Fatal log example");

syslog.logs().assertContains("Error log example");
syslog.logs().assertContains("Warn log example");
syslog.logs().assertContains("Info log example");

// the value of minimum logging level overrides the logging level
syslog.logs().assertDoesNotContain("Debug log example");
syslog.logs().assertDoesNotContain("Trace log example");
}

@Test
@Tag("https://issues.redhat.com/browse/QUARKUS-4531")
public void logBigMessage() {
String shorterMessage = "Relatively long message";
app.given().when()
.post("/log/static/info?message={message}", shorterMessage)
.then().statusCode(204);
syslog.logs().assertContains(shorterMessage);
}

@Test
@Tag("https://issues.redhat.com/browse/QUARKUS-4531")
public void filterBigMessage() {
String longerMessage = "Message, which is very long and is not expected to fit into 64 bytes";
app.given().when()
.post("/log/static/info?message={message}",
longerMessage)
.then().statusCode(204);

syslog.logs().assertDoesNotContain(longerMessage);
}

}
11 changes: 11 additions & 0 deletions logging/thirdparty/src/test/resources/syslog-ng.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@version: 4.4
@include "scl.conf"

log {
source {
#network();
tcp(ip(0.0.0.0) port(514));
};
#destination { file("/var/log/syslog"); };
destination {stdout();};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.quarkus.ts.micrometer.prometheus;

import java.net.URI;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.Response;

@Path("/test")
public class PathPatternResource {
@GET
@Path("/redirect")
public Response redirect() {
return Response.status(Response.Status.FOUND) //302
.location(URI.create("/new-location"))
.build();
}

@GET
@Path("/not-found")
public Response notFound() {
return Response.status(Response.Status.NOT_FOUND).build(); //404
}

@GET
@Path("/not-found/{uri}")
public Response notFoundUri(@PathParam("uri") String uri) {
return Response.status(Response.Status.NOT_FOUND).build(); //404
}

@GET
@Path("/moved/{id}")
public Response moved(@PathParam("id") String id) {
return Response.status(Response.Status.MOVED_PERMANENTLY).build(); // 301
}

@GET
@Path("")
public Response emptyPath() {
return Response.status(Response.Status.NO_CONTENT).build(); //204
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package io.quarkus.ts.micrometer.prometheus;

import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.services.QuarkusApplication;

@Tag("QUARKUS-4430")
@QuarkusScenario
public class HttpPathMetricsPatternIT {

private static final int ASSERT_METRICS_TIMEOUT_SECONDS = 30;
private static final List<String> HTTP_SERVER_REQUESTS_METRICS_SUFFIX = Arrays.asList("count", "sum", "max");
private static final String HTTP_SERVER_REQUESTS_METRICS_FORMAT = "http_server_requests_seconds_%s{method=\"GET\",outcome=\"%s\",status=\"%d\",uri=\"%s\"}";
private static final String REDIRECT_ENDPOINT = "/test/redirect";
private static final String NOT_FOUND_ENDPOINT = "/test/not-found";
private static final String NOT_FOUND_URI_ENDPOINT = "/test/not-found/{uri}";
private static final String MOVED_ENDPOINT = "/test/moved/{id}";
private static final String EMPTY_ENDPOINT = "/test";

@QuarkusApplication
static RestService app = new RestService();

@Test
public void verifyNotFoundInMetrics() {
whenCallNotFoundEndpoint();
thenMetricIsExposedInServiceEndpoint(404, "CLIENT_ERROR", "NOT_FOUND");
}

@Test
public void verifyUriNotFoundInMetrics() {
whenCallNotFoundWithParamEndpoint("/url123");
thenMetricIsExposedInServiceEndpoint(404, "CLIENT_ERROR", NOT_FOUND_URI_ENDPOINT);
}

@Test
public void verifyRedirectionInMetrtics() {
whenCallRedirectEndpoint();
thenMetricIsExposedInServiceEndpoint(302, "REDIRECTION", "REDIRECTION");
}

@Test
public void verifyEmptyPathInMetrics() {
whenCallEmptyPathEndpoint();
thenMetricIsExposedInServiceEndpoint(204, "SUCCESS", EMPTY_ENDPOINT);
}

@Test
public void verifyDynamicRedirectionInMetrics() {
String id = "41";
whenCallDynamicSegmentEndpoint(id);
thenMetricIsExposedInServiceEndpoint(301, "REDIRECTION", MOVED_ENDPOINT);
}

private void whenCallRedirectEndpoint() {
given()
.redirects().follow(false)
.when().get(REDIRECT_ENDPOINT)
.then().statusCode(302);
}

private void whenCallEmptyPathEndpoint() {
given()
.when().get("/test")
.then().statusCode(HttpStatus.SC_NO_CONTENT);
}

private void whenCallNotFoundEndpoint() {
given()
.when().get(NOT_FOUND_ENDPOINT)
.then().statusCode(HttpStatus.SC_NOT_FOUND);
}

private void whenCallNotFoundWithParamEndpoint(String url) {
given()
.pathParam("uri", url)
.redirects().follow(false)
.when().get(NOT_FOUND_URI_ENDPOINT)
.then().statusCode(HttpStatus.SC_NOT_FOUND);
}

private void whenCallDynamicSegmentEndpoint(String id) {
given()
.pathParam("id", id)
.redirects().follow(false)
.when().get(MOVED_ENDPOINT)
.then().statusCode(HttpStatus.SC_MOVED_PERMANENTLY);
}

private void thenMetricIsExposedInServiceEndpoint(int statusCode, String outcome, String uri) {
await().ignoreExceptions().atMost(ASSERT_METRICS_TIMEOUT_SECONDS, TimeUnit.SECONDS).untilAsserted(() -> {
String metrics = app.given().get("/q/metrics").then()
.statusCode(HttpStatus.SC_OK).extract().asString();
for (String metricSuffix : HTTP_SERVER_REQUESTS_METRICS_SUFFIX) {
String metric = String.format(HTTP_SERVER_REQUESTS_METRICS_FORMAT, metricSuffix, outcome, statusCode, uri);

assertTrue(metrics.contains(metric), "Expected metric : " + metric + ". Metrics: " + metrics);
}
});
}

}
15 changes: 15 additions & 0 deletions monitoring/opentelemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@
<artifactId>quarkus-test-service-jaeger</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-grpc-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-grpc-client</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Loading