Skip to content
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

Fix unintuitive behaviour of RegisterAt with custom registry #181

Merged
merged 1 commit into from Oct 21, 2023
Merged

Fix unintuitive behaviour of RegisterAt with custom registry #181

merged 1 commit into from Oct 21, 2023

Conversation

ghost
Copy link

@ghost ghost commented Sep 21, 2023

This commit fixes some counterintuitive behaviour when creating the middleware with a custom registry.

Previously, using a custom registry with additional metrics requires avoiding the RegisterAt function, which used only the prometheus.DefaultGatherer.

Given a *prometheus.Registry, instead of the more intuitive:

fp := fiberprometheus.NewWithRegistry(reg, "my-application", "http", "", nil)
fp.RegisterAt(app, "/metrics")

One would have to do this:

app.Get("/metrics", adaptor.HTTPHandler(promhttp.HandlerFor(reg, promhttp.HandlerOpts{})))

The change here detects when the prometheus.Registerer is also a prometheus.Gatherer, and then uses the prometheus.Gatherer when calling RegisterAt.

This change will not fix work in the case of a custom implementation of prometheus.Registerer when the that implementation is not also a prometheus.Gatherer, which is an unlikely situation for inexperienced users of prometheus.

For the more common case of passing a *prometheus.Registry, this change will provide a more intuitive experience.

This commit fixes some counterintuitive behaviour when creating the middleware
with a custom registry.

Previously, using a custom registry with additional metrics requires avoiding
the RegisterAt function, which used only the prometheus.DefaultGatherer.

Given a *prometheus.Registry, instead of the more intuitive:

```
fp := fiberprometheus.NewWithRegistry(reg, "my-application", "http", "", nil)
fp.RegisterAt(app, "/metrics")
```

One would have to do this:

```
app.Get("/metrics", adaptor.HTTPHandler(promhttp.HandlerFor(reg, promhttp.HandlerOpts{})))
```

The change here detects when the `prometheus.Registerer` is also a
`prometheus.Gatherer`, and then uses the `prometheus.Gatherer` when calling
`RegisterAt`.

This change will _not_ fix work in the case of a custom implementation of
`prometheus.Registerer` when the that implementation is not _also_ a
`prometheus.Gatherer`, which is an unlikely situation for inexperienced users of
prometheus.

For the more common case of passing a `*prometheus.Registry`, this change will
provide a more intuitive experience.
@ghost
Copy link
Author

ghost commented Oct 9, 2023

Hi @ansrivas if this PR is not satisfactory, I'd be happy to attempt another solution. Am I wrong about expecting the API to work with the custom registry when using the RegisterAt method?

@ansrivas
Copy link
Owner

ansrivas commented Oct 9, 2023

Hello @calloway-jacob, sorry for taking time in reviewing this, a bit busy lately.
I will make sure to go through this later today.

@ansrivas ansrivas merged commit 7015afd into ansrivas:master Oct 21, 2023
8 checks passed
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