Skip to content

.label() Method throws Exceptions #342

Open
@Tigraine

Description

@Tigraine

Apparently if labels are missing or a null value is supplied to a label the prometheus client will throw a IllegalArgumentException.

Exceptions being thrown on the "hot" path with null values in labels are a problem as they either require me to add try/catch logic around my monitoring code or decorate the whole prometheus client with try/catch blocks.

IMO there are a ton of instances where you might have a label that is not compile-time supplied (I know in most examples it's the HTTP method being passed).
But for a lot of cases it could be something like a AWS Region-ID or a Cluster-ID or a machine name or endpoint name etc..
Not saying that any of these values being null is a good thing, but errors happen sometimes and especially when you are dealing with legacy systems these things are commonplace.
Having code break in very unexpected ways because prometheus complains about it's arguments is really really problematic.

The offending code in the client is here:
https://github.com/prometheus/client_java/blob/master/simpleclient/src/main/java/io/prometheus/client/SimpleCollector.java#L64-L68

Is there any policy on metrics? Because in my book metrics/logging should be totally transparent and never require any additional logic. If I can't call the prometheus client with absolute certainty that it won't break my code under ANY circumstances I'm hesitant to include it as I am opening myself up to another level of complexity (and all of this suddenly needs testing etc).

Imo it's preferable to have missing labels be mis-reported as empty string and the client being 100% runtime safe than having a operation fail because some parameter was not correctly checked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions