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

Panic on registering /metrics globally #373

Open
3 tasks done
grishy opened this issue Jan 22, 2025 · 0 comments
Open
3 tasks done

Panic on registering /metrics globally #373

grishy opened this issue Jan 22, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@grishy
Copy link
Contributor

grishy commented Jan 22, 2025

Have you read a contributing guide?

  • I have read CONTRIBUTING.md
  • I have searched the existing issues and didn't find any that were similar
  • I have considered creating a pull request with fixes instead of a bug report and want to proceed

Current Behavior

Hi,
Thanks for project ❤️
I am creating a build of an Anytype all-in-one, and one of the issues that I encountered was that some components register themselves globally, like metrics. You can't create two separate App instances and register them to separate metrics because they are using a global HTTP package.

Problem line -

http.Handle("/metrics", promhttp.HandlerFor(m.registry, promhttp.HandlerOpts{}))

Error:

// ...
panic: pattern "/metrics" (registered at /Users/grishy/go/pkg/mod/github.com/anyproto/[email protected]/metric/metric.go:107) conflicts with pattern "/metrics" (registered at /Users/grishy/go/pkg/mod/github.com/anyproto/[email protected]/metric/metric.go:107):
        /metrics matches the same requests as /metrics

goroutine 1 [running]:
net/http.(*ServeMux).register(...)
        /opt/homebrew/Cellar/go/1.23.5/libexec/src/net/http/server.go:2797
net/http.Handle({0x104c7abfb?, 0x0?}, {0x105272e60?, 0x14000256cc0?})
        /opt/homebrew/Cellar/go/1.23.5/libexec/src/net/http/server.go:2781 +0x98
github.com/anyproto/any-sync/metric.(*metric).Run(0x140004d1d40, {0x1051cf9c0?, 0x1400050e880?})
        /Users/grishy/go/pkg/mod/github.com/anyproto/[email protected]/metric/metric.go:107 +0x18c
github.com/anyproto/any-sync/app.(*App).Start(0x14000a12120, {0x10527d590, 0x140008e8200})
        /Users/grishy/go/pkg/mod/github.com/anyproto/[email protected]/app/app.go:262 +0x490
main.main()
        /Users/grishy/personal/github/any-sync-bundle/main.go:35 +0x188
exit status 2

I want to ask for a way that you think would be better so I can create a PR.
Thx!

Expected Behavior

Allow specifying the path for metrics if they are registered globally to avoid conflicts or to merge metrics properly

Steps To Reproduce

Create two apps with separate instances of metric.

Environment

n/a

Anything else?

No response

@grishy grishy added the bug Something isn't working label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant