open-telemetry / prometheus-interoperability-spec

Workgroup for building Prometheus-OTLP interoperability for the OTEL Collector and Prometheus related discussions.
Apache License 2.0
41 stars 6 forks source link

Prometheus Receiver UI for Viewing Targets/Service Discovery/Config #63

Open gracewehner opened 3 years ago

gracewehner commented 3 years ago

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: targets (2)

service-discovery (3)

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:

dashpole commented 3 years ago

It is similar in concept to zpages, but for prometheus metrics. Having it as an extension like zpages would be nice for decoupling, but looking at the zpages extension, it isn't actually very decoupled, since it is mostly implemented by the service itself, rather than the extension.

I'd lean towards using as much of the upstream prometheus code as we can. It may also be possible to request small changes in upstream prometheus if that would make things much easier for us.

juliusv commented 3 years ago

Hi! @roidelapluie helpfully pointed me at this issue.

Just to let you know, there are two implementations of the UI in Prometheus:

gracewehner commented 3 years ago

Thanks @juliusv! I have it working with the React UI now with the same code as above that's using the Prometheus web package. Is there a place where the UI reusability work is tracked or a design proposal? I'd be happy to help with contributing this.

juliusv commented 3 years ago

@gracewehner We don't have a properly tracked effort for it yet on the Prometheus side, as it's more of a loose aspiration of a couple of folks so far who are too distracted by other stuff as well :) Thanos did touch on this a bit in https://github.com/thanos-io/thanos/issues/2198 because it would make sense to reuse components there.

However, @Nexucis already laid some of the groundwork in Prometheus recently by breaking up the single React app into a multi-module structure all within the same repo (all living under https://github.com/prometheus/prometheus/tree/main/web/ui). The only module that is broken out so far is the PromQL text editor support code, but ultimately it could make sense to break out other reusable components in a similar way, so that external consumers like Thanos, Cortex, the Prometheus Receiver, etc. can just "plug together" a partial Prometheus UI that fits their needs. TBH I haven't fully thought through all the implications of that yet in terms of maintainability, reusability, and so on, so I guess this project is looking for someone to lead it :)

Nexucis commented 3 years ago

breaking up the single React

so accurate haha.

joke appart, I'm currently looking to good a candidate that will ultimately validate this new model. codemirror-promql was a special case that cannot be really followed for other potentiel components.

I proposed to start with the Graph page here: https://github.com/prometheus/prometheus/issues/8685. But perhaps it's not the best candidate.

Like by looking at this issue, perhaps sharing the way to display the targets could be more interesting. (and let's be crazy, it could be the good opportunity to tackle the optimization issues around this page)

philchia commented 1 year ago

Is there any updates here?

cforce commented 8 months ago

Seem like the failed test from https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/23244 need to be fixed + approval and as well the MR https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/29622 need reopen/rebase and testing.