Skip to content
This repository has been archived by the owner on Aug 24, 2020. It is now read-only.

Commit

Permalink
Ports to new go-kit.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasd committed Aug 30, 2016
1 parent 46aca60 commit 4321ca8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
13 changes: 6 additions & 7 deletions log.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}))

Expand Down Expand Up @@ -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)
}))

Expand Down
9 changes: 4 additions & 5 deletions server.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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)
})
Expand Down

0 comments on commit 4321ca8

Please sign in to comment.