telemetry_metrics_prometheus icon indicating copy to clipboard operation
telemetry_metrics_prometheus copied to clipboard

Extract plug

Open chulkilee opened this issue 4 years ago • 2 comments

Instead of running separate cowboy process, I'd like to plug prometheus exporter plug directly to existing endpoint (e.g. to keep everything in one port...)

I could do that with this in Phoenix router.

  get "/metrics", TelemetryMetricsPrometheus.Router, [name: :prometheus_metrics]

However, I need to call example.com/metrics/metrics - since the router has metrics path init.

This PR is to extract minimal plug (e.g. not covering other routes, etc.), so that it can be added freely.

Also it adds @moduledoc to make it public.

chulkilee avatar Oct 01 '20 07:10 chulkilee

Hey @chulkilee.

This needs a lot more documentation, especially around how and when you'd use one method over another and examples of how this would be used in Phoenix. 😉

The purpose of this library was to provide an out-of-the-box ability to expose prometheus metrics on a different port which requires a separately running server. If a user doesn't want those features then this probably isn't the right package to download since it includes plug_cowbyoy. Instead, users should probably be guided to simply copy and paste the plug to their own codebase and only include the core prometheus dependency and follow setup instructions there.

bryannaegele avatar Oct 01 '20 14:10 bryannaegele

Thanks a lot for the feedback!

You're absolutely correct that it needs more documentation. Before working more on that I'd like to make sure it's the right direction 😉

I agree that this is very simple plug - but it would require copy and paste for any users not wanting to run the separate port) and that's what this PR to solve. For example, Plug itself has many commonly needed but simple plugs such as Plug.BasicAuth for convenience.

Also this lib is anyway not auto-starting global app anyway - if we really want to make it out-of-box, we may just make it otp app starting by itself with global config (like logger) - but it's kind of middle of app and library since it requires adding it to supervisor manually.

The main question here is whether we require running separate process with separate port to use this package. I believe that should be an option, not only option. Probably it would be better to make plug as dependency, and plug_cowboy as optional dep, and raise error when it's needed but not added.

chulkilee avatar Oct 01 '20 20:10 chulkilee