Files
weave-scope/app/multitenant/common.go
Tom Wilkie a7b34f1601 Use NATS for shortcut reports in the service. (#1568)
* Vendor nats-io/nats

* Use NATS for shortcut reports.

* Review feedback.

* Rejig shortcut subscriptions, so they work.

* Review feedback
2016-06-09 12:48:41 +01:00

23 lines
445 B
Go

package multitenant
import (
"time"
"github.com/prometheus/client_golang/prometheus"
)
func errorCode(err error) string {
if err == nil {
return "200"
}
return "500"
}
func timeRequest(method string, metric *prometheus.SummaryVec, f func() error) error {
startTime := time.Now()
err := f()
duration := time.Now().Sub(startTime)
metric.WithLabelValues(method, errorCode(err)).Observe(float64(duration.Nanoseconds()))
return err
}