Skip to content

Fix NPE when label value is null#1265

Open
max-melentyev wants to merge 1 commit intoprometheus:mainfrom
max-melentyev:patch-1
Open

Fix NPE when label value is null#1265
max-melentyev wants to merge 1 commit intoprometheus:mainfrom
max-melentyev:patch-1

Conversation

@max-melentyev
Copy link

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.

Signed-off-by: max-melentyev <119438383+max-melentyev@users.noreply.github.com>
@dhoard
Copy link
Collaborator

dhoard commented Jan 20, 2025

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

@max-melentyev
Copy link
Author

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

@benjaminp
Copy link
Contributor

I faced a similar problem and proposed #1335.

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

This PR has been marked as stale due to 120 days of inactivity. It will be automatically closed if there is no further activity over the next 30 days.

@github-actions github-actions bot added the stale label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants