diff --git a/api/context/context.go b/api/context/context.go index 77fa388b..d7df44f2 100644 --- a/api/context/context.go +++ b/api/context/context.go @@ -1,4 +1,4 @@ -// Copyright 2015 clair authors +// Copyright 2017 clair authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import ( "github.com/coreos/clair/config" "github.com/coreos/clair/database" - "github.com/coreos/clair/utils" ) var ( @@ -52,7 +51,10 @@ func HTTPHandler(handler Handler, ctx *RouteContext) httprouter.Handle { if status == 0 { statusStr = "???" } - utils.PrometheusObserveTimeMilliseconds(promResponseDurationMilliseconds.WithLabelValues(route, statusStr), start) + + promResponseDurationMilliseconds. + WithLabelValues(route, statusStr). + Observe(float64(time.Since(start).Nanoseconds()) / float64(time.Millisecond)) log.Infof("%s \"%s %s\" %s (%s)", r.RemoteAddr, r.Method, r.RequestURI, statusStr, time.Since(start)) } diff --git a/database/pgsql/pgsql.go b/database/pgsql/pgsql.go index f1d8d7d6..4abd29ee 100644 --- a/database/pgsql/pgsql.go +++ b/database/pgsql/pgsql.go @@ -35,7 +35,6 @@ import ( "github.com/coreos/clair/database" "github.com/coreos/clair/database/pgsql/migrations" "github.com/coreos/clair/pkg/commonerr" - "github.com/coreos/clair/utils" ) var ( @@ -300,5 +299,7 @@ func isErrUniqueViolation(err error) bool { } func observeQueryTime(query, subquery string, start time.Time) { - utils.PrometheusObserveTimeMilliseconds(promQueryDurationMilliseconds.WithLabelValues(query, subquery), start) + promQueryDurationMilliseconds. + WithLabelValues(query, subquery). + Observe(float64(time.Since(start).Nanoseconds()) / float64(time.Millisecond)) } diff --git a/notifier/notifier.go b/notifier/notifier.go index fa80482d..ad3619fa 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -96,8 +96,9 @@ func Run(config *config.NotifierConfig, datastore database.Datastore, stopper *u go func() { success, interrupted := handleTask(*notification, stopper, config.Attempts) if success { - utils.PrometheusObserveTimeMilliseconds(promNotifierLatencyMilliseconds, notification.Created) datastore.SetNotificationNotified(notification.Name) + + promNotifierLatencyMilliseconds.Observe(float64(time.Since(notification.Created).Nanoseconds()) / float64(time.Millisecond)) } if interrupted { running = false diff --git a/utils/prometheus.go b/utils/prometheus.go deleted file mode 100644 index decd1a9e..00000000 --- a/utils/prometheus.go +++ /dev/null @@ -1,13 +0,0 @@ -package utils - -import ( - "time" - - "github.com/prometheus/client_golang/prometheus" -) - -// PrometheusObserveTimeMilliseconds observes the elapsed time since start, in milliseconds, -// on the specified Prometheus Histogram. -func PrometheusObserveTimeMilliseconds(h prometheus.Histogram, start time.Time) { - h.Observe(float64(time.Since(start).Nanoseconds()) / float64(time.Millisecond)) -}