niebes/retrofit-plugins

Invalid number of tags when reporting to prometheus

atomfrede opened this issue ยท 2 comments

Thanks for the nice plugin ๐Ÿ‘ I think there is a bug when using this plugin and reporting to prometheus. I get the followign exception java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named 'http_client_requests_seconds' containing tag keys [async, base_url, method, series, status, uri]. The meter you are attempting to register has keys [async, base_url, exception, method, uri].

I guess the root cause is in https://github.com/niebes/retrofit-plugins/blob/master/retrofit-metrics/src/main/kotlin/net/niebes/retrofit/metrics/RetrofitCallMetricsCollector.kt which has different labels for the exceptional and successful case which use the same metric name. Not sure if other metrics systems have the same limitation but as prometheus is widely used it should work out of box.

I think spring webmcv exposed an exception tag with value None in case there was no exception. I could provide a PR for that if you agree this is a bug.

EDIT: Seems it was removed on purpose: 698022b

Hey, thanks for reporting this bug.

looking back at #84 I remember there are three tags affected here. A success additionally contains status and series, while an exception contains the tag exception.
Now I had to choose whether to provide either e default value for both status and series or to remove exception instead.

This should be fixed with #139
Let me know whether that is what you expect.

Best

Thanks @niebes! Looks good, basically what I would have done and it's aligned with e.g. the spring behaviour.