Skip to content

Add tests for remote logging#14230

Open
thivindu wants to merge 1 commit into
wso2:masterfrom
thivindu:remote-logging-tests
Open

Add tests for remote logging#14230
thivindu wants to merge 1 commit into
wso2:masterfrom
thivindu:remote-logging-tests

Conversation

@thivindu

Copy link
Copy Markdown
Contributor

Summary

Adds integration tests for the remote logging appender management behaviour, covering how log4j2.properties is modified (or deliberately left unchanged) when remote server logging is enabled or disabled via the RemoteLoggingConfig admin service.

Related to - wso2/api-manager#4925

Changes

New: RemoteLoggingConfigClient

A thin wrapper around RemoteLoggingConfigStub that exposes the five operations of the RemoteLoggingConfig Axis2 admin service — addRemoteServerConfig, resetRemoteServerConfig, getRemoteServerConfigs, getRemoteServerConfig, and syncRemoteServerConfigs — in a form that integrates with the existing admin-client authentication pattern.


New: RemoteLoggingAppenderTest

Ten independent integration tests grouped into four scenarios. Each test writes a dedicated fixture to the live log4j2.properties, calls the service under test, reads the file back, and asserts on its content. @AfterMethod(alwaysRun = true) resets all active remote logging configurations and restores the original log4j2.properties after every test (pass or fail), providing full isolation without dependsOnMethods chaining.

A built-in Java HttpServer acts as the mock remote log receiver for the end-to-end test; no additional test dependencies are introduced.

Test method What it verifies
testExistingAppendersPreservedOnResetWithBlankUrl Calling resetRemoteServerConfig on already-RollingFile appenders is a no-op
testOnlyConfiguredAppenderIsReset Reset for one log type does not affect the other two appender blocks
testMissingAuditAppenderCreatedOnEnable AUDIT_LOGFILE block written as HTTP + AUDIT_LOG logger wired when block was absent
testMissingCarbonAppenderCreatedOnEnable CARBON_LOGFILE block written as HTTP + rootLogger appenderRef added when block was absent
testMissingApiAppenderCreatedOnEnable API_LOGFILE block written as HTTP + API_LOG logger wired when block was absent
testOnlyTargetedAppenderCreatedWhenOthersAbsent Enabling remote logging for API only creates API_LOGFILE; AUDIT_LOGFILE and CARBON_LOGFILE remain absent
testMissingAppendersNotAddedOnSyncWhenRemoteLoggingNotConfigured syncRemoteServerConfigs() with no configured remote URLs leaves a stripped log4j2.properties unchanged
testNoDuplicateAppenderInList Enabling then resetting does not produce duplicate entries in the appenders = ... list
testRemoteLoggingEndToEnd Audit log entries reach the mock HTTP endpoint when enabled, and stop after reset
testAllThreeMissingAppendersCreatedOnEnable Enabling all three log types populates all three appender blocks and their corresponding loggers

New: log4j2 test fixtures (5 files)

Each fixture is a self-consistent log4j2.properties file. Loggers that reference absent appenders are removed to prevent Unable to locate appender warnings during the test run.

Fixture State
log4j2WithAllAppenders.properties All three blocks present as RollingFile; baseline for reset and no-duplicate tests
log4j2WithoutAuditAppender.properties AUDIT_LOGFILE block and AUDIT_LOG logger absent
log4j2WithoutCarbonAppender.properties CARBON_LOGFILE block and its rootLogger reference absent
log4j2WithoutApiAppender.properties API_LOGFILE block and API_LOG logger absent
log4j2WithoutLocalAppenders.properties All three blocks, their loggers, and their rootLogger reference absent

Modified: pom.xml files

  • Root pom.xml — added org.wso2.carbon.logging.remote.config.stub to dependencyManagement
  • admin-clients/pom.xml — consumed the above dependency

Modified: testng.xml

Added the apim-remote-logging-tests test group pointing at RemoteLoggingAppenderTest.


Testing

The end-to-end test (testRemoteLoggingEndToEnd) requires no external infrastructure — it binds an ephemeral HttpServer on a free local port and uses Awaitility to wait up to 30 seconds for the first log payload to arrive.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new remote logging admin client, Log4j2 fixtures, and integration tests covering appender updates, sync behavior, deduplication, and HTTP delivery. It also updates TestNG wiring and the remote logging stub dependency version.

Changes

Remote Logging Appender Tests

Layer / File(s) Summary
Dependency and version updates
all-in-one-apim/pom.xml, modules/integration/tests-common/admin-clients/pom.xml
Bumps carbon.commons.version to 4.13.4, adds org.wso2.carbon.logging.remote.config.stub to root dependency management, and adds the same stub dependency to the admin-clients module.
RemoteLoggingConfigClient admin client
modules/integration/tests-common/admin-clients/src/main/java/org/wso2/am/admin/clients/logging/RemoteLoggingConfigClient.java
New Axis2-based client wrapping RemoteLoggingConfigStub with basic auth initialization, public APIs for add/reset/get/sync operations, raw SOAP OM payload construction for add/reset, and null-safe child element helpers.
Remote logging fixture configurations
modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/*Appender.properties
New Log4j2 fixtures cover the all-appender baseline and missing AUDIT, CARBON, and API appender variants used by the remote logging tests.
No-local-appender fixture variants
modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutLocalAppenders.properties
Additional Log4j2 fixtures remove all three local appender blocks and document the blank-URL and reset/sync scenarios that use that layout.
RemoteLoggingAppenderTest setup and helpers
...logging/RemoteLoggingAppenderTest.java
Test class constants, shared fields, mock HTTP server setup, restore logic, fixture copy/load helpers, properties parsing utilities, remote config builders, log-trigger helpers, and timing/network helpers.
RemoteLoggingAppenderTest scenarios
...logging/RemoteLoggingAppenderTest.java
Test methods cover blank-URL reset, AUDIT enable/revert, missing-appender creation for AUDIT/CARBON/API, targeted scoping, sync behavior when unconfigured, deduplication, end-to-end payload delivery, and all-three-missing creation.
TestNG suite wiring
modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml
Adds RemoteLoggingAppenderTest to the apim-logging-tests suite class list.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • tharindu1st
  • AnuGayan
  • chamilaadhi
  • Arshardd
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding remote logging tests.
Description check ✅ Passed The description is clearly related to the remote logging integration test changes.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java (4)

887-889: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Consider replacing fixed sleep with polling for actual config file change.

waitForLog4j2ConfigSync uses Thread.sleep(seconds) which is a fixed delay. While the comment explains this is for OSGi reconfiguration, the test could be more resilient by polling the actual file content or a JMX/health indicator until the expected change is visible, with a timeout. This would reduce test flakiness and runtime when the sync is faster than the fixed delay.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`
around lines 887 - 889, `waitForLog4j2ConfigSync` currently uses a fixed sleep,
which makes `RemoteLoggingAppenderTest` slower and flaky; replace the
`TimeUnit.SECONDS.sleep` delay with a polling-based wait that repeatedly checks
the actual Log4j2 config state or file contents until the expected change is
observed or a timeout is reached. Keep the helper method name the same so
callers remain unchanged, but update its implementation to use a bounded retry
loop with a small interval and clear timeout handling.

652-663: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Enable or remove commented-out logger wiring assertions.

Lines 652-663 contain commented-out assertions that verify AUDIT_LOG and API_LOG appear in the loggers list with correct appenderRef values, and that rootLogger references CARBON_LOGFILE. These are important completeness checks for the "all three missing" scenario. Either enable them or remove with explanation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`
around lines 652 - 663, The RemoteLoggingAppenderTest contains commented-out
assertions for the all-three-missing scenario, so the completeness checks for
AUDIT_LOG, API_LOG, and rootLogger wiring are currently skipped. In the relevant
test method in RemoteLoggingAppenderTest, either re-enable the assertions that
call isLoggerInList and hasLoggerAppenderRef for LOGGER_KEY_AUDIT,
LOGGER_KEY_API, and the root logger appender ref, or remove them only if this
case is intentionally no longer covered. Keep the assertions aligned with the
existing LOGGER_KEY_AUDIT, LOGGER_KEY_API, APPENDER_AUDIT, APPENDER_API, and
APPENDER_CARBON symbols so the test still verifies the expected logger wiring.

472-475: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the server-side NPE as a known issue.

The comment at lines 472-475 describes a NullPointerException in isDataUpdated on the server side when getUsername() returns null. This is a genuine server-side bug that the test works around. Consider filing a bug ticket or adding a TODO comment with a reference so the workaround can be removed once the server code is fixed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`
around lines 472 - 475, The comment in RemoteLoggingAppenderTest should
explicitly mark the server-side NullPointerException in isDataUpdated as a known
issue rather than just describing the workaround. Update the nearby test fixture
note that references getRemoteServerConfigs and getUsername().equals(...) to
include a TODO or bug reference tied to isDataUpdated so the workaround is
clearly tracked and can be removed once the server-side fix lands.

451-454: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Enable or remove commented-out logger assertions.

The commented-out assertions at lines 451-454 verify that API_LOG appears in the loggers list and has an appenderRef to API_LOGFILE after remote logging is enabled. These checks are important for ensuring the logger wiring is correct when a missing appender block is created. Either enable them if they pass, or remove them with a comment explaining why they are not valid.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`
around lines 451 - 454, The RemoteLoggingAppenderTest is leaving important
logger verification disabled by commenting out assertions in the API remote
logging check. Update the test around the logger validation logic to either
re-enable the assertions that use isLoggerInList and hasLoggerAppenderRef for
LOGGER_KEY_API and APPENDER_API, or remove them and add a brief justification
comment if the behavior is no longer valid. Keep the test consistent with the
rest of the remote logging assertions so the API logger wiring is still
verified.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@all-in-one-apim/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/am/admin/clients/logging/RemoteLoggingConfigClient.java`:
- Around line 94-107: The admin mutation call in
RemoteLoggingConfigClient.sendConfigOp is using fireAndForget, which can swallow
SOAP faults and defer failures. Replace the
stub._getServiceClient().fireAndForget(op) call with sendRobust for this request
path so add/reset errors surface immediately at the admin call. Keep the
existing request-building logic in sendConfigOp and preserve the op element
construction, only changing the transport invocation.

---

Nitpick comments:
In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`:
- Around line 887-889: `waitForLog4j2ConfigSync` currently uses a fixed sleep,
which makes `RemoteLoggingAppenderTest` slower and flaky; replace the
`TimeUnit.SECONDS.sleep` delay with a polling-based wait that repeatedly checks
the actual Log4j2 config state or file contents until the expected change is
observed or a timeout is reached. Keep the helper method name the same so
callers remain unchanged, but update its implementation to use a bounded retry
loop with a small interval and clear timeout handling.
- Around line 652-663: The RemoteLoggingAppenderTest contains commented-out
assertions for the all-three-missing scenario, so the completeness checks for
AUDIT_LOG, API_LOG, and rootLogger wiring are currently skipped. In the relevant
test method in RemoteLoggingAppenderTest, either re-enable the assertions that
call isLoggerInList and hasLoggerAppenderRef for LOGGER_KEY_AUDIT,
LOGGER_KEY_API, and the root logger appender ref, or remove them only if this
case is intentionally no longer covered. Keep the assertions aligned with the
existing LOGGER_KEY_AUDIT, LOGGER_KEY_API, APPENDER_AUDIT, APPENDER_API, and
APPENDER_CARBON symbols so the test still verifies the expected logger wiring.
- Around line 472-475: The comment in RemoteLoggingAppenderTest should
explicitly mark the server-side NullPointerException in isDataUpdated as a known
issue rather than just describing the workaround. Update the nearby test fixture
note that references getRemoteServerConfigs and getUsername().equals(...) to
include a TODO or bug reference tied to isDataUpdated so the workaround is
clearly tracked and can be removed once the server-side fix lands.
- Around line 451-454: The RemoteLoggingAppenderTest is leaving important logger
verification disabled by commenting out assertions in the API remote logging
check. Update the test around the logger validation logic to either re-enable
the assertions that use isLoggerInList and hasLoggerAppenderRef for
LOGGER_KEY_API and APPENDER_API, or remove them and add a brief justification
comment if the behavior is no longer valid. Keep the test consistent with the
rest of the remote logging assertions so the API logger wiring is still
verified.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b8895b3f-2fcc-4a49-ae00-a8dccfdb067c

📥 Commits

Reviewing files that changed from the base of the PR and between 18c63e5 and 297b330.

📒 Files selected for processing (10)
  • all-in-one-apim/modules/integration/tests-common/admin-clients/pom.xml
  • all-in-one-apim/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/am/admin/clients/logging/RemoteLoggingConfigClient.java
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithAllAppenders.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutApiAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutAuditAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutCarbonAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutLocalAppenders.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml
  • all-in-one-apim/pom.xml

@thivindu thivindu force-pushed the remote-logging-tests branch from 297b330 to 22aa768 Compare June 30, 2026 07:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`:
- Around line 673-677: The cleanup in restoreAfterMethod() and the related
teardown path for remote logging state should not only log and continue when
reset fails. Update the RemoteLoggingAppenderTest cleanup flow around
disableAllActiveRemoteConfigs() and restoreLog4j2Properties() so any failure to
restore the baseline is surfaced as a test failure, using the existing teardown
methods to throw or assert after logging the error. Apply the same behavior to
the other cleanup block referenced in this test class so shared server state
cannot be left partially modified without failing the suite.
- Around line 4-8: The Apache license header in RemoteLoggingAppenderTest
contains a malformed URL, so update the license comment in the test file to use
the standard Apache 2.0 link and remove the stray trailing text from the URL.
Keep the rest of the header unchanged and make sure the corrected link is the
canonical http://www.apache.org/licenses/LICENSE-2.0 reference.
- Around line 574-598: The await in RemoteLoggingAppenderTest is only checking
that receivedLogPayloads is non-empty, which can pass because of earlier traffic
or addRemoteServerConfig() activity. Update triggerAuditLogEntry()/the wait
block to capture the payload count before triggering the admin action and then
wait for the count to increase, or otherwise assert a newly received payload
from the AUDIT appender rather than any existing entry. Make the assertion in
the atMost/poll loop verify a new log delivery was added to receivedLogPayloads.
- Around line 131-132: The mock logging server setup in
RemoteLoggingAppenderTest is using findFreePort() before HttpServer.create(),
which can race with other processes and cause flaky binds. Update the test
initialization to create the server with a port-0 InetSocketAddress directly,
then read the assigned port from the HttpServer instance for mockServerPort;
remove the now-unneeded findFreePort() helper and its call sites, including the
one used in the test setup and the duplicate helper near the bottom of the
class.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e41fefcb-42b6-4a3f-a0f1-997d4bda3d80

📥 Commits

Reviewing files that changed from the base of the PR and between 297b330 and 22aa768.

📒 Files selected for processing (10)
  • all-in-one-apim/modules/integration/tests-common/admin-clients/pom.xml
  • all-in-one-apim/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/am/admin/clients/logging/RemoteLoggingConfigClient.java
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithAllAppenders.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutApiAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutAuditAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutCarbonAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutLocalAppenders.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml
  • all-in-one-apim/pom.xml
🚧 Files skipped from review as they are similar to previous changes (9)
  • all-in-one-apim/modules/integration/tests-common/admin-clients/pom.xml
  • all-in-one-apim/pom.xml
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithAllAppenders.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutLocalAppenders.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutApiAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutAuditAppender.properties
  • all-in-one-apim/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/am/admin/clients/logging/RemoteLoggingConfigClient.java
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutCarbonAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml

Comment on lines +131 to +132
mockServerPort = findFreePort();
mockLogServer = HttpServer.create(new InetSocketAddress(mockServerPort), 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java"

echo "== file stats =="
wc -l "$FILE"
echo

echo "== outline =="
ast-grep outline "$FILE" --view expanded || true
echo

echo "== relevant slices =="
sed -n '110,160p' "$FILE"
echo
sed -n '870,920p' "$FILE"
echo
sed -n '880,910p' "$FILE" | nl -ba
echo

echo "== helper usages =="
rg -n "findFreePort\(|mockServerPort|HttpServer.create" "$FILE"

Repository: wso2/product-apim

Length of output: 6055


Bind the mock server directly on port 0. findFreePort() closes the socket before HttpServer binds, so another process can grab the port and make this test fail intermittently. Create the server with new InetSocketAddress(0), read back the assigned port, and remove findFreePort() (also at lines 894-898).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`
around lines 131 - 132, The mock logging server setup in
RemoteLoggingAppenderTest is using findFreePort() before HttpServer.create(),
which can race with other processes and cause flaky binds. Update the test
initialization to create the server with a port-0 InetSocketAddress directly,
then read the assigned port from the HttpServer instance for mockServerPort;
remove the now-unneeded findFreePort() helper and its call sites, including the
one used in the test setup and the duplicate helper near the bottom of the
class.

Comment on lines +574 to +598
RemoteServerLoggerData auditConfig = buildRemoteConfig(LOG_TYPE_AUDIT);
remoteLoggingConfigClient.addRemoteServerConfig(auditConfig);
waitForLog4j2ConfigSync(5);

/* Verify the appender was converted to HTTP type */
String afterEnable = readServerLog4j2Properties();
assertEquals(extractAppenderType(APPENDER_AUDIT, afterEnable), HTTP_TYPE,
"AUDIT_LOGFILE must be HTTP type after enabling remote logging");
assertTrue(afterEnable.contains("http://localhost:" + mockServerPort + "/api/logs/consume"),
"Remote URL must be present in the AUDIT_LOGFILE block");

/*
* Trigger an admin action that produces an audit log entry.
* The admin REST API is authenticated, so calling any admin resource with valid
* credentials generates an AUDIT_LOG entry.
*/
triggerAuditLogEntry();

/* Wait for the log entry to arrive at the mock server (up to 30 seconds) */
with().pollInterval(2, TimeUnit.SECONDS).await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
synchronized (receivedLogPayloads) {
assertFalse(receivedLogPayloads.isEmpty(),
"Mock log server must have received at least one log payload from the AUDIT appender");
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Wait for a new payload, not just any payload.

receivedLogPayloads is class-scoped, and Line 595 only checks for non-empty. If addRemoteServerConfig() or prior traffic already populated the buffer, this await passes without proving that Line 590 produced a delivery.

Proposed fix
-        triggerAuditLogEntry();
+        int payloadCountBeforeTrigger;
+        synchronized (receivedLogPayloads) {
+            payloadCountBeforeTrigger = receivedLogPayloads.size();
+        }
+        triggerAuditLogEntry();

         /* Wait for the log entry to arrive at the mock server (up to 30 seconds) */
         with().pollInterval(2, TimeUnit.SECONDS).await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
             synchronized (receivedLogPayloads) {
-                assertFalse(receivedLogPayloads.isEmpty(),
-                        "Mock log server must have received at least one log payload from the AUDIT appender");
+                assertTrue(receivedLogPayloads.size() > payloadCountBeforeTrigger,
+                        "Mock log server must receive a new log payload from the AUDIT appender");
             }
         });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
RemoteServerLoggerData auditConfig = buildRemoteConfig(LOG_TYPE_AUDIT);
remoteLoggingConfigClient.addRemoteServerConfig(auditConfig);
waitForLog4j2ConfigSync(5);
/* Verify the appender was converted to HTTP type */
String afterEnable = readServerLog4j2Properties();
assertEquals(extractAppenderType(APPENDER_AUDIT, afterEnable), HTTP_TYPE,
"AUDIT_LOGFILE must be HTTP type after enabling remote logging");
assertTrue(afterEnable.contains("http://localhost:" + mockServerPort + "/api/logs/consume"),
"Remote URL must be present in the AUDIT_LOGFILE block");
/*
* Trigger an admin action that produces an audit log entry.
* The admin REST API is authenticated, so calling any admin resource with valid
* credentials generates an AUDIT_LOG entry.
*/
triggerAuditLogEntry();
/* Wait for the log entry to arrive at the mock server (up to 30 seconds) */
with().pollInterval(2, TimeUnit.SECONDS).await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
synchronized (receivedLogPayloads) {
assertFalse(receivedLogPayloads.isEmpty(),
"Mock log server must have received at least one log payload from the AUDIT appender");
}
});
int payloadCountBeforeTrigger;
synchronized (receivedLogPayloads) {
payloadCountBeforeTrigger = receivedLogPayloads.size();
}
triggerAuditLogEntry();
/* Wait for the log entry to arrive at the mock server (up to 30 seconds) */
with().pollInterval(2, TimeUnit.SECONDS).await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
synchronized (receivedLogPayloads) {
assertTrue(receivedLogPayloads.size() > payloadCountBeforeTrigger,
"Mock log server must receive a new log payload from the AUDIT appender");
}
});
🧰 Tools
🪛 ast-grep (0.44.0)

[warning] 581-581: Avoid building a URL host from untrusted input
Context: "http://localhost:" + mockServerPort
Note: [CWE-20] Improper Input Validation.

(tainted-url-host)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`
around lines 574 - 598, The await in RemoteLoggingAppenderTest is only checking
that receivedLogPayloads is non-empty, which can pass because of earlier traffic
or addRemoteServerConfig() activity. Update triggerAuditLogEntry()/the wait
block to capture the payload count before triggering the admin action and then
wait for the count to increase, or otherwise assert a newly received payload
from the AUDIT appender rather than any existing entry. Make the assertion in
the atMost/poll loop verify a new log delivery was added to receivedLogPayloads.

Comment on lines +673 to +677
@AfterMethod(alwaysRun = true)
public void restoreAfterMethod() {
disableAllActiveRemoteConfigs();
restoreLog4j2Properties();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Fail the test when cleanup cannot restore the baseline.

restoreAfterMethod() logs and continues even when resetting remote configs or restoring log4j2.properties fails. Since this class mutates shared server state, warning-only cleanup turns the suite into an order-dependent false-positive generator.

Also applies to: 697-730

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`
around lines 673 - 677, The cleanup in restoreAfterMethod() and the related
teardown path for remote logging state should not only log and continue when
reset fails. Update the RemoteLoggingAppenderTest cleanup flow around
disableAllActiveRemoteConfigs() and restoreLog4j2Properties() so any failure to
restore the baseline is surfaced as a test failure, using the existing teardown
methods to throw or assert after logging the error. Apply the same behavior to
the other cleanup block referenced in this test class so shared server state
cannot be left partially modified without failing the suite.

@thivindu thivindu force-pushed the remote-logging-tests branch from 22aa768 to 9314c65 Compare June 30, 2026 08:25

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java (1)

451-454: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Remove or re-enable the commented-out logger-wiring assertions and now-unused helpers. The disabled assertions in testOnlyTargetedAppenderCreatedWhenOthersAbsent (Lines 451-454) and testAllThreeMissingAppendersCreatedOnEnable (Lines 652-663) drop verification that the recreated appenders are actually wired into the loggers list / appenderRefs — so these tests confirm the block exists but not that it routes logs. With them commented out, isLoggerInList (Line 825), hasLoggerAppenderRef (Line 845), and hasRootLoggerAppenderRef (Line 854) are dead code. Either restore the assertions (preferred, to validate routing) or delete both the commented blocks and the unused helpers.

Want me to wire up the logger-list assertions or strip the dead helpers?

Also applies to: 652-663

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`
around lines 451 - 454, Re-enable or remove the commented logger-wiring checks
in RemoteLoggingAppenderTest so the tests still validate that recreated
appenders are actually attached to the logging configuration, not just present
in the XML. In testOnlyTargetedAppenderCreatedWhenOthersAbsent and
testAllThreeMissingAppendersCreatedOnEnable, restore the assertions that use
isLoggerInList, hasLoggerAppenderRef, and hasRootLoggerAppenderRef if you want
to keep routing verification; otherwise delete those commented assertions and
remove the now-unused helper methods.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java`:
- Around line 451-454: Re-enable or remove the commented logger-wiring checks in
RemoteLoggingAppenderTest so the tests still validate that recreated appenders
are actually attached to the logging configuration, not just present in the XML.
In testOnlyTargetedAppenderCreatedWhenOthersAbsent and
testAllThreeMissingAppendersCreatedOnEnable, restore the assertions that use
isLoggerInList, hasLoggerAppenderRef, and hasRootLoggerAppenderRef if you want
to keep routing verification; otherwise delete those commented assertions and
remove the now-unused helper methods.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: eb4df39d-2f48-4cd9-8c68-6989a18bd693

📥 Commits

Reviewing files that changed from the base of the PR and between 22aa768 and 9314c65.

📒 Files selected for processing (10)
  • all-in-one-apim/modules/integration/tests-common/admin-clients/pom.xml
  • all-in-one-apim/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/am/admin/clients/logging/RemoteLoggingConfigClient.java
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/logging/RemoteLoggingAppenderTest.java
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithAllAppenders.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutApiAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutAuditAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutCarbonAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutLocalAppenders.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml
  • all-in-one-apim/pom.xml
✅ Files skipped from review due to trivial changes (1)
  • all-in-one-apim/modules/integration/tests-common/admin-clients/pom.xml
🚧 Files skipped from review as they are similar to previous changes (8)
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutApiAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithAllAppenders.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutAuditAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutCarbonAppender.properties
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/remoteLogging/log4j2WithoutLocalAppenders.properties
  • all-in-one-apim/pom.xml
  • all-in-one-apim/modules/integration/tests-common/admin-clients/src/main/java/org/wso2/am/admin/clients/logging/RemoteLoggingConfigClient.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant