Skip to content

Commit 2b0036a

Browse files
committed
add log message when ReadHealthStep fails
1 parent 4664e60 commit 2b0036a

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

operator/src/main/java/oracle/kubernetes/operator/logging/MessageKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,5 @@ private MessageKeys() {}
154154
public static final String EXTERNAL_CHANNEL_SERVICE_CREATED = "WLSKO-0150";
155155
public static final String EXTERNAL_CHANNEL_SERVICE_REPLACED = "WLSKO-0151";
156156
public static final String EXTERNAL_CHANNEL_SERVICE_EXISTS = "WLSKO-0152";
157+
public static final String WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT = "WLSKO-0153";
157158
}

operator/src/main/java/oracle/kubernetes/operator/steps/ReadHealthStep.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import oracle.kubernetes.operator.http.HttpClient;
1818
import oracle.kubernetes.operator.logging.LoggingFacade;
1919
import oracle.kubernetes.operator.logging.LoggingFactory;
20+
import oracle.kubernetes.operator.logging.LoggingFilter;
2021
import oracle.kubernetes.operator.logging.MessageKeys;
2122
import oracle.kubernetes.operator.work.NextAction;
2223
import oracle.kubernetes.operator.work.Packet;
@@ -93,6 +94,10 @@ public NextAction apply(Packet packet) {
9394
HttpClient httpClient = (HttpClient) packet.get(HttpClient.KEY);
9495

9596
if (httpClient == null) {
97+
LOGGER.info(
98+
(LoggingFilter) packet.get(LoggingFilter.LOGGING_FILTER_PACKET_KEY),
99+
MessageKeys.WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT,
100+
packet.get(ProcessingConstants.SERVER_NAME));
96101
return doNext(packet);
97102
}
98103

@@ -158,8 +163,11 @@ public NextAction apply(Packet packet) {
158163
return doNext(packet);
159164
} catch (Throwable t) {
160165
// do not retry for health check
161-
LOGGER.fine(
162-
MessageKeys.WLS_HEALTH_READ_FAILED, packet.get(ProcessingConstants.SERVER_NAME), t);
166+
LOGGER.info(
167+
(LoggingFilter) packet.get(LoggingFilter.LOGGING_FILTER_PACKET_KEY),
168+
MessageKeys.WLS_HEALTH_READ_FAILED,
169+
packet.get(ProcessingConstants.SERVER_NAME),
170+
t);
163171
return doNext(packet);
164172
}
165173
}

operator/src/main/resources/Operator.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,4 @@ WLSKO-0148=Current Pod dump [{0}] vs expected pod [{1}].
150150
WLSKO-0150=Creating external channel service for WebLogic domain with UID: {0}.
151151
WLSKO-0151=Replacing external channel service for WebLogic domain with UID: {0}.
152152
WLSKO-0152=Existing external channel service is correct for WebLogic domain with UID: {0}.
153+
WLSKO-0153=Failed to read health information from server {0}. Unable to connect to server.

operator/src/test/java/oracle/kubernetes/LogMatcher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public static LogMatcher containsInfo(String expectedMessage) {
3232
return new LogMatcher(Level.INFO, expectedMessage);
3333
}
3434

35+
public static LogMatcher containsInfo(String expectedMessage, Object expectedParameter) {
36+
return new LogMatcher(Level.INFO, expectedMessage, expectedParameter);
37+
}
38+
3539
public static LogMatcher containsWarning(String expectedMessage) {
3640
return new LogMatcher(Level.WARNING, expectedMessage);
3741
}

operator/src/test/java/oracle/kubernetes/operator/steps/ReadHealthStepTest.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
package oracle.kubernetes.operator.steps;
66

7-
import static oracle.kubernetes.LogMatcher.containsFine;
7+
import static oracle.kubernetes.LogMatcher.containsInfo;
88
import static oracle.kubernetes.operator.logging.MessageKeys.WLS_HEALTH_READ_FAILED;
9+
import static oracle.kubernetes.operator.logging.MessageKeys.WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT;
910
import static org.hamcrest.MatcherAssert.assertThat;
1011
import static org.junit.Assert.*;
1112

@@ -20,7 +21,6 @@
2021
import oracle.kubernetes.operator.ProcessingConstants;
2122
import oracle.kubernetes.operator.http.HttpClient;
2223
import oracle.kubernetes.operator.steps.ReadHealthStep.ReadHealthWithHttpClientStep;
23-
import oracle.kubernetes.operator.work.Component;
2424
import oracle.kubernetes.operator.work.NextAction;
2525
import oracle.kubernetes.operator.work.Packet;
2626
import oracle.kubernetes.operator.work.Step;
@@ -30,7 +30,9 @@
3030

3131
public class ReadHealthStepTest {
3232
// The log messages to be checked during this test
33-
private static final String[] LOG_KEYS = {WLS_HEALTH_READ_FAILED};
33+
private static final String[] LOG_KEYS = {
34+
WLS_HEALTH_READ_FAILED, WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT
35+
};
3436

3537
private List<LogRecord> logRecords = new ArrayList<>();
3638
private Memento consoleControl;
@@ -52,6 +54,23 @@ public void tearDown() {
5254

5355
@Test
5456
public void withHttpClientStep_Health_logIfFailed() {
57+
V1Service service = Stub.createStub(V1ServiceStub.class);
58+
Step next = new MockStep(null);
59+
final String SERVER_NAME = "admin-server";
60+
Packet packet =
61+
Stub.createStub(PacketStub.class)
62+
.withServerName(SERVER_NAME)
63+
.withGetKeyThrowsException(true);
64+
65+
ReadHealthWithHttpClientStep withHttpClientStep =
66+
new ReadHealthWithHttpClientStep(service, next);
67+
withHttpClientStep.apply(packet);
68+
69+
assertThat(logRecords, containsInfo(WLS_HEALTH_READ_FAILED, SERVER_NAME));
70+
}
71+
72+
@Test
73+
public void withHttpClientStep_logIfMissingHTTPClient() {
5574
V1Service service = Stub.createStub(V1ServiceStub.class);
5675
Step next = new MockStep(null);
5776
final String SERVER_NAME = "admin-server";
@@ -61,29 +80,31 @@ public void withHttpClientStep_Health_logIfFailed() {
6180
new ReadHealthWithHttpClientStep(service, next);
6281
withHttpClientStep.apply(packet);
6382

64-
assertThat(logRecords, containsFine(WLS_HEALTH_READ_FAILED, SERVER_NAME));
83+
assertThat(logRecords, containsInfo(WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT, SERVER_NAME));
6584
}
6685

6786
abstract static class PacketStub extends Packet {
6887

69-
Integer retryCount;
7088
String serverName;
89+
boolean getKeyThrowsException;
7190

72-
PacketStub withServerName(String serverName) {
73-
this.serverName = serverName;
91+
PacketStub withGetKeyThrowsException(boolean getKeyThrowsException) {
92+
this.getKeyThrowsException = getKeyThrowsException;
7493
return this;
7594
}
7695

77-
PacketStub addSpi(Class clazz, Object spiObject) {
78-
Component component = Component.createFor(spiObject);
79-
this.getComponents().put(clazz.getName(), component);
96+
PacketStub withServerName(String serverName) {
97+
this.serverName = serverName;
8098
return this;
8199
}
82100

83101
@Override
84102
public Object get(Object key) {
85103
if (HttpClient.KEY.equals(key)) {
86-
throw CLASSCAST_EXCEPTION; // to go to catch clause in WithHttpClientStep.apply() method
104+
if (getKeyThrowsException) {
105+
throw CLASSCAST_EXCEPTION; // to go to catch clause in WithHttpClientStep.apply() method
106+
}
107+
return null;
87108
} else if (ProcessingConstants.SERVER_NAME.equals(key)) {
88109
return serverName;
89110
}

0 commit comments

Comments
 (0)