prometheus / client_java

Prometheus instrumentation library for JVM applications
http://prometheus.github.io/client_java/
Apache License 2.0
2.18k stars 798 forks source link

MapperConfig does not allow : in regex #645

Open muuki88 opened 3 years ago

muuki88 commented 3 years ago

Hi,

Thanks for the custom mapper config on the dropwizard export. It makes creating tags really easy :heart:

I found a restriction in the regex that makes it impossible for me to create a certain configuration. : are not allowed and we have metrics that contain ip:port in the metric name.

https://github.com/prometheus/client_java/blob/29dfd0a2bf9b93282764d31447b843a1d36d4f10/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/samplebuilder/MapperConfig.java#L25

This is what the mapper config would look like

// this port is dynamically set from the outside
final int httpPort = 8080
final MapperConfig vertxServerHttp = new MapperConfig(
     // the IP address is always 0.0.0.0
    "vertx.http.servers.0.0.0.0:" + httpPort + ".*", "vertx.http.servers.${4}",
     ImmutableMap.of("endpoint", "http")
);

So the metric currentely ends up like this in prometheus

vertx_http_servers_0_0_0_0:8080_metric

which gets messy as ports change.

Suggestion

Add : to the global regex.

I don't know what implications this would have

fstab commented 3 years ago

Sorry for the delay. I put this on my TODO list, but I would like to get Exemplars done first before I look into Dropwizard. I will get back to this issue.

muuki88 commented 3 years ago

No worries :heart: I would open a pull request with this feature if it helps you and there's a chance this can get merged :smile: