grafana/pkg/services/supportbundles/bundleregistry/service.go
Jo f9163351fd
Support bundles: Refactor registry into separate service (#62945)
* add bundle registry service to avoid dependency cycles

* move user support bundle collector to user service

* move usage stat bundle implementation to usage stats

* add info for background service

* fix remaining imports

* whitespace
2023-02-06 17:50:03 +01:00

33 lines
919 B
Go

package bundleregistry
import (
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/supportbundles"
)
// Service is the service that registers support bundle collectors.
type Service struct {
collectors map[string]supportbundles.Collector
log log.Logger
}
// NewService creates a new support bundle collector register service.
func ProvideService() *Service {
return &Service{
collectors: make(map[string]supportbundles.Collector),
log: log.New("support-bundle-collector-registry"),
}
}
func (s *Service) RegisterSupportItemCollector(collector supportbundles.Collector) {
if _, ok := s.collectors[collector.UID]; ok {
s.log.Warn("Support bundle collector with the same UID already registered", "uid", collector.UID)
}
s.collectors[collector.UID] = collector
}
func (s *Service) Collectors() map[string]supportbundles.Collector {
return s.collectors
}