diff --git a/spectator-reg-sidecar/src/main/java/com/netflix/spectator/sidecar/SidecarWriter.java b/spectator-reg-sidecar/src/main/java/com/netflix/spectator/sidecar/SidecarWriter.java index d3f928191..fe2b8f81a 100644 --- a/spectator-reg-sidecar/src/main/java/com/netflix/spectator/sidecar/SidecarWriter.java +++ b/spectator-reg-sidecar/src/main/java/com/netflix/spectator/sidecar/SidecarWriter.java @@ -65,8 +65,11 @@ static SidecarWriter create(String location) { private final String location; + private volatile boolean suppressWarnings; + SidecarWriter(String location) { this.location = location; + this.suppressWarnings = false; } abstract void writeImpl(String line) throws IOException; @@ -75,8 +78,16 @@ void write(String line) { try { LOGGER.trace("writing to {}: {}", location, line); writeImpl(line); + suppressWarnings = false; } catch (IOException e) { - LOGGER.warn("write to {} failed: {}", location, line, e); + // Some writers such as the UDP writer can be quite noisy if the sidecar is not present. + // To avoid spamming the user with warnings, they will be suppressed after a warning is + // logged. Warnings will be re-enabled if there is a successful write so that if there + // are problems with a sidecar being intermittently accessible it will still get detected. + if (!suppressWarnings) { + LOGGER.warn("write to {} failed: {}", location, line, e); + suppressWarnings = true; + } } }