Skip to content

Commit 9ef486a

Browse files
authored
Merge pull request #815 from oracle/suppress-exceptions
Suppress exceptions in operator log
2 parents 86d777c + 95a519f commit 9ef486a

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

operator/src/main/java/oracle/kubernetes/operator/Main.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
import io.kubernetes.client.models.V1PodList;
1111
import io.kubernetes.client.models.V1Service;
1212
import io.kubernetes.client.models.V1ServiceList;
13+
import java.io.FileOutputStream;
1314
import java.io.IOException;
1415
import java.io.InputStream;
16+
import java.io.OutputStream;
17+
import java.io.PrintStream;
1518
import java.util.ArrayList;
1619
import java.util.Collection;
1720
import java.util.HashSet;
@@ -34,6 +37,7 @@
3437
import oracle.kubernetes.operator.helpers.CRDHelper;
3538
import oracle.kubernetes.operator.helpers.CallBuilder;
3639
import oracle.kubernetes.operator.helpers.CallBuilderFactory;
40+
import oracle.kubernetes.operator.helpers.ClientPool;
3741
import oracle.kubernetes.operator.helpers.ConfigMapHelper;
3842
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
3943
import oracle.kubernetes.operator.helpers.HealthCheckHelper;
@@ -89,6 +93,13 @@ public Thread newThread(Runnable r) {
8993

9094
static {
9195
try {
96+
// suppress System.err since we catch all necessary output with Logger
97+
OutputStream output = new FileOutputStream("/dev/null");
98+
PrintStream nullOut = new PrintStream(output);
99+
System.setErr(nullOut);
100+
101+
ClientPool.initialize(threadFactory);
102+
92103
TuningParameters.initializeInstance(wrappedExecutorService, "/operator/config");
93104
tuningAndConfig = TuningParameters.getInstance();
94105
} catch (IOException e) {

operator/src/main/java/oracle/kubernetes/operator/helpers/ClientPool.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
package oracle.kubernetes.operator.helpers;
66

7+
import com.squareup.okhttp.Dispatcher;
78
import io.kubernetes.client.ApiClient;
89
import io.kubernetes.client.Configuration;
910
import io.kubernetes.client.util.Config;
1011
import java.io.IOException;
12+
import java.util.concurrent.ExecutorService;
13+
import java.util.concurrent.SynchronousQueue;
14+
import java.util.concurrent.ThreadFactory;
15+
import java.util.concurrent.ThreadPoolExecutor;
16+
import java.util.concurrent.TimeUnit;
1117
import java.util.concurrent.atomic.AtomicBoolean;
1218
import oracle.kubernetes.operator.logging.LoggingFacade;
1319
import oracle.kubernetes.operator.logging.LoggingFactory;
@@ -18,9 +24,28 @@
1824
public class ClientPool extends Pool<ApiClient> {
1925
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
2026
private static ClientPool SINGLETON = new ClientPool();
27+
private static ThreadFactory threadFactory;
2128

2229
private static final ClientFactory FACTORY = new DefaultClientFactory();
2330

31+
public static void initialize(ThreadFactory threadFactory) {
32+
ClientPool.threadFactory = threadFactory;
33+
}
34+
35+
private static Runnable wrapRunnable(Runnable r) {
36+
return new Runnable() {
37+
@Override
38+
public void run() {
39+
try {
40+
r.run();
41+
} catch (Throwable t) {
42+
// These will almost always be spurious exceptions
43+
LOGGER.finer(MessageKeys.EXCEPTION, t);
44+
}
45+
}
46+
};
47+
}
48+
2449
public static ClientPool getInstance() {
2550
return SINGLETON;
2651
}
@@ -71,6 +96,24 @@ public ApiClient get() {
7196
if (first.getAndSet(false)) {
7297
Configuration.setDefaultApiClient(client);
7398
}
99+
100+
if (threadFactory != null) {
101+
ExecutorService exec =
102+
new ThreadPoolExecutor(
103+
0,
104+
Integer.MAX_VALUE,
105+
60,
106+
TimeUnit.SECONDS,
107+
new SynchronousQueue<Runnable>(),
108+
threadFactory) {
109+
@Override
110+
public void execute(Runnable command) {
111+
super.execute(wrapRunnable(command));
112+
}
113+
};
114+
client.getHttpClient().setDispatcher(new Dispatcher(exec));
115+
}
116+
74117
return client;
75118
} catch (IOException e) {
76119
throw new RuntimeException(e);

operator/src/main/java/oracle/kubernetes/operator/helpers/FileGroupReader.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class JarScriptPath implements ScriptPath {
117117
private FileSystem fileSystem;
118118

119119
JarScriptPath(URI uri) throws IOException {
120-
System.out.println("loading from " + uri);
121120
fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
122121
}
123122

src/scripts/logstash.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
.level=INFO
1+
.level=WARNING
2+
Operator.level=INFO
23
handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler
34
java.util.logging.ConsoleHandler.level=INFO
45
java.util.logging.ConsoleHandler.formatter=oracle.kubernetes.operator.logging.LoggingFormatter

src/scripts/operator.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
33
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
44

5-
set -x
6-
75
export PATH=$PATH:/operator
86

97
echo "Launching Oracle WebLogic Server Kubernetes Operator..."
@@ -52,7 +50,7 @@ if [[ ! -z "$JAVA_LOGGING_LEVEL" ]]; then
5250
[ $JAVA_LOGGING_LEVEL != $FINEST ]; then
5351
echo "WARNING: Ignoring invalid JAVA_LOGGING_LEVEL: \"${JAVA_LOGGING_LEVEL}\". Valid values are $SEVERE, $WARNING, $INFO, $CONFIG, $FINE, $FINER and $FINEST."
5452
else
55-
sed -i -e "s|\(.*\.level=\).*|\1${JAVA_LOGGING_LEVEL}|g" $LOGGING_CONFIG
53+
sed -i -e "s|INFO|${JAVA_LOGGING_LEVEL}|g" $LOGGING_CONFIG
5654
fi
5755
fi
5856

0 commit comments

Comments
 (0)