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

Custom exposition of the Metrics #114

Closed
oliverpool opened this issue Feb 23, 2017 · 4 comments
Closed

Custom exposition of the Metrics #114

oliverpool opened this issue Feb 23, 2017 · 4 comments

Comments

@oliverpool
Copy link
Contributor

oliverpool commented Feb 23, 2017

The prometheuscollector sub-package gives a short example to make a custom exposition of the metrics:

handler, err := tusd.NewHandler(…)
collector := prometheuscollector.New(handler.Metrics)
prometheus.MustRegister(collector)

It does however not work when used in an other package (main in my case), because github.com/prometheus/client_golang/prometheus is vendored inside tusd:

cannot use collector (type prometheuscollector.Collector) as type "github.com/prometheus/client_golang/prometheus".Collector in argument to "github.com/prometheus/client_golang/prometheus".MustRegister:
	prometheuscollector.Collector does not implement "github.com/prometheus/client_golang/prometheus".Collector (wrong type for Collect method)
		have Collect(chan<- "github.com/tus/tusd/vendor/github.com/prometheus/client_golang/prometheus".Metric)
		want Collect(chan<- "github.com/prometheus/client_golang/prometheus".Metric)

If I try to import "github.com/tus/tusd/vendor/github.com/prometheus/client_golang/prometheus" instead, it fails with use of vendored package not allowed.

@oliverpool
Copy link
Contributor Author

A possible solution is to add the following function to prometheuscollector.go:

// Handler creates a prometheus handler to serve the metrics
func Handler(metrics *tusd.Metrics) http.Handler {
	prometheus.MustRegister(New(metrics))
	return prometheus.Handler()
}

But it does not allow to add custom metrics.

@Acconut
Copy link
Member

Acconut commented Feb 24, 2017

We encountered the exact same problem with the S3Store and ConsulLocker structs. The only proper way to address this is to actually remove the packages from the vendor directory. For example, you will not find github.com/aws/aws-go-sdk or github.com/hashicorp/consul there. I will probably go with a same route to tackle this issue.

@oliverpool
Copy link
Contributor Author

I will probably go with a same route to tackle this issue.

Do you want a PR for this?

@Acconut
Copy link
Member

Acconut commented Feb 28, 2017

Thank you for offering your help here! I took care of it now because it also requires a few adjustments using govendor (our dependency manager) and the test scripts for Travis/AppVeyor. Please try the above commit :)

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

2 participants