1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-02 22:17:10 +08:00
Dejan Mijic 86f563ee10
Ensure codestyle adherence
Simplified code where possible. Fixed golint suggestions regarding the
missing godoc comments and unnecessary initialized variables.

Signed-off-by: Dejan Mijic <dejan@mainflux.com>
2017-10-06 23:03:24 +02:00

36 lines
819 B
Go

package api
import (
"time"
"github.com/go-kit/kit/metrics"
"github.com/mainflux/mainflux/http"
"github.com/mainflux/mainflux/writer"
)
var _ http.Service = (*metricService)(nil)
type metricService struct {
counter metrics.Counter
latency metrics.Histogram
http.Service
}
// NewMetricService instruments adapter by tracking request count and latency.
func NewMetricService(counter metrics.Counter, latency metrics.Histogram, s http.Service) http.Service {
return &metricService{
counter: counter,
latency: latency,
Service: s,
}
}
func (ms *metricService) Publish(msg writer.RawMessage) error {
defer func(begin time.Time) {
ms.counter.With("method", "publish").Add(1)
ms.latency.With("method", "publish").Observe(time.Since(begin).Seconds())
}(time.Now())
return ms.Service.Publish(msg)
}