-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[Prometheus Receiver] Add in setting to enable server for Prometheus UI #29622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, i'm hesitant to add this functionality to a receiver, but I understand how useful it can be. Is there a way to add this as an extension, similar to the remote tap extension? https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/remotetapextension
webOptions := web.Options{ | ||
ScrapeManager: r.scrapeManager, | ||
Context: ctx, | ||
ListenAddress: fmt.Sprintf(":%d", prometheusUIServerPort), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means only a single prometheus receiver can have the web UI enabled at once, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's right, per VM or pod it's running on. I have added a setting to make this port configurable
@@ -497,6 +497,10 @@ func TestTargetAllocatorJobRetrieval(t *testing.T) { | |||
|
|||
require.NoError(t, receiver.Start(ctx, componenttest.NewNopHost())) | |||
|
|||
t.Cleanup(func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related to the change, or just a useful fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from running all the tests with the UI enabled by default. Some tests are not cleaning up before the next one runs so the port is already taken on the next test. I could also remove these changes since it's not enabled by default and has separate tests for the UI
@@ -17,13 +17,16 @@ import ( | |||
"time" | |||
|
|||
"github.com/go-kit/log" | |||
"github.com/google/cadvisor/version" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the right import? Seems odd to depend on cAdvisor...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, this should be the Prometheus version package, fixed this
Thanks @dashpole, after reading more about the extensions design, I see why it would fit more as an extension. I looked into the remote tap extension and created a similar extension for the UI to see if this would work. The UI needs 2 things from the prom receiver to get all the data correctly:
The remotetapextension is getting the data from the remotetapprocessor. The implementation hasn't been added yet for these to the repo, but I looked a bit more into it after this morning and found this as part of the POC example that fixes having to export the whole extension type for access from the receiver: https://github.com/pmcollins/opentelemetry-collector-contrib/blob/9dfc2cb971b6181beb919038fc715c06f123296b/processor/websocketprocessor/processor.go#L88 So at the end of the Start() function of the Prom Receiver the following can be added to pass the config and scrapemanager to the extension:
I can make this change in this PR so that this is the only functionality added in the Prom Receiver. If we don't want this to always run, I can also keep the enable_prometheus_ui setting to go around this code? Then I can open a PR also for the extension. (As reference, here's what the extension would look like:)
|
Thanks @gracewehner for the investigation. The approach you laid out makes sense to me. A follow-up question: @gracewehner do you think we can pass the prom receiver name in to RegisterPrometheusReceiverComponents as well? That would, in theory, allow us to support multiple prometheus receivers. One way to do this (I think?) would be for each receiver to get its own webserver at a different route. Maybe they could each listen at I.e. the UI for:
would be at route "/". The UI for:
would be at route: |
@atoulme, since you are working on the remote tap extension
Thanks! |
|
Thanks @atoulme. @gracewehner, lets move forward with the changes to the prometheus receiver here, and open an issue for a new component for the prometheusuiextension. I can sponsor, and we can both be codeowners if that is alright with you. |
I'm a bit wary of including the entire Prometheus API when we can only support a small subset of its features. I have a PR I can resurrect that implements only the |
Do you think having them on different routes is enough? Or do you think different ports is better? |
@Aneurysm9 having the UI also seems more useful than just serving the /targets endpoint. Is it possible to use the UI with your PR? |
When creating the webhandler in agent mode, only the /configs, /service-discovery, /targets APIs are exposed which would be useful and can be supported by the receiver (plus some build info)
To add to this, from looking at the way the prometheus web handler is setup, a lot of changes would need to be made on the Prometheus-side to be able to support different routes pointing to different scrapemanagers at the same port. Using different ports would be supported though |
I do agree that trying to merge receivers would make the UI confusing. We could add the configuration to the prometheus receiver for the UI port. It would be nice to also somehow detect conflicts. |
Having the UI means we're taking on an entire front-end application into our footprint. I certainly don't have the expertise to maintain it or even really to understand the issues that may present or how to deal with security patching and maintenance. My understanding is that the front-end application gets its information from the API, so as long as we're exposing a compatible API it should be possible to point the UI at it and have it work. |
|
I think that adding the entire Prometheus web UI here (even the agent-mode subset) is a significant one-way door to walk through. I'd be much more comfortable adding a |
Ok I see, thanks @Aneurysm9, just to expand on it a bit more, the webhandler is just a wrapper around the API that then serves the react app files. The Prometheus project embeds the react app at build time, but I was thinking we can just have the webhandler and its APIs exposed and the react app files/build can be managed by the user if we don't want to directly put it in the project. Updates for the webhandler package would be the same Prometheus package updates. Then, there is an equivalent version of the react app published in each Prometheus release that can be pulled, unzipped, and put in the same directory that the otelcollector is run from: https://github.com/prometheus/prometheus/releases/tag/v2.48.1 has the ui build: https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-web-ui-2.48.1.tar.gz. The other idea was the build for the extension package can pull this UI and embed these files directly. You are right that the UI is just using the same APIs. The webhandler has both The UI however can definitely be pointed to directly exposed APIs by setting up a separate instance re-using the inner web package code such as https://github.com/prometheus/prometheus/blob/main/web/web.go#L391-L443. This part could also be the extension in the future if we wanted. |
With this being possible I feel strongly that the receiver should only expose the I'm not sure that I like the idea of serving the web UI through an extension. It feels beyond the scope of the collector to include what is basically a static HTTP server for a specific application, especially if we're not embedding the resources it would serve. If the end user needs to bring their own assets they can also bring their own web server. We don't need to be all things to all people. That said, as long as it is completely decoupled from the receiver such that I do not need to include it in my downstream distribution, I don't think that's a hill I need to die on. |
Ok thanks @Aneurysm9, it would be great to open back up your PR then. I am happy to help with anything or can build upon your PR if needed |
If we're good with that path I'll get my PR re-opened and up-to-date, probably tomorrow or Thursday. @dashpole? |
I'm ok with that plan, although it does seem likely to diverge from upstream over time. If we go this route, can we also try and get prometheus to provide a web entrypoint for agents like us so we don't need to maintain a copy? It would also be good to keep copied code in separate files/directory. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
This feature Is still needed any update on this? I am still looking for a way to enable Prometheus WebUI for Prometheus reciever。 |
Hi @jatinmehrotra, currently this is dependent on this open PR for the API behind the UI: #23244 (@Aneurysm9) |
@gracewehner Thank you for your confirmation. Not directly related but until #23244 is merged is there a way where I can get similar metrics as exposed by prometheus server( when we configure job called prometheus) for example I am not looking for the same metrics as I am aware this is the exposed by prometheus server but is there a way to expose metrics related to Otel collector? |
Description:
Adds a feature to the Prometheus Receiver to allow enabling the server for the Prometheus UI using the Prometheus web package. The React app from the Prometheus repo will need to be built and run alongside the collector to actually use the server. However, there are discussions to publish this UI to make it easier to use outside of the Prometheus binary.
The UI allows easier debugging of scrape configs, target discovery, and error messages for failed scrapes. The UI is set to run in agent mode so the UI will not have the graph for querying, but will have the /config, /service-discovery, and /targets pages.
Link to tracking Issue: open-telemetry/prometheus-interoperability-spec#63
Testing:
Added unit tests to ensure the server is only enabled when the setting is added in the config and to make sure the changes are backwards compatible. Tested running the otelcollector along with the React app that the UI is accessible and displays the correct information. Tested with and without the target allocator.
Documentation:
Added to the Prometheus Receiver README instructions for how to use.