Patch looks pretty good —Final things needed:
better error reporting/diagnostics on the socket exceptions than the JRE gives you; this is done in NetUtils.wrapException()
Could you wrap the code which creates the DatagramSocket or writes to it with something like:
// network operation
throw NetUtils.wrapException(destHost, destPort, localHost, 0, ioe)
It's not quite so important/useful for datagrams, but it will still report better outcomes binding to the local host, looking up the hostname of the destination, etc, etc.
writeMetric loses the exception raised on a write failure.
It logs it at error, then it attempts a statsd.close(), which will raise an error if it fails, but the original exception gets lost.
- catch IOException only.
- assuming the inner StatsD class has done the exception wrapping, no more needs to be done except convert to a MetricsException through something like throw new MetricsException(ioe.toString(), ioe)
Use "." instead of "_" in keys.
This is just because its the convention in the hadoop config options; makes it more consistent with the others.
in the StatsD.close() operation, have socket=null in a finally clause. That way even if the inner socket.close() failed, the socket reference would be released & the code not reused.