Skip to content

Commit

Permalink
e2emonitoring: Adding support for custom registry. (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: Bartlomiej Plotka <[email protected]>
  • Loading branch information
bwplotka authored Apr 14, 2022
1 parent cd47243 commit 77debfd
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions monitoring/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (l *listener) OnRunnableChange(started []e2e.Runnable) error {

type opt struct {
scrapeInterval time.Duration
customRegistry *prometheus.Registry
}

// WithScrapeInterval changes how often metrics are scrape by Prometheus. 5s by default.
Expand All @@ -126,6 +127,15 @@ func WithScrapeInterval(interval time.Duration) func(*opt) {
}
}

// WithCustomRegistry allows injecting a custom registry to use for this process metrics.
// NOTE(bwplotka): Injected registry will be used as is, while the default registry
// will have prometheus.NewGoCollector() and prometheus.NewProcessCollector(..) registered.
func WithCustomRegistry(reg *prometheus.Registry) func(*opt) {
return func(o *opt) {
o.customRegistry = reg
}
}

type Option func(*opt)

// Start deploys monitoring service which deploys Prometheus that monitors all registered InstrumentedServices
Expand All @@ -137,11 +147,14 @@ func Start(env e2e.Environment, opts ...Option) (_ *Service, err error) {
}

// Expose metrics from the current process.
metrics := prometheus.NewRegistry()
metrics.MustRegister(
collectors.NewGoCollector(),
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
)
metrics := opt.customRegistry
if metrics == nil {
metrics = prometheus.NewRegistry()
metrics.MustRegister(
collectors.NewGoCollector(),
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
)
}

m := http.NewServeMux()
h := promhttp.HandlerFor(metrics, promhttp.HandlerOpts{})
Expand Down

0 comments on commit 77debfd

Please sign in to comment.