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

Seperate out checkpoint tests for audit tests #30556

Open
wants to merge 1 commit into
base: integration
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 @@ -167,6 +167,7 @@ public static interface ClassTearDown<T extends Throwable> {
private Consumer<LibertyServer> postCheckpointLambda;
private final Set<String> unsupportedRepeatIDs = new HashSet<>(Arrays.asList(EE6FeatureReplacementAction.ID, EE7FeatureReplacementAction.ID));
private String[] checkpointIgnoreMessages;
private boolean runNormalTests = true;

/**
* Sets the optional function to do class setup before running the normal and checkpoint mode for the test
Expand Down Expand Up @@ -287,11 +288,28 @@ public CheckpointRule setConsoleLogName(String consoleLogName) {
return this;
}

/**
* Adds regular expressions to match messages to ignore from the server
*
* @param regExs regular expression to match server messages
* @return
*/
public CheckpointRule addCheckpointRegexIgnoreMessages(String... regExs) {
this.checkpointIgnoreMessages = regExs;
return this;
}

/**
* Sets if the tests should be run on a normal server which has no checkpoint done.
*
* @param runNormalTests
* @return
*/
public CheckpointRule setRunNormalTests(boolean runNormalTests) {
this.runNormalTests = runNormalTests;
return this;
}

@Override
public Statement apply(Statement base, Description desc) {
assertNotNull("Must set ServerSetup", serverSetup);
Expand Down Expand Up @@ -333,7 +351,9 @@ public void evaluate() throws Throwable {
classSetup.call();
}
try {
evaluate(ServerMode.NORMAL);
if (runNormalTests) {
evaluate(ServerMode.NORMAL);
}
evaluate(ServerMode.CHECKPOINT);
} finally {
if (classTearDown != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
TelemetrySourcesTest.class,
TelemetryApplicationConfigTest.class,
TelemetryDropinsTest.class,
TelemetryAuditTest.class
TelemetryAuditTest.class,
TelemetryAuditCheckpointTest.class
})

public class FATSuite {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright year -> 2025

* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package io.openliberty.microprofile.telemetry.logging.internal_fat;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.List;
import java.util.stream.Collectors;

import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.RemoteFile;
import com.ibm.websphere.simplicity.log.Log;

import componenttest.annotation.CheckpointTest;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.rules.repeater.CheckpointRule;
import componenttest.rules.repeater.CheckpointRule.ServerMode;
import componenttest.rules.repeater.RepeatTests;
import componenttest.topology.impl.LibertyServer;
import componenttest.topology.impl.LibertyServerFactory;
import componenttest.topology.utils.FATServletClient;
import io.openliberty.microprofile.telemetry.internal_fat.shared.TelemetryActions;

@RunWith(FATRunner.class)
@CheckpointTest(alwaysRun = true)
public class TelemetryAuditCheckpointTest extends FATServletClient {

public static final String SERVER_NAME = "TelemetryAuditCheckpoint";

@ClassRule
public static CheckpointRule checkpointRule = new CheckpointRule()
.setConsoleLogName(TelemetryAuditCheckpointTest.class.getSimpleName() + ".log")
.setRunNormalTests(false)
.setServerSetup(TelemetryAuditCheckpointTest::initialSetup)
.setServerStart(TelemetryAuditCheckpointTest::testSetup)
.setServerTearDown(TelemetryAuditCheckpointTest::testTearDown);

//This test will run on all mp 2.0 repeats to ensure we have some test coverage on all versions.
//I chose this one because TelemetryMessages is core to this bucket
// Will re-enable in follow-on issue.
@ClassRule
public static RepeatTests rt = TelemetryActions.telemetry20Repeats();

private static LibertyServer server;

public static LibertyServer initialSetup(ServerMode mode) throws Exception {
server = LibertyServerFactory.getLibertyServer(SERVER_NAME, null, true);
server.saveServerConfiguration();
return server;
}

public static void testSetup(ServerMode mode, LibertyServer server) throws Exception {
server.startServer();
}

public static void testTearDown(ServerMode mode, LibertyServer server) throws Exception {
server.stopServer();

// Restore the server configuration, after each test case.
server.restoreServerConfiguration();
}

/**
* Ensures Audit messages are correctly bridged and all attributes are present.
*/
@Test
public void testTelemetryAuditLogs() throws Exception {
// on restore we expect no audit messages that happened on the checkpoint side
RemoteFile consoleLog = server.getConsoleLogFile();
List<String> linesConsoleLog = server.findStringsInLogsUsingMark(".*scopeInfo.*", consoleLog);

Log.info(getClass(), "testRestoreTelemetryAuditLogs", "Number of logs: " + linesConsoleLog.size());
for (String line : linesConsoleLog) {
Log.info(getClass(), "testRestoreTelemetryAuditLogs", line);
}

linesConsoleLog = linesConsoleLog.stream().filter((l) -> !l.contains("WebSphere:type=ThreadPoolStats")).collect(Collectors.toList());

assertEquals("Expected no audit messages on restore", 0, linesConsoleLog.size());
// generate JMX_MBEAN_REGISTER audit message by hitting the root of the server
TestUtils.runGetMethod("http://" + server.getHostname() + ":" + server.getHttpDefaultPort());
String line = server.waitForStringInLog("JMXService", server.getConsoleLogFile());
assertNotNull("The JMXService audit event was not not found.", line);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,52 @@
*******************************************************************************/
package io.openliberty.microprofile.telemetry.logging.internal_fat;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.RemoteFile;

import componenttest.annotation.CheckpointTest;
import componenttest.annotation.Server;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.rules.repeater.CheckpointRule;
import componenttest.rules.repeater.CheckpointRule.ServerMode;
import componenttest.rules.repeater.RepeatTests;
import componenttest.topology.impl.LibertyServer;
import componenttest.topology.impl.LibertyServerFactory;
import componenttest.topology.utils.FATServletClient;
import io.openliberty.microprofile.telemetry.internal_fat.shared.TelemetryActions;

@RunWith(FATRunner.class)
@CheckpointTest(alwaysRun = true)
public class TelemetryAuditTest extends FATServletClient {

private static Class<?> c = TelemetryAuditTest.class;

public static final String SERVER_NAME = "TelemetryAudit";

@ClassRule
public static CheckpointRule checkpointRule = new CheckpointRule()
.setConsoleLogName(TelemetryAuditTest.class.getSimpleName() + ".log")
.setServerSetup(TelemetryAuditTest::initialSetup)
.setServerStart(TelemetryAuditTest::testSetup)
.setServerTearDown(TelemetryAuditTest::testTearDown);

//This test will run on all mp 2.0 repeats to ensure we have some test coverage on all versions.
//I chose this one because TelemetryMessages is core to this bucket
// Will re-enable in follow-on issue.
@ClassRule
public static RepeatTests rt = TelemetryActions.telemetry20Repeats();

private static LibertyServer server;
@Server(SERVER_NAME)
public static LibertyServer server;

public static LibertyServer initialSetup(ServerMode mode) throws Exception {
server = LibertyServerFactory.getLibertyServer(SERVER_NAME, null, true);
@BeforeClass
public static void initialSetup() throws Exception {
server.saveServerConfiguration();
return server;
}

public static void testSetup(ServerMode mode, LibertyServer server) throws Exception {
@Before
public void testSetup() throws Exception {
server.startServer();
}

public static void testTearDown(ServerMode mode, LibertyServer server) throws Exception {
@After
public void testTearDown() throws Exception {
server.stopServer();

// Restore the server configuration, after each test case.
Expand All @@ -78,27 +66,7 @@ public static void testTearDown(ServerMode mode, LibertyServer server) throws Ex
*/
@Test
public void testTelemetryAuditLogs() throws Exception {
if (CheckpointRule.isActive()) {
testRestoreTelemetryAuditLogs(server);
} else {
testTelemetryAuditLogs(server);
}
}

private void testRestoreTelemetryAuditLogs(LibertyServer s) throws Exception {
// on restore we expect no audit messages that happened on the checkpoint side
RemoteFile consoleLog = s.getConsoleLogFile();
List<String> linesConsoleLog = s.findStringsInLogsUsingMark(".*scopeInfo.*", consoleLog);
assertEquals("Expected no audit messages on restore", 0, linesConsoleLog.size());

// generate JMX_MBEAN_REGISTER audit message by hitting the root of the server
TestUtils.runGetMethod("http://" + s.getHostname() + ":" + s.getHttpDefaultPort());
String line = s.waitForStringInLog("JMXService", s.getConsoleLogFile());
assertNotNull("The JMXService audit event was not not found.", line);
}

private void testTelemetryAuditLogs(LibertyServer s) throws Exception {
String line = s.waitForStringInLog("AuditService", s.getConsoleLogFile());
String line = server.waitForStringInLog("AuditService", server.getConsoleLogFile());

assertNotNull("The AuditService audit event was not not found.", line);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bootstrap.include=../testports.properties
com.ibm.ws.logging.console.log.level=OFF
com.ibm.ws.logging.trace.specification=io.openliberty.microprofile.telemetry.internal.common=all:io.openliberty.microprofile.telemetry.logging.internal.fat.MpTelemetryLogApp.*=all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed, since we aren't checking for trace or even using the test app in the checkpoint test.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Dcom.ibm.ws.beta.edition=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
OTEL_LOGS_EXPORTER=console
OTEL_METRICS_EXPORTER=none
OTEL_TRACE_EXPORTER=none
OTEL_SDK_DISABLED=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
Copyright (c) 2024 IBM Corporation and others.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this needs to be updated to 2025, or if config files even need a copyright header?

All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-2.0/

SPDX-License-Identifier: EPL-2.0

Contributors:
IBM Corporation - initial API and implementation
-->
<server description="Telemetry Server to test Message logs">
<featureManager>
<feature>servlet-6.1</feature>
<feature>mpTelemetry-2.0</feature>
<feature>audit-2.0</feature>
<feature>componentTest-2.0</feature>
<feature>appsecurity-6.0</feature>
</featureManager>
<include location="../fatTestPorts.xml"/>
<mpTelemetry source="audit"/>
</server>