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

Export baseReporter from Scope #174

Open
yoonsio opened this issue Apr 6, 2022 · 0 comments
Open

Export baseReporter from Scope #174

yoonsio opened this issue Apr 6, 2022 · 0 comments

Comments

@yoonsio
Copy link

yoonsio commented Apr 6, 2022

Prometheus CachedReporter provides a handler for metrics endpoint.
It is useful to have the ability to access baseReporter from Scope so that the handler method can be called from the top level.

func getScope() (tally.Scope, io.Closer, error) {
	r := promreporter.NewReporter(promreporter.Options{})
	scope, closer := tally.NewRootScope(tally.ScopeOptions{
		Prefix:         "my_service",
		Tags:           map[string]string{},
		CachedReporter: r,
		Separator:      promreporter.DefaultSeparator,
	}, 1*time.Second)
	return scope, closer, nil
}

func main() {
	scope, closer, _ := getScope()

	// TODO: get the http handler from the scope
	r, _, := scope.BaseReporter.(promreporter.Reporter)
	http.Handle("/metrics", r.HTTPHandler())

	fmt.Printf("Serving :8080/metrics\n")
	fmt.Printf("%v\n", http.ListenAndServe(":8080", nil))
}
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

No branches or pull requests

1 participant