Start deploys monitoring service which deploys Prometheus that monitors all InstrumentedRunnable instances in an environment created with AsInstrumented.
(env e2e.Environment, opts ...Option)
| 232 | // Start deploys monitoring service which deploys Prometheus that monitors all |
| 233 | // InstrumentedRunnable instances in an environment created with AsInstrumented. |
| 234 | func Start(env e2e.Environment, opts ...Option) (_ *Service, err error) { |
| 235 | opt := opt{ |
| 236 | scrapeInterval: 5 * time.Second, |
| 237 | useCadvisor: true, |
| 238 | } |
| 239 | for _, o := range opts { |
| 240 | o(&opt) |
| 241 | } |
| 242 | |
| 243 | // Expose metrics from the current process. |
| 244 | metrics := opt.customRegistry |
| 245 | if metrics == nil { |
| 246 | metrics = prometheus.NewRegistry() |
| 247 | metrics.MustRegister( |
| 248 | collectors.NewGoCollector(), |
| 249 | collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}), |
| 250 | ) |
| 251 | } |
| 252 | |
| 253 | m := http.NewServeMux() |
| 254 | h := promhttp.HandlerFor(metrics, promhttp.HandlerOpts{}) |
| 255 | o := sync.Once{} |
| 256 | scraped := make(chan struct{}) |
| 257 | m.Handle("/metrics", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { |
| 258 | o.Do(func() { close(scraped) }) |
| 259 | h.ServeHTTP(w, req) |
| 260 | })) |
| 261 | |
| 262 | // Listen on all addresses, since we need to connect to it from docker container. |
| 263 | list, err := net.Listen("tcp", "0.0.0.0:0") |
| 264 | if err != nil { |
| 265 | return nil, err |
| 266 | } |
| 267 | s := http.Server{Handler: m} |
| 268 | |
| 269 | go func() { _ = s.Serve(list) }() |
| 270 | env.AddCloser(func() { _ = s.Close() }) |
| 271 | |
| 272 | p := NewPrometheus(env, "monitoring", opt.customPromImage, nil) |
| 273 | |
| 274 | _, port, err := net.SplitHostPort(list.Addr().String()) |
| 275 | if err != nil { |
| 276 | return nil, err |
| 277 | } |
| 278 | l := &listener{p: p, localAddr: net.JoinHostPort(env.HostAddr(), port), scrapeInterval: opt.scrapeInterval} |
| 279 | if err := l.updateConfig(map[string]Instrumented{}); err != nil { |
| 280 | return nil, err |
| 281 | } |
| 282 | env.AddListener(l) |
| 283 | |
| 284 | if opt.useCadvisor { |
| 285 | c := newCadvisor(env, "cadvisor") |
| 286 | if err := e2e.StartAndWaitReady(c); err != nil { |
| 287 | return nil, errors.Wrap(err, "starting cadvisor and waiting until ready") |
| 288 | } |
| 289 | } |
| 290 | if err := e2e.StartAndWaitReady(p); err != nil { |
| 291 | return nil, errors.Wrap(err, "starting monitoring and waiting until ready") |
nothing calls this directly
no test coverage detected
searching dependent graphs…