Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discussion: kprom improvement, following collector pattern #914

Open
loginakhil opened this issue Feb 21, 2025 · 2 comments
Open

discussion: kprom improvement, following collector pattern #914

loginakhil opened this issue Feb 21, 2025 · 2 comments
Labels
plugin PRs related to plugins waiting

Comments

@loginakhil
Copy link

Hello there,

Thank you for your hard work in implementing such an awesome library.

Upon exploring kprom, I noticed that this module implements the Prometheus collector differently.
Instead of implementing a Prometheus collector like below:

// NewCustomCollector creates a new CustomCollector
func NewCustomCollector() *CustomCollector {
	counter := prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "my_custom_counter",
			Help: "A custom counter for demonstration purposes",
		},
		[]string{"label"},
	)

	prometheus.MustRegister(counter)

	return &CustomCollector{
		counter: counter,
	}
}

// Collect implements the Collector interface
func (c *CustomCollector) Collect(ch chan<- prometheus.Metric) {
	// Simulate some metrics
	c.counter.WithLabelValues("example").Inc()
	c.counter.WithLabelValues("example2").Inc()

	// Collect the metrics
	c.counter.Collect(ch)
}

// Describe implements the Collector interface
func (c *CustomCollector) Describe(ch chan<- *prometheus.Desc) {
	c.counter.Describe(ch)
}

Is there any specific reason behind this implementation style, or would you be open to approving a pull request for this modification?

@twmb
Copy link
Owner

twmb commented Mar 7, 2025

What's the benefit of a change?

@twmb twmb added waiting plugin PRs related to plugins labels Mar 7, 2025
@loginakhil
Copy link
Author

This will allow applications that use kprom to register multiple collectors to the same registry by inversing the dependency.
We will then be following the recommended approach of collector implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin PRs related to plugins waiting
Projects
None yet
Development

No branches or pull requests

2 participants