Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphiteReporter should reconnect when connection fails temporarily #694

Closed
jsyrjala opened this issue Oct 22, 2014 · 14 comments
Closed

GraphiteReporter should reconnect when connection fails temporarily #694

jsyrjala opened this issue Oct 22, 2014 · 14 comments
Assignees

Comments

@jsyrjala
Copy link
Contributor

With Metrics 3.1.0 GraphiteReporter we had a problem where data was no longer sent to graphite server. This happened after some network component was rebooted. Same server is sending data also with Metrics 2.1.3 GraphiteReporter. Older graphite reporters kept on sending data just fine.

Sounds like this could be related to #607.

Stacktrace from 3.1.0:

2014-10-22 12:00:21,036 [WARN] [] [] com.codahale.metrics.graphite.GraphiteReporter.report(GraphiteReporter.java:179) Unable to report to Graphite: java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
        at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
        at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
        at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
        at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
        at java.io.BufferedWriter.write(BufferedWriter.java:230)
        at java.io.Writer.write(Writer.java:157)
        at com.codahale.metrics.graphite.Graphite.send(Graphite.java:130)
        at com.codahale.metrics.graphite.GraphiteReporter.reportGauge(GraphiteReporter.java:270)
        at com.codahale.metrics.graphite.GraphiteReporter.report(GraphiteReporter.java:158)
        at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)
        at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
 : java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
        at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
        at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
        at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
        at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
        at java.io.BufferedWriter.write(BufferedWriter.java:230)
        at java.io.Writer.write(Writer.java:157)
        at com.codahale.metrics.graphite.Graphite.send(Graphite.java:130)
        at com.codahale.metrics.graphite.GraphiteReporter.reportGauge(GraphiteReporter.java:270)
        at com.codahale.metrics.graphite.GraphiteReporter.report(GraphiteReporter.java:158)
        at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)
        at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

2014-10-22 12:00:21,037 [WARN] [] [] com.codahale.metrics.graphite.GraphiteReporter.report(GraphiteReporter.java:183) Error closing Graphite: java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
        at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
        at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
        at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
        at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
        at java.io.BufferedWriter.write(BufferedWriter.java:230)
        at java.io.Writer.write(Writer.java:157)
        at com.codahale.metrics.graphite.Graphite.send(Graphite.java:130)
        at com.codahale.metrics.graphite.GraphiteReporter.reportGauge(GraphiteReporter.java:270)
        at com.codahale.metrics.graphite.GraphiteReporter.report(GraphiteReporter.java:158)
        at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)
        at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
 : java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
        at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
        at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
        at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
        at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
        at java.io.BufferedWriter.write(BufferedWriter.java:230)
        at java.io.Writer.write(Writer.java:157)
        at com.codahale.metrics.graphite.Graphite.send(Graphite.java:130)
        at com.codahale.metrics.graphite.GraphiteReporter.reportGauge(GraphiteReporter.java:270)
        at com.codahale.metrics.graphite.GraphiteReporter.report(GraphiteReporter.java:158)
        at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)
        at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
@jsyrjala
Copy link
Contributor Author

Related code is below. Seems that close() on socket fails, and then the reconnect logic doesn't notice that reconnection should be made.

GraphiteReporter.java:

    @Override
    public void report(SortedMap<String, Gauge> gauges,
                       SortedMap<String, Counter> counters,
                       SortedMap<String, Histogram> histograms,
                       SortedMap<String, Meter> meters,
                       SortedMap<String, Timer> timers) {
        final long timestamp = clock.getTime() / 1000;

        // oh it'd be lovely to use Java 7 here
        try {
            if (!graphite.isConnected()) {
                  graphite.connect();
            }

            for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
                reportGauge(entry.getKey(), entry.getValue(), timestamp);
            }

            for (Map.Entry<String, Counter> entry : counters.entrySet()) {
                reportCounter(entry.getKey(), entry.getValue(), timestamp);
            }

            for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
                reportHistogram(entry.getKey(), entry.getValue(), timestamp);
            }

            for (Map.Entry<String, Meter> entry : meters.entrySet()) {
                reportMetered(entry.getKey(), entry.getValue(), timestamp);
            }

            for (Map.Entry<String, Timer> entry : timers.entrySet()) {
                reportTimer(entry.getKey(), entry.getValue(), timestamp);
            }

            graphite.flush();
        } catch (IOException e) {
            LOGGER.warn("Unable to report to Graphite", graphite, e);
            try {
                graphite.close();
            } catch (IOException e1) {
                LOGGER.warn("Error closing Graphite", graphite, e);
            }
        }
    }

``

@velvia
Copy link

velvia commented Oct 24, 2014

I'm also experiencing this same error.

@velvia
Copy link

velvia commented Oct 24, 2014

I can verify that dropping back to 3.0.2 fixes this issue, so the bug appears to be around that isConnected().

@jsyrjala
Copy link
Contributor Author

#675 and #669 may be related or the same issue.

@velvia
Copy link

velvia commented Oct 25, 2014

True, hope to test this out sometime.

On Fri, Oct 24, 2014 at 1:51 PM, Juha Syrjälä notifications@github.com
wrote:

#675 #675 may be related or
the same issue.


Reply to this email directly or view it on GitHub
#694 (comment).

The fruit of silence is prayer;
the fruit of prayer is faith;
the fruit of faith is love;
the fruit of love is service;
the fruit of service is peace. -- Mother Teresa

@v-garki
Copy link
Contributor

v-garki commented Oct 27, 2014

Indeed, this is the same issue we experienced and reported in #669. Until 3.1.1 is released a possible workaround is to use a modified Graphite class which contains the fix like we did.

@ryantenney
Copy link
Contributor

Closed as fixed in #669, and 3.1.1 will be out very soon.

@posto
Copy link

posto commented Dec 23, 2014

@ryantenney, any plans to release 3.1.1 ? I'd love to upgrade from 3.0 to 3.1, without the risk of loosing metric data :)

@mfoo
Copy link

mfoo commented Jan 21, 2015

+1 on a release of this fix. Is there any ETA?

In the meantime, is it feasible to roll back to 3.0.2 as suggested by @velvia without losing important changes? I don't see a changelog anywhere.

@jwhitlark
Copy link
Contributor

+1 on 3.1.1 release. Any timeline? This is causing us issues in production...

@AlexeyZalivko
Copy link

+1. When it will be fixed??? Guys do this simple fix - make us happier

@jshook
Copy link

jshook commented Feb 26, 2015

@ryantenney
Can you clarify what 'very soon' means, from "Closed as fixed in #669, and 3.1.1 will be out very soon."

@jshook
Copy link

jshook commented Mar 7, 2015

@ryantenney Can you re-open this issue? As it is, I can not add dependencies to this project/version from mine. It is just broken for graphite use. 3.1.1 has not seen the light of day, and 4.0 may not be here for awhile yet.

@ryantenney
Copy link
Contributor

@jshook I just pushed 3.1.1 to Maven Central, check for it an hour or two. I'm sorry for the delay, a lot of things have been getting in the way.

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

No branches or pull requests

9 participants