Open Tiernan-Stapleton opened 3 years ago
Thanks for reporting. What if you just create one PromClientInterceptor()
and use that instance to intercept the channel?
Unfortunately that isn't possible in my use case. I'm using multiple gRPC connections to different services, each which require their own instance of the PromClientInterceptor()
. Since v0.6, whenever I run my code, the second gRPC service connection will fail to initialise with the error above.
What I am suggesting is make a single instance of "PromClientInterceptor", then you can used it in multiple clients.
.e.g.
PROM_CLIENT_INTERCEPTOR = PromClientInterceptor()) a = grpc.intercept_channel(PROM_CLIENT_INTERCEPTOR) b = grpc.intercept_channel(PROM_CLIENT_INTERCEPTOR)
Would that work?
That will work, however my issue with it as a solution is that that is a non-standard way to implement an interceptor with prometheus. Also, there is nothing stopping someone else coming across the same issue as I have. Moving the metrics definition back to the file level solves the problem, and allows both of these ways to define an interceptor to be usable.
I can open a PR making the required changes to fix this issue when I get the time over the next few days, if changing the metric definitions back to file level is OK with you?
+1, I ran into this error as well.
The latest version v0.6.0 is raising the following error by
prometheus_client/registry.py
, when using thePromClientInterceptor()
"ValueError: Duplicated timeseries in CollectorRegistry: {'grpc_client_started_created', 'grpc_client_started', 'grpc_client_started_total'}"
I think I've narrowed down the issue to being a side effect of changes from https://github.com/lchenn/py-grpc-prometheus/pull/21, specifically https://github.com/lchenn/py-grpc-prometheus/pull/21/files#diff-04b7eb91d0278b63925e45233c6beffcf6d3f4acb166c847d08982268c8cf111L4 where the metrics are changed from being defined at the file level to being defined per interceptor instance via
init_metrics()
. This is causing duplication of metrics registration when thePromClientInterceptor
is defined multiple times to intercept different GRPC calls.I've included a simple test which reproduces the error:
when run