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

Quarkus logging #2171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.jboss.logging.Logger;

import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down Expand Up @@ -38,17 +37,4 @@ public PersistentLog(int level, String message) {
this.timestamp = Instant.now();
}

public static Logger.Level logLevel(int level) {
switch (level) {
case DEBUG:
return Logger.Level.DEBUG;
case INFO:
return Logger.Level.INFO;
case WARN:
return Logger.Level.WARN;
case ERROR:
default:
return Logger.Level.ERROR;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ public Uni<String> execute(JsonNode config, JsonNode secrets, Object payload) {
return post(path, secrets, JsonNodeFactory.instance.objectNode().put("body", comment))
.onItem().transformToUni(response -> {
if (response.statusCode() < 400) {
return Uni.createFrom()
.item(String.format("Successfully(%d) added comment to %s", response.statusCode(), path));
return Uni.createFrom().item("Successfully(" + response.statusCode() + ") added comment to " + path);
} else if (response.statusCode() == 403 && response.getHeader("Retry-After") != null) {
return retry(response, config, secrets, payload);

} else {
return Uni.createFrom().failure(new RuntimeException(
String.format("Failed to add comment to %s, response %d: %s",
path, response.statusCode(), response.bodyAsString())));
String message = "Failed to add comment to " + path + ", response" + response.statusCode() + ":\n"
+ response.bodyAsString();
return Uni.createFrom().failure(new RuntimeException(message));
}
}).onFailure().transform(t -> new RuntimeException("Failed to add comment to " + path + ": " + t.getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ public Uni<String> execute(JsonNode config, JsonNode secrets, Object payload) {
.put("title", title).put("body", body).set("labels", JsonNodeFactory.instance.arrayNode().add("horreum")))
.onItem().transformToUni(response -> {
if (response.statusCode() < 400) {
return Uni.createFrom()
.item(String.format("Successfully(%d) created issue in %s", response.statusCode(), path));
return Uni.createFrom().item("Successfully(" + response.statusCode() + ") created issue in " + path);
} else if (response.statusCode() == 403 && response.getHeader("Retry-After") != null) {
return retry(response, config, secrets, payload);
} else {
return Uni.createFrom().failure(new RuntimeException(
String.format("Failed to create issue in %s, response %d: %s",
path, response.statusCode(), response.bodyAsString())));
String message = "Failed to create issue in " + path + ", response" + response.statusCode() + ":\n"
+ response.bodyAsString();
return Uni.createFrom().failure(new RuntimeException(message));
}
}).onFailure()
.transform(t -> new RuntimeException("Failed to create issue in " + path + ": " + t.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;

import org.jboss.logging.Logger;

import com.fasterxml.jackson.databind.JsonNode;

import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.RequestOptions;
Expand All @@ -17,7 +16,6 @@
import io.vertx.mutiny.ext.web.client.HttpResponse;

public abstract class GitHubPluginBase {
protected static final Logger log = Logger.getLogger(GitHubPluginBase.class);

@Inject
Vertx vertx;
Expand Down Expand Up @@ -62,7 +60,7 @@ protected Uni<HttpResponse<Buffer>> post(String path, JsonNode secrets, JsonNode

protected Uni<String> retry(HttpResponse<Buffer> response, JsonNode config, JsonNode secrets, Object payload) {
int retryAfter = Integer.parseInt(response.getHeader("Retry-After"));
log.warnf("Exceeded Github request limits, retrying after %d seconds", retryAfter);
Log.warnf("Exceeded Github request limits, retrying after %d seconds", retryAfter);
return Uni.createFrom()
.emitter(em -> vertx.setTimer(TimeUnit.SECONDS.toMillis(retryAfter), id -> execute(config, secrets, payload)
.subscribe().with(em::complete, em::fail)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import jakarta.inject.Inject;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;

import com.fasterxml.jackson.databind.JsonNode;

import io.hyperfoil.tools.horreum.entity.data.AllowedSiteDAO;
import io.hyperfoil.tools.horreum.svc.ServiceException;
import io.hyperfoil.tools.horreum.svc.Util;
import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpVersion;
Expand All @@ -26,7 +26,6 @@

@ApplicationScoped
public class HttpAction implements ActionPlugin {
private static final Logger log = Logger.getLogger(HttpAction.class);

public static final String TYPE_HTTP = "http";

Expand Down Expand Up @@ -89,13 +88,13 @@ public Uni<String> execute(JsonNode config, JsonNode secrets, Object payload) {
.setPort(url.getPort() >= 0 ? url.getPort() : url.getDefaultPort())
.setURI(url.getFile())
.setSsl("https".equalsIgnoreCase(url.getProtocol()));
log.infof("Sending event to %s", url);
Log.infof("Sending event to %s", url);
return http1xClient.request(HttpMethod.POST, options)
.putHeader("Content-Type", "application/json")
.sendBuffer(Buffer.buffer(body.toString()))
.onItem().transform(response -> {
if (response.statusCode() < 400) {
return String.format("Successfully(%d) notified hook: %s", response.statusCode(), url);
return "Successfully(" + response.statusCode() + ") notified hook: " + url;
} else {
throw new IllegalArgumentException("Failed to POST " + url + ", response " + response.statusCode()
+ ": " + response.bodyAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@

import org.apache.http.HttpStatus;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import io.hyperfoil.tools.horreum.svc.Util;
import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import io.vertx.core.json.JsonObject;

@ApplicationScoped
public class SlackChannelMessageAction extends SlackPluginBase implements ActionPlugin {
private static final Logger log = Logger.getLogger(SlackChannelMessageAction.class);
public static final String TYPE_SLACK_MESSAGE = "slack-channel-message";

@Override
Expand All @@ -28,7 +27,7 @@ public String type() {

@Override
public void validate(JsonNode config, JsonNode secrets) {
log.tracef("Validating config %s, secrets %s", config, secrets);
Log.tracef("Validating config %s, secrets %s", config, secrets);
requireProperties(secrets, "token");
requireProperties(config, "formatter", "channel");
}
Expand Down Expand Up @@ -64,29 +63,27 @@ public Uni<String> execute(JsonNode config, JsonNode secrets, Object payload) {
text.put("text", comment);
blocks.add(section);

log.debugf("Slack URL %s, token %s, body %s", url, token, body);
Log.debugf("Slack URL %s, token %s, body %s", url, token, body);
return post(url, secrets, body)
.onItem().transformToUni(response -> {
if (response.statusCode() < 400) {
JsonObject status = response.bodyAsJsonObject();
if (!status.getBoolean("ok")) {
return Uni.createFrom().failure(
new RuntimeException(
String.format("Failed to post to channel %s, response %s", channel,
status.getString("error"))));
return Uni.createFrom().failure(new RuntimeException(
"Failed to post to channel " + channel + ", response " + status.getString("error")));
}
return Uni.createFrom()
.item(String.format("Successfully(%d) posted to channel %s", response.statusCode(), channel));
.item("Successfully(" + response.statusCode() + ") posted to channel " + channel);
} else if (response.statusCode() == HttpStatus.SC_TOO_MANY_REQUESTS
&& response.getHeader("Retry-After") != null) {
log.debugf("Slack POST needs retry: %s (%s)", response.toString(), response.bodyAsString());
Log.debugf("Slack POST needs retry: %s (%s)", response.toString(), response.bodyAsString());
return retry(response, config, secrets, payload);

} else {
log.debugf("Slack POST failed: %s (%s)", response.statusCode(), response.bodyAsString());
return Uni.createFrom().failure(new RuntimeException(
String.format("Failed to post to channel %s, response %d: %s",
channel, response.statusCode(), response.bodyAsString())));
Log.debugf("Slack POST failed: %s (%s)", response.statusCode(), response.bodyAsString());

String message = "Failed to create issue in " + channel + ", response" + response.statusCode() + ":\n"
+ response.bodyAsString();
return Uni.createFrom().failure(new RuntimeException(message));
}
}).onFailure()
.transform(t -> new RuntimeException("Failed to post message to " + channel + ": " + t.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;

import org.jboss.logging.Logger;

import com.fasterxml.jackson.databind.JsonNode;

import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.RequestOptions;
Expand All @@ -19,7 +18,6 @@
import io.vertx.mutiny.ext.web.client.HttpResponse;

public abstract class SlackPluginBase {
protected static final Logger log = Logger.getLogger(SlackPluginBase.class);

@Inject
Vertx vertx;
Expand Down Expand Up @@ -48,7 +46,7 @@ protected Uni<HttpResponse<Buffer>> post(String path, JsonNode secrets, JsonNode
if (token == null || token.isBlank()) {
throw new IllegalArgumentException("Missing access token!");
}
log.debugf("POST %s (%s): %s", path, token, payload.toString());
Log.debugf("POST %s (%s): %s", path, token, payload.toString());
URL url;
try {
url = new URL(path);
Expand All @@ -72,7 +70,7 @@ protected Uni<HttpResponse<Buffer>> post(String path, JsonNode secrets, JsonNode

protected Uni<String> retry(HttpResponse<Buffer> response, JsonNode config, JsonNode secrets, Object payload) {
int retryAfter = Integer.parseInt(response.getHeader("Retry-After"));
log.warnf("Exceeded server request limits, retrying after %d seconds", retryAfter);
Log.warnf("Exceeded server request limits, retrying after %d seconds", retryAfter);
return Uni.createFrom()
.emitter(em -> vertx.setTimer(TimeUnit.SECONDS.toMillis(retryAfter), id -> execute(config, secrets, payload)
.subscribe().with(em::complete, em::fail)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import org.jboss.logging.Logger;

import io.hyperfoil.tools.horreum.svc.Util;
import io.quarkus.logging.Log;
import io.quarkus.runtime.Startup;
import io.vertx.core.Vertx;

@Startup
@ApplicationScoped
public class BlockingTaskDispatcher {
private static final Logger log = Logger.getLogger(BlockingTaskDispatcher.class);

@Inject
Vertx vertx;

Expand All @@ -31,7 +30,7 @@ public void executeForTest(int testId, Runnable runnable) {
TaskQueue queue = taskQueues.computeIfAbsent(testId, TaskQueue::new);
queue.executeOrAdd(task);
} catch (Exception e) {
log.error("Failed to execute blocking task", e);
Log.error("Failed to execute blocking task", e);
} finally {
promise.complete();
}
Expand All @@ -41,7 +40,6 @@ public void executeForTest(int testId, Runnable runnable) {
}

class TaskQueue {
private static final Logger log = Logger.getLogger(TaskQueue.class);
private final int testId;
private final Queue<Runnable> queue = new ConcurrentLinkedQueue<>();
private final ReentrantLock lock = new ReentrantLock();
Expand All @@ -54,21 +52,21 @@ public void executeOrAdd(Runnable runnable) {
queue.add(runnable);
do {
if (lock.tryLock()) {
log.debugf("This thread is going to execute tasks (%d) for test %d, lock level %d", queue.size(), testId,
Log.debugf("This thread is going to execute tasks (%d) for test %d, lock level %d", queue.size(), testId,
lock.getHoldCount());
try {
while (!queue.isEmpty()) {
Runnable task = queue.poll();
task.run();
}
} catch (Throwable t) {
log.errorf(t, "Error executing task in the queue for test %d", testId);
Log.errorf(t, "Error executing task in the queue for test %d", testId);
} finally {
log.debugf("Finished executing tasks for test %d", testId);
Log.debugf("Finished executing tasks for test %d", testId);
lock.unlock();
}
} else {
log.debugf("There's another thread executing the tasks (%d) for test %d", queue.size(), testId);
Log.debugf("There's another thread executing the tasks (%d) for test %d", queue.size(), testId);
return;
}
} while (!queue.isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import org.jboss.logging.Logger;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -18,10 +16,10 @@
import io.hyperfoil.tools.horreum.api.data.changeDetection.FixedThresholdDetectionConfig;
import io.hyperfoil.tools.horreum.entity.alerting.ChangeDAO;
import io.hyperfoil.tools.horreum.entity.alerting.DataPointDAO;
import io.quarkus.logging.Log;

@ApplicationScoped
public class FixedThresholdModel implements ChangeDetectionModel {
private static final Logger log = Logger.getLogger(FixedThresholdModel.class);

@Inject
ObjectMapper mapper;
Expand All @@ -36,7 +34,6 @@ public ConditionConfig config() {
"Upper bound for acceptable datapoint values.");
conditionConfig.defaults.put("model", new TextNode(ChangeDetectionModelType.names.FIXED_THRESHOLD));
return conditionConfig;

}

@Override
Expand All @@ -55,29 +52,28 @@ public void analyze(List<DataPointDAO> dataPoints, JsonNode configuration, Consu
if (config.min.enabled) {
if ((!config.min.inclusive && dp.value <= config.min.value) || dp.value < config.min.value) {
ChangeDAO c = ChangeDAO.fromDatapoint(dp);
c.description = String.format("%f is below lower bound %f (%s)", dp.value, config.min.value,
c.description = "%f is below lower bound %f (%s)".formatted(dp.value, config.min.value,
config.min.inclusive ? "inclusive" : "exclusive");
log.debug(c.description);
Log.debug(c.description);
changeConsumer.accept(c);
return;
}
}
if (config.max.enabled) {
if ((!config.max.inclusive && dp.value >= config.max.value) || dp.value > config.max.value) {
ChangeDAO c = ChangeDAO.fromDatapoint(dp);
c.description = String.format("%f is above upper bound %f (%s)", dp.value, config.max.value,
c.description = "%f is above upper bound %f (%s)".formatted(dp.value, config.max.value,
config.max.inclusive ? "inclusive" : "exclusive");
log.debug(c.description);
Log.debug(c.description);
changeConsumer.accept(c);
}
}

} catch (JsonProcessingException e) {
String errMsg = String.format("Failed to parse configuration for variable %d", dp.variable.id);
log.error(errMsg, e);
String errMsg = "Failed to parse configuration for variable %d".formatted(dp.variable.id);
Log.error(errMsg, e);
throw new ChangeDetectionException(errMsg, e);
}

}

@Override
Expand Down
Loading
Loading