Merge pull request #1722 from weaveworks/summary-execution

Delete unused instrumentation code
This commit is contained in:
Paul Bellamy
2016-07-26 12:55:21 +01:00
committed by GitHub

View File

@@ -14,32 +14,6 @@ func ErrorCode(err error) string {
return "500"
}
// TimeRequest runs 'f' and records how long it took in the given Prometheus
// metric. If 'f' returns successfully, record a "200". Otherwise, record
// "500".
//
// If you want more complicated logic for translating errors into statuses,
// use 'TimeRequestStatus'.
func TimeRequest(method string, metric *prometheus.SummaryVec, f func() error) error {
return TimeRequestStatus(method, metric, ErrorCode, f)
}
// TimeRequestStatus runs 'f' and records how long it took in the given
// Prometheus metric.
//
// toStatusCode is a function that translates errors returned by 'f' into
// HTTP-like status codes.
func TimeRequestStatus(method string, metric *prometheus.SummaryVec, toStatusCode func(error) string, f func() error) error {
if toStatusCode == nil {
toStatusCode = ErrorCode
}
startTime := time.Now()
err := f()
duration := time.Now().Sub(startTime)
metric.WithLabelValues(method, toStatusCode(err)).Observe(duration.Seconds())
return err
}
// TimeRequestHistogram runs 'f' and records how long it took in the given Prometheus
// histogram metric. If 'f' returns successfully, record a "200". Otherwise, record
// "500".