apache / apache/pulsar-client-go
Use dependency injection for metrics
- Dominant language
- Go
- Stars
- 745
- Forks
- 389
- Avg merge
- 3d 20h
- Merged PRs (30d)
- 3
Description
**Is your feature request related to a problem? Please describe.**
Currently `promauto.NewCounter`, `promauto.NewGauge`, etc are used in such way:
```go
var (
consumersOpened = promauto.NewCounter(prometheus.CounterOpts{
Name: "pulsar_client_consumers_opened",
Help: "Counter of consumers created by the client",
})
consumersClosed = promauto.NewCounter(prometheus.CounterOpts{
Name: "pulsar_client_consumers_closed",
Help: "Counter of consumers closed by the client",
})
consumersPartitions = promauto.NewGauge(prometheus.GaugeOpts{
Name: "pulsar_client_consumers_partitions_active",
Help: "Counter of individual partitions the consumers are currently active",
})
)
```
There are several problems with such approach:
1. Using `prometheus.DefaultRegisterer`
2. Using global variables
**Describe the solution you'd like**
1. Add an ability to provide custom prometheus registry instance
2. Remove global variable usage in favor of dependency injection (e.g. via struct fields like logger)
Contributor guide
Research direction
Start by locating all uses of promauto.NewCounter, promauto.NewGauge, and related metrics declarations, then inspect how logger dependencies are provided through client structs. Done means callers can provide a custom Prometheus registry and metrics no longer depend on global variables or prometheus.DefaultRegisterer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, prometheus
- Domain
- observability
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100