Skip to content

Implement am proxy command - #128

Merged
brettimus merged 13 commits into
mainfrom
am-proxy
Aug 30, 2023
Merged

brettimus merged 13 commits into
mainfrom
am-proxy

Conversation

@brettimus

@brettimus brettimus commented Aug 28, 2023 •

Copy link
Copy Markdown
Member

Description

This PR adds support for an am proxy command, which would

  1. Start serving explorer, as usual (can still be configured via --listen-address and --explorer-address)
  2. Optionally proxy requests to /prometheus to a user-specified url (configured via --prometheus-url)
  3. NOT download or launch a local Prometheus

So, if we already had prometheus running on http://localhost:8063 for some odd reason, we could run:

am proxy --prometheus-url http://localhost:8063

And am would not download/launch prometheus, but explorer would still be accessible and automagically connected to the Prometheus instance we're interested in connecting to.

For what it's worth, I tested that scenario, and it does indeed work.

Where I need help

I wanted to create a handler factory, but struggled immensely with the type definition, because you can't use impl Trait to describe the return type for a Fn trait (rust-lang/rust#99697).

What I wanted was something that looked like:

if is_proxying_prometheus {
        app = app
            .route("/prometheus/*path", any(prometheus::handler_factory(prometheus_upstream_base)))
            .route("/prometheus",  any(prometheus::handler_factory(prometheus_upstream_base)));
    }

Ultimately, I gave up, and opted to use inline blocks/closures to define the handlers for this functionality.

Additionally, I figured we would need to rewrite the path of any requests to /prometheus/* before forwarding to the external prometheus. There has to be a better/more concise way than I chose.

Basically, this PR still needs some cleanup, api review (is proxy the right command name even?), and probably some tests.

Checklist

  • Changelog updated

@brettimus
brettimus requested a review from a team as a code owner August 28, 2023 16:01
@brettimus
brettimus marked this pull request as draft August 28, 2023 16:01
@brettimus
brettimus marked this pull request as ready for review August 28, 2023 20:32
@hatchan

hatchan commented Aug 30, 2023

Copy link
Copy Markdown
Contributor

Additionally, I figured we would need to rewrite the path of any requests to /prometheus/* before forwarding to the external prometheus. There has to be a better/more concise way than I chose.

I think this is the correct way of dealing with this 👍

Basically, this PR still needs some cleanup, api review (is proxy the right command name even?), and probably some tests.

I think proxy is the best name.

Comment thread .gitignore Resolved
Comment thread src/bin/am/commands/proxy.rs Resolved
Comment thread src/bin/am/server.rs Resolved
@brettimus brettimus changed the title [WIP] am proxy Implement am proxy command Aug 30, 2023
@brettimus
brettimus merged commit 7e7bebf into main Aug 30, 2023
@brettimus
brettimus deleted the am-proxy branch August 30, 2023 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants