client_java icon indicating copy to clipboard operation
client_java copied to clipboard

Fix NPE when label value is null

Open max-melentyev opened this issue 11 months ago • 3 comments

Hi, we faced an NPE in metrics exporter in cassandra-management-api.

WARN  [epollEventLoopGroup-6-1] 2025-01-17 07:37:13,527 DefaultChannelPipeline.java:1152 - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in th
e pipeline did not handle the exception.
java.lang.NullPointerException: null
        at io.prometheus.client.exporter.common.TextFormat.writeEscapedLabelValue(TextFormat.java:156)
        at io.prometheus.client.exporter.common.TextFormat.write004(TextFormat.java:119)
        at io.prometheus.client.exporter.common.TextFormat.writeFormat(TextFormat.java:53)
at io.k8ssandra.metrics.http.NettyServerHandler.channelRead0(NettyServerHandler.java:76)
        at io.k8ssandra.metrics.http.NettyServerHandler.channelRead0(NettyServerHandler.java:31)

It exports a lot of metrics and prometheus client doesn't add information about the particular metric that causes the exception, so it's hard to identify and fix a particular metric definition. Adding information about metric and label for all possible exceptions will require much more effort, so I think rendering nulls as empty values should be a good option instead of not rendering anything at all.

max-melentyev avatar Jan 20 '25 19:01 max-melentyev

I feel this is the wrong approach. Treating null values as empty strings can mask real issues.

dhoard avatar Jan 20 '25 22:01 dhoard

Sure, it would be great to wrap exceptions with the information about metric and label that have null values!

max-melentyev avatar Jan 21 '25 16:01 max-melentyev

I faced a similar problem and proposed https://github.com/prometheus/client_java/pull/1335.

benjaminp avatar Apr 25 '25 00:04 benjaminp