Permalink
Browse files

Ports to new go-kit.

  • Loading branch information...
tamasd committed Aug 30, 2016
1 parent 46aca60 commit 4321ca8dc9d6fe371c3d9eb0e9ede027414845dc
Showing with 10 additions and 12 deletions.
  1. +6 −7 log.go
  2. +4 −5 server.go
View
13 log.go
@@ -22,7 +22,6 @@ import (
"net/http"
"time"
"github.com/go-kit/kit/metrics"
"github.com/go-kit/kit/metrics/prometheus"
stdprometheus "github.com/prometheus/client_golang/prometheus"
"gitlab.com/tamasd/ab"
@@ -95,14 +94,14 @@ func logService(ec *ab.EntityController, baseurl string) ab.Service {
})
res.ExtraEndpoints = func(srv *ab.Server) error {
walkthroughPlayed := prometheus.NewCounter(stdprometheus.CounterOpts{
walkthroughPlayed := prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: "walkhub",
Subsystem: "metrics",
Name: "walkthrough_played",
Help: "Number of walkthrough plays",
}, []string{"uuid", "embedorigin"})
walkthroughVisited := prometheus.NewCounter(stdprometheus.CounterOpts{
walkthroughVisited := prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: "walkhub",
Subsystem: "metrics",
Name: "walkthrough_visited",
@@ -150,8 +149,8 @@ func logService(ec *ab.EntityController, baseurl string) ab.Service {
ab.MaybeFail(http.StatusInternalServerError, DBLog(db, ec, "walkthroughplayed", message))
walkthroughPlayed.
With(metrics.Field{Key: "uuid", Value: l.UUID}).
With(metrics.Field{Key: "embedorigin", Value: l.EmbedOrigin}).
With("uuid", l.UUID).
With("embedorigin", l.EmbedOrigin).
Add(1)
}))
@@ -179,8 +178,8 @@ func logService(ec *ab.EntityController, baseurl string) ab.Service {
ab.MaybeFail(http.StatusInternalServerError, DBLog(db, ec, "walkthroughvisited", message))
walkthroughVisited.
With(metrics.Field{Key: "uuid", Value: l.UUID}).
With(metrics.Field{Key: "embedorigin", Value: l.EmbedOrigin}).
With("uuid", l.UUID).
With("embedorigin", l.EmbedOrigin).
Add(1)
}))
View
@@ -27,7 +27,6 @@ import (
"text/template"
"time"
"github.com/go-kit/kit/metrics"
"github.com/go-kit/kit/metrics/prometheus"
stdprometheus "github.com/prometheus/client_golang/prometheus"
"github.com/spf13/viper"
@@ -58,7 +57,7 @@ type WalkhubServer struct {
}
func prometheusMiddleware() func(http.Handler) http.Handler {
requestDuration := prometheus.NewSummary(stdprometheus.SummaryOpts{
requestDuration := prometheus.NewSummaryFrom(stdprometheus.SummaryOpts{
Namespace: "walkhub",
Subsystem: "main",
Name: "request_duration_nanoseconds_count",
@@ -72,9 +71,9 @@ func prometheusMiddleware() func(http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func(begin time.Time) {
requestDuration.
With(metrics.Field{Key: "method", Value: r.Method}).
With(metrics.Field{Key: "url", Value: r.URL.String()}).
Observe(int64(time.Since(begin)))
With("method", r.Method).
With("url", r.URL.String()).
Observe(float64(time.Since(begin)))
}(time.Now())
next.ServeHTTP(w, r)
})

0 comments on commit 4321ca8

Please sign in to comment.