Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #28 from microservices-demo/refactor/prometheus
Browse files Browse the repository at this point in the history
Remove old monitoring code.
  • Loading branch information
Phil Winder authored Mar 13, 2017
2 parents 691e3dc + 8bc59f8 commit dd16f30
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 55 deletions.
34 changes: 0 additions & 34 deletions logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package payment

import (
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/metrics"
"time"
)

Expand Down Expand Up @@ -42,36 +41,3 @@ func (mw loggingMiddleware) Health() (health []Health) {
}(time.Now())
return mw.next.Health()
}

type instrumentingService struct {
requestCount metrics.Counter
requestLatency metrics.Histogram
Service
}

// NewInstrumentingService returns an instance of an instrumenting Service.
func NewInstrumentingService(requestCount metrics.Counter, requestLatency metrics.Histogram, s Service) Service {
return &instrumentingService{
requestCount: requestCount,
requestLatency: requestLatency,
Service: s,
}
}

func (s *instrumentingService) Authorise(amount float32) (auth Authorisation, err error) {
defer func(begin time.Time) {
s.requestCount.With("method", "authorise").Add(1)
s.requestLatency.With("method", "authorise").Observe(time.Since(begin).Seconds())
}(time.Now())

return s.Service.Authorise(amount)
}

func (s *instrumentingService) Health() []Health {
defer func(begin time.Time) {
s.requestCount.With("method", "health").Add(1)
s.requestLatency.With("method", "health").Observe(time.Since(begin).Seconds())
}(time.Now())

return s.Service.Health()
}
22 changes: 1 addition & 21 deletions wiring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
"github.com/go-kit/kit/log"
"golang.org/x/net/context"

kitprometheus "github.com/go-kit/kit/metrics/prometheus"
stdopentracing "github.com/opentracing/opentracing-go"
stdprometheus "github.com/prometheus/client_golang/prometheus"
"github.com/microservices-demo/payment/middleware"
stdopentracing "github.com/opentracing/opentracing-go"
)

func WireUp(ctx context.Context, declineAmount float32, tracer stdopentracing.Tracer, serviceName string) (http.Handler, log.Logger) {
Expand All @@ -22,29 +20,11 @@ func WireUp(ctx context.Context, declineAmount float32, tracer stdopentracing.Tr
logger = log.NewContext(logger).With("caller", log.DefaultCaller)
}

fieldKeys := []string{"method"}
// Service domain.
var service Service
{
service = NewAuthorisationService(declineAmount)
service = LoggingMiddleware(logger)(service)
service = NewInstrumentingService(
kitprometheus.NewCounterFrom(
stdprometheus.CounterOpts{
Namespace: "http",
Subsystem: "requests",
Name: "total",
Help: "Number of requests received.",
},
fieldKeys),
kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{
Namespace: "http",
Subsystem: "request",
Name: "duration_microseconds_sum",
Help: "Total duration of requests in microseconds.",
}, fieldKeys),
service,
)
}

// Endpoint domain.
Expand Down

0 comments on commit dd16f30

Please sign in to comment.