endclothing / prometheus_client_php

Prometheus instrumentation library for PHP applications
https://prometheus.io/docs/concepts/metric_types/
Apache License 2.0
150 stars 79 forks source link

Ability to inject Redis client in redis storage #7

Closed martinssipenko closed 4 years ago

martinssipenko commented 5 years ago

Rigth now \Redis client is constructed within __construct method of Prometheus\Storage\Redis class. What thoughts do you have on adding ability to inject \Redis into storage class? This would allow to reuse already existing connection from framework.

I'm happy to contribute the code change if/when it's decided to do it and what would be the best approach to do it.

NoelDavies commented 5 years ago

I'm down for that if others are open to it - the only thing is it's a huge method signature change and would not be backwards compat. So we'd have to solve this in one of the following ways (open to others, these are just the ideas I can see):

martinssipenko commented 5 years ago

I personally like the names constructor option. Let me try it out and I'll send some code your way when I have something to show.

martinssipenko commented 5 years ago

Just noticed that $this->openConnection(); is being called in all methods. This would gave to change in case Redis is injected as the connection would have been established already.

I see two options here:

WDYT?

martinssipenko commented 5 years ago

Here is a draft PR: https://github.com/endclothing/prometheus_client_php/pull/8

NoelDavies commented 5 years ago

The existing connection would still have to be injected, but nice find!

martinssipenko commented 4 years ago

Closed by #8