Skip to content

Commit

Permalink
Merge pull request #2007 from nordic-institute/e2e-logging-improvements
Browse files Browse the repository at this point in the history
chore: improve e2e logging and increase performance
  • Loading branch information
ricardas-buc authored Mar 25, 2024
2 parents b4da9ff + 0144338 commit 04ae8c2
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Docker/centralserver/files/etc/xroad/conf.d/local.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[admin-service]
global-configuration-generation-rate-in-seconds = 10
[configuration-client]
#default 60
update-interval = 10
4 changes: 2 additions & 2 deletions src/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ commonsCompressVersion=1.26.0
commonsIOVersion=2.15.1
commonsLang3Version=3.14.0
commonsConfiguration2Version=2.9.0
testAutomationFrameworkVersion=0.2.16
awaitilityVersion=4.2.0
testAutomationFrameworkVersion=0.2.17
awaitilityVersion=4.2.1
bucket4jVersion=7.4.0
assertjVersion=3.24.2
assertj.version=${assertjVersion}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* The MIT License
* Copyright (c) 2019- Nordic Institute for Interoperability Solutions (NIIS)
* Copyright (c) 2018 Estonian Information System Authority (RIA),
* Nordic Institute for Interoperability Solutions (NIIS), Population Register Centre (VRK)
* Copyright (c) 2015-2017 Estonian Information System Authority (RIA), Population Register Centre (VRK)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.niis.xroad.e2e.container;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.FileAppender;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class ComposeLoggerFactory {
public static final String CONTAINER_LOGS_DIR = "container-logs";

private static final String APPENDER_NAME = "REPORT";
private static final String LOG_PATTERN = "%d{HH:mm:ss.SS} [%logger{50}] %msg%n";

public Logger create(String containerName) {
var context = (LoggerContext) LoggerFactory.getILoggerFactory();

FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
fileAppender.setContext(context);
fileAppender.setName(APPENDER_NAME);
fileAppender.setFile(createFilePath(containerName));
fileAppender.setEncoder(createEncoder(context));
fileAppender.start();

Logger logger = context.getLogger(containerName.toUpperCase());
logger.addAppender(fileAppender);
logger.setAdditive(false);

return logger;
}

private PatternLayoutEncoder createEncoder(LoggerContext context) {
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern(LOG_PATTERN);
encoder.start();

return encoder;
}

private String createFilePath(String containerName) {
return System.getProperty("testExecLogDir") + "/" + CONTAINER_LOGS_DIR + "/" + containerName + "-test-automation.log";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.stereotype.Service;
import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.containers.ContainerState;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;

import java.io.File;
Expand All @@ -58,6 +59,7 @@ public class EnvSetup implements TestableContainerInitializer {
public static final String SS1 = "ss1";
public static final String HURL = "hurl";

private final ComposeLoggerFactory composeLoggerFactory;
private final CustomProperties customProperties;

private ComposeContainer environment;
Expand All @@ -83,7 +85,10 @@ public void initialize() {
.withEnv("SS_IMG", customProperties.getSsImage())
.withEnv("CA_IMG", customProperties.getCaImage())
.withEnv("IS_SOAP_IMG", customProperties.getIssoapImage())

.withLogConsumer(HURL, createLogConsumer(HURL))
.withLogConsumer(CS, createLogConsumer(CS))
.withLogConsumer(SS0, createLogConsumer(SS0))
.withLogConsumer(SS1, createLogConsumer(SS1))
.waitingFor(CS, Wait.forLogMessage("^.*xroad-center entered RUNNING state.*$", 1));

environment.start();
Expand All @@ -92,6 +97,10 @@ public void initialize() {
}
}

private Slf4jLogConsumer createLogConsumer(String containerName) {
return new Slf4jLogConsumer(new ComposeLoggerFactory().create(containerName));
}

@SuppressWarnings("checkstyle:magicnumber")
private void waitForHurl() {
await()
Expand All @@ -104,6 +113,10 @@ private void waitForHurl() {
.map(container -> !container.isRunning())
.orElse(false);
});

var gracePeriod = Duration.ofSeconds(30);
log.info("Waiting grace period of {} before continuing..", gracePeriod);
await().pollDelay(gracePeriod).timeout(gracePeriod.plusMinutes(1)).until(() -> true);
}

@PreDestroy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* The MIT License
* Copyright (c) 2019- Nordic Institute for Interoperability Solutions (NIIS)
* Copyright (c) 2018 Estonian Information System Authority (RIA),
* Nordic Institute for Interoperability Solutions (NIIS), Population Register Centre (VRK)
* Copyright (c) 2015-2017 Estonian Information System Authority (RIA), Population Register Centre (VRK)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.niis.xroad.e2e.hook;

import com.nortal.test.core.services.hooks.AfterSuiteHook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.nio.file.Path;

import static java.nio.file.Files.move;
import static org.niis.xroad.e2e.container.ComposeLoggerFactory.CONTAINER_LOGS_DIR;

@Slf4j
@Component
public class LogPrepHook implements AfterSuiteHook {
@Override
public void afterSuite() {
log.info("Moving container logs to final destination.");
try {
move(
Path.of(System.getProperty("testExecLogDir"), CONTAINER_LOGS_DIR),
Path.of(System.getProperty("testExecLogDir"), "allure-report", CONTAINER_LOGS_DIR)
);
} catch (Exception e) {
log.error("Failed to move container logs to their final destination.", e);
}
}

@Override
@SuppressWarnings("checkstyle:MagicNumber")
public int afterSuitOrder() {
// Exec after allure report is generated. We just want to attach it to final report.
return 50100;
}
}

0 comments on commit 04ae8c2

Please sign in to comment.