MCPcopy
hub / github.com/grafana/dskit / New

Function New

runtimeconfig/manager.go:91–137  ·  view source on GitHub ↗

New creates an instance of Manager. Manager is a services.Service, and must be explicitly started to perform any work.

(cfg Config, configName string, registerer prometheus.Registerer, logger log.Logger)

Source from the content-addressed store, hash-verified

89
90// New creates an instance of Manager. Manager is a services.Service, and must be explicitly started to perform any work.
91func New(cfg Config, configName string, registerer prometheus.Registerer, logger log.Logger) (*Manager, error) {
92 if len(cfg.LoadPath) == 0 {
93 return nil, errors.New("LoadPath is empty")
94 }
95
96 // The cluster-validation counter shares its name with similarly-named counters from other
97 // client-side cluster-validation reporters in the calling application (e.g. gRPC clients), so
98 // its label set must match theirs: {client, protocol, method}, with no per-manager "config"
99 // label. We therefore pass an un-wrapped registerer to httpTransport and disambiguate per
100 // manager via the "client" label value (set to "runtime-config/<configName>").
101 clusterValidationRegisterer := registerer
102 registerer = prometheus.WrapRegistererWith(prometheus.Labels{"config": configName}, registerer)
103
104 mgr := Manager{
105 cfg: cfg,
106 configLoadSuccess: promauto.With(registerer).NewGauge(prometheus.GaugeOpts{
107 Name: "runtime_config_last_reload_successful",
108 Help: "Whether the last runtime-config reload attempt was successful.",
109 }),
110 configHash: promauto.With(registerer).NewGaugeVec(prometheus.GaugeOpts{
111 Name: "runtime_config_hash",
112 Help: "Hash of the currently active runtime configuration, merged from all configured files.",
113 }, []string{"sha256"}),
114 logger: logger,
115 }
116
117 var httpClient *http.Client
118 var httpDuration *prometheus.HistogramVec
119 for _, p := range cfg.LoadPath {
120 if isURL(p) {
121 if httpClient == nil {
122 timeout := cfg.HTTPClientTimeout
123 if timeout == 0 {
124 timeout = 30 * time.Second
125 }
126 httpClient = &http.Client{Timeout: timeout, Transport: httpTransport(cfg, configName, clusterValidationRegisterer, logger)}
127 httpDuration = newHTTPRequestDuration(registerer)
128 }
129 mgr.providers = append(mgr.providers, newHTTPProvider(p, httpClient, httpDuration))
130 } else {
131 mgr.providers = append(mgr.providers, newFileProvider(p))
132 }
133 }
134
135 mgr.Service = services.NewBasicService(mgr.starting, mgr.loop, mgr.stopping)
136 return &mgr, nil
137}
138
139func (om *Manager) starting(ctx context.Context) error {
140 if len(om.cfg.LoadPath) == 0 {

Calls 7

NewBasicServiceFunction · 0.92
isURLFunction · 0.85
httpTransportFunction · 0.85
newHTTPRequestDurationFunction · 0.85
newHTTPProviderFunction · 0.85
newFileProviderFunction · 0.85
WithMethod · 0.80