Skip to content

Commit

Permalink
Merge pull request #4066 from jglick/quiet-JENKINS-57993
Browse files Browse the repository at this point in the history
[JENKINS-57993] Avoid printing stack traces for some common agent conditions
  • Loading branch information
oleg-nenashev committed Jun 15, 2019
2 parents e3afbdb + b4aa9d7 commit dcc395b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
8 changes: 6 additions & 2 deletions core/src/main/java/hudson/TcpSlaveAgentListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.SocketAddress;
import java.util.Arrays;
import jenkins.AgentProtocol;

import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
Expand Down Expand Up @@ -286,7 +286,11 @@ public void run() {
// try to clean up the socket
}
} catch (IOException e) {
LOGGER.log(Level.WARNING,"Connection #"+id+" failed",e);
if (e instanceof EOFException) {
LOGGER.log(Level.INFO, "Connection #{0} failed: {1}", new Object[] {id, e});
} else {
LOGGER.log(Level.WARNING, "Connection #" + id + " failed", e);
}
try {
s.close();
} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package hudson.node_monitors;

import hudson.Functions;
import hudson.model.Computer;
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import hudson.slaves.SlaveComputer;
import jenkins.model.Jenkins;

import javax.annotation.CheckForNull;
Expand Down Expand Up @@ -93,7 +95,7 @@ protected Map<Computer, T> monitor() throws InterruptedException {
futures.put(c,ch.callAsync(cc));
}
} catch (RuntimeException | IOException e) {
LOGGER.log(WARNING, "Failed to monitor "+c.getDisplayName()+" for "+getDisplayName(), e);
error(c, e);
}
}

Expand All @@ -111,7 +113,7 @@ protected Map<Computer, T> monitor() throws InterruptedException {
try {
data.put(c,f.get(Math.max(0,end-System.currentTimeMillis()), MILLISECONDS));
} catch (RuntimeException | TimeoutException | ExecutionException x) {
LOGGER.log(WARNING, "Failed to monitor " + c.getDisplayName() + " for " + getDisplayName(), x);
error(c, x);
}
} else {
skipped.add(c);
Expand All @@ -121,6 +123,14 @@ protected Map<Computer, T> monitor() throws InterruptedException {
return new Result<>(data, skipped);
}

private void error(Computer c, Throwable x) {
if (c instanceof SlaveComputer) {
Functions.printStackTrace(x, ((SlaveComputer) c).getListener().error("Failed to monitor for " + getDisplayName()));
} else {
LOGGER.log(WARNING, "Failed to monitor " + c.getDisplayName() + " for " + getDisplayName(), x);
}
}

private static final Logger LOGGER = Logger.getLogger(AbstractAsyncNodeMonitorDescriptor.class.getName());

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jenkinsci.remoting.engine.JnlpConnectionState;

import java.io.IOException;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -181,7 +182,9 @@ public void afterChannel(@NonNull JnlpConnectionState event) {
public void channelClosed(@NonNull JnlpConnectionState event) {
final String nodeName = event.getProperty(JnlpConnectionState.CLIENT_NAME_KEY);
IOException cause = event.getCloseCause();
if (cause != null) {
if (cause instanceof ClosedChannelException) {
LOGGER.log(Level.INFO, "{0} for {1} terminated: {2}", new Object[] {Thread.currentThread().getName(), nodeName, cause});
} else if (cause != null) {
LOGGER.log(Level.WARNING, Thread.currentThread().getName() + " for " + nodeName + " terminated",
cause);
}
Expand Down

0 comments on commit dcc395b

Please sign in to comment.