Prometheus Receiver UI for Viewing Targets/Service Discovery/Config #63
Description
Currently, authoring scrape configs or debugging issues with scrape configs can be difficult and has a learning curve using just the debug logs of the prometheus receiver.
Prometheus has a web UI with the pages Targets, Service Discovery, and Configuration for this:
This UI uses html templates with the data filled by calling the scrape manager's functions. The prometheus receiver is using the same scrape manager in metrics_receiver.go, so the same functions to get the same data can be called to have an optional, similar UI.
A config option can be added for the prometheus receiver to enable hosting the UI as a local endpoint. The code that enables this would be in the Start() function of metrics_receiver.go, where the scrapeManager is created and run:
webOptions := web.Options{
ScrapeManager: scrapeManager,
Context: ctxWeb,
ListenAddress: ":9090",
ExternalURL: &url.URL{
Scheme: "http",
Host: "localhost:9090",
Path: "",
},
RoutePrefix: "/",
ReadTimeout: time.Second * 30,
PageTitle: "Prometheus Receiver",
Version: &web.PrometheusVersion{
Version: version.Version,
Revision: version.Revision,
Branch: version.Branch,
BuildUser: version.BuildUser,
BuildDate: version.BuildDate,
GoVersion: version.GoVersion,
},
MaxConnections: 5,
}
webHandler := web.New(go_kit_logger, &webOptions)
listener, err := webHandler.Listener()
if err != nil {
return errors.Wrapf(err, "error creating listener")
}
webHandler.ApplyConfig(r.cfg.PrometheusConfig)
webHandler.Ready()
go func() {
if err := webHandler.Run(ctxWeb, listener, ""); err != nil {
return errors.Wrapf(err, "error starting web server")
}
}()
I currently have two different proof of concepts:
-
Directly using the web package of the Prometheus repo, creating the webHandler, passing it the configuration options including the scrapeManager, and running it. The only code changes needed would be something similar to above.
The issues with this approach are that:
- The pages for Alerts, Graph, Rules, etc. won't apply in this situation and won't load any information.
- The html templates and static files would need to be present in the working directory where the opentelemetry-collector executable is actually run because:
- Prometheus generates a golang file that has the file system at build time: https://github.com/prometheus/prometheus/blob/main/Makefile#L53-L59 https://github.com/prometheus/prometheus/blob/main/web/ui/assets_generate.go. https://github.com/prometheus/prometheus/blob/main/web/web.go#L371.
However, this file isn't available by using the UI package, so generating it ourselves would still require a change in the code since the web package will point to this Assets() function instead: https://github.com/prometheus/prometheus/blob/5a4c3734b10cccecdd17c8c4c3a43e0e1ee77466/web/ui/ui.go#L31
-
Creating a new folder called web in the prometheusreceiver folder, copying over most of the golang code and html/css/js files but customizing the code to fix the above issues by:
- Changing the code so that only including the Target, Service Discovery, and Configuration pages are served and shown on the webpage
- Changing the code to embed the html templates and static files so that they can be built in with the opentelemetry collector executable.
However this means that a lot of the same code from the prometheus web package is copied over, including the html/css/js files.