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

chore: change info to debug logging #410

Merged
merged 2 commits into from
Nov 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class LdioHttpEnricher extends LdioTransformer {

private static final Logger LOGGER = LoggerFactory.getLogger(LdioHttpEnricher.class);
private static final Logger log = LoggerFactory.getLogger(LdioHttpEnricher.class);

private final LdiAdapter adapter;
private final RequestExecutor requestExecutor;
Expand All @@ -34,7 +34,7 @@ public void apply(Model model) {
final Request request = createRequest(model);
final Response response = requestExecutor.execute(request);

LOGGER.info(request.getMethod() + " " + request.getUrl() + " " + response.getHttpStatus());
log.debug(request.getMethod() + " " + request.getUrl() + " " + response.getHttpStatus());

addResponseToModel(model, response);
this.next(model);
Expand Down Expand Up @@ -100,7 +100,7 @@ private void addResponseToModel(Model model, Response response) {
.toList()
.forEach(model::add);
} else {
LOGGER.atWarn().log("Failed to enrich model. The request url was {}. " +
log.atWarn().log("Failed to enrich model. The request url was {}. " +
"The http response obtained from the server has code {} and body \"{}\".",
response.getRequestedUrl(), response.getHttpStatus(), response.getBody().orElse(null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class HttpInputPoller extends LdiInput {
private final RequestExecutor requestExecutor;
private final List<? extends Request> requests;
private final boolean continueOnFail;
private static final Logger LOGGER = LoggerFactory.getLogger(HttpInputPoller.class);
private static final Logger log = LoggerFactory.getLogger(HttpInputPoller.class);
private static final String CONTENT_TYPE = "Content-Type";

public HttpInputPoller(ComponentExecutor executor, LdiAdapter adapter, List<String> endpoints,
Expand All @@ -46,7 +46,7 @@ public void poll() {
try {
executeRequest(request);
} catch (Exception e) {
LOGGER.error(e.getMessage());
log.error(e.getMessage());
if (!continueOnFail) {
throw e;
}
Expand All @@ -55,11 +55,11 @@ public void poll() {
}

private void executeRequest(Request request) {
LOGGER.atDebug().log("Polling next url: {}", request.getUrl());
log.atDebug().log("Polling next url: {}", request.getUrl());

Response response = requestExecutor.execute(request);

LOGGER.info(request.getMethod() + " " + request.getUrl() + " " + response.getHttpStatus());
log.debug(request.getMethod() + " " + request.getUrl() + " " + response.getHttpStatus());

if (HttpStatusCode.valueOf(response.getHttpStatus()).is2xxSuccessful()) {
String contentType = response.getFirstHeaderValue(CONTENT_TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import be.vlaanderen.informatievlaanderen.ldes.ldi.types.LdiInput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;

import java.util.NoSuchElementException;
Expand All @@ -17,7 +19,7 @@

public class LdioHttpIn extends LdiInput {

private static final Logger LOGGER = LoggerFactory.getLogger(LdioHttpIn.class);
private static final Logger log = LoggerFactory.getLogger(LdioHttpIn.class);
private final String endpoint;

public LdioHttpIn(ComponentExecutor executor, LdiAdapter adapter, String endpoint) {
Expand All @@ -32,9 +34,7 @@ public RouterFunction<ServerResponse> mapping() {
.orElseThrow(() -> new NoSuchElementException("No Content-Type header found"))
.toString();

String type = req.headers().contentType().map(MediaType::toString).orElse("(unknown)");
LOGGER.info("POST " + "/%s".formatted(endpoint) + " type:" + type + " length:"
+ req.headers().contentLength().orElse(0L));
logIncomingRequest(req);

return req.bodyToMono(String.class)
.doOnNext(content -> getAdapter().apply(Content.of(content, contentType))
Expand All @@ -43,4 +43,11 @@ public RouterFunction<ServerResponse> mapping() {
});
}

private void logIncomingRequest(ServerRequest request) {
var httpMethod = HttpMethod.POST.name();
var type = request.headers().contentType().map(MediaType::toString).orElse("(unknown)");
long contentLength = request.headers().contentLength().orElse(0L);
log.atDebug().log("{} /{} type: {} length: {}", httpMethod, endpoint, type, contentLength);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class LdioHttpOut implements LdiOutput {

private static final Logger LOGGER = LoggerFactory.getLogger(LdioHttpOut.class);
private static final Logger log = LoggerFactory.getLogger(LdioHttpOut.class);

private final RequestExecutor requestExecutor;
private final String targetURL;
Expand All @@ -39,9 +39,9 @@ public void accept(Model linkedDataModel) {
final PostRequest request = new PostRequest(targetURL, new RequestHeaders(List.of(requestHeader)), content);
Response response = requestExecutor.execute(request);
if (response.isSuccess()) {
LOGGER.info(request.getMethod() + " " + request.getUrl() + " " + response.getHttpStatus());
log.debug(request.getMethod() + " " + request.getUrl() + " " + response.getHttpStatus());
} else {
LOGGER.atError().log("Failed to post model. The request url was {}. " +
log.atError().log("Failed to post model. The request url was {}. " +
"The http response obtained from the server has code {} and body \"{}\".",
response.getRequestedUrl(), response.getHttpStatus(), response.getBody().orElse(null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.common.header.Header;
import org.apache.kafka.common.header.Headers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.listener.MessageListener;

public class LdioKafkaIn extends LdiInput implements MessageListener<String, String> {

private static final Logger log = LoggerFactory.getLogger(LdioKafkaIn.class);
private final String defaultContentType;

/**
Expand All @@ -30,8 +33,9 @@ public LdioKafkaIn(ComponentExecutor executor, LdiAdapter adapter, String defaul
@Override
public void onMessage(ConsumerRecord<String, String> data) {
final String contentType = determineContentType(data.headers());
getAdapter().apply(LdiAdapter.Content.of(data.value(), contentType))
.forEach(getExecutor()::transformLinkedData);
final var content = LdiAdapter.Content.of(data.value(), contentType);
log.atDebug().log("Incoming kafka message: {}", content);
getAdapter().apply(content).forEach(getExecutor()::transformLinkedData);
}

private String determineContentType(Headers headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.edc.services.TransferService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
Expand Down Expand Up @@ -46,9 +47,10 @@ public RouterFunction<ServerResponse> endpoints() {
}

private void logIncomingRequest(ServerRequest request) {
var httpMethod = HttpMethod.POST.name();
var type = request.headers().contentType().map(MediaType::toString).orElse("(unknown)");
long contentLength = request.headers().contentLength().orElse(0L);
log.atDebug().log("POST /%s type: %s length: %s".formatted(pipelineName, type, contentLength));
log.atDebug().log("{} /{} type: {} length: {}", httpMethod, pipelineName, type, contentLength);
}

}
Loading