forked from TrueCloudLab/frostfs-node
[#426] service/object: Add request duration metrics
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
f8ab7a9c60
commit
0b93e8a029
1 changed files with 75 additions and 0 deletions
|
@ -2,6 +2,7 @@ package object
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
@ -71,6 +72,58 @@ var (
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Request duration metrics.
|
||||||
|
var (
|
||||||
|
getDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "get_req_duration",
|
||||||
|
Help: "Accumulated get request process duration",
|
||||||
|
})
|
||||||
|
|
||||||
|
putDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "put_req_duration",
|
||||||
|
Help: "Accumulated put request process duration",
|
||||||
|
})
|
||||||
|
|
||||||
|
headDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "head_req_duration",
|
||||||
|
Help: "Accumulated head request process duration",
|
||||||
|
})
|
||||||
|
|
||||||
|
searchDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "search_req_duration",
|
||||||
|
Help: "Accumulated search request process duration",
|
||||||
|
})
|
||||||
|
|
||||||
|
deleteDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "delete_req_duration",
|
||||||
|
Help: "Accumulated delete request process duration",
|
||||||
|
})
|
||||||
|
|
||||||
|
rangeDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "range_req_duration",
|
||||||
|
Help: "Accumulated range request process duration",
|
||||||
|
})
|
||||||
|
|
||||||
|
rangeHashDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "range_hash_req_duration",
|
||||||
|
Help: "Accumulated range hash request process duration",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
func registerMetrics() {
|
func registerMetrics() {
|
||||||
prometheus.MustRegister(getCounter) // todo: replace with for loop over map
|
prometheus.MustRegister(getCounter) // todo: replace with for loop over map
|
||||||
prometheus.MustRegister(putCounter)
|
prometheus.MustRegister(putCounter)
|
||||||
|
@ -79,6 +132,14 @@ func registerMetrics() {
|
||||||
prometheus.MustRegister(deleteCounter)
|
prometheus.MustRegister(deleteCounter)
|
||||||
prometheus.MustRegister(rangeCounter)
|
prometheus.MustRegister(rangeCounter)
|
||||||
prometheus.MustRegister(rangeHashCounter)
|
prometheus.MustRegister(rangeHashCounter)
|
||||||
|
|
||||||
|
prometheus.MustRegister(getDuration)
|
||||||
|
prometheus.MustRegister(putDuration)
|
||||||
|
prometheus.MustRegister(headDuration)
|
||||||
|
prometheus.MustRegister(searchDuration)
|
||||||
|
prometheus.MustRegister(deleteDuration)
|
||||||
|
prometheus.MustRegister(rangeDuration)
|
||||||
|
prometheus.MustRegister(rangeHashDuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMetricCollector(next ServiceServer) *MetricCollector {
|
func NewMetricCollector(next ServiceServer) *MetricCollector {
|
||||||
|
@ -90,56 +151,70 @@ func NewMetricCollector(next ServiceServer) *MetricCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MetricCollector) Get(req *object.GetRequest, stream GetObjectStream) error {
|
func (m MetricCollector) Get(req *object.GetRequest, stream GetObjectStream) error {
|
||||||
|
t := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
getCounter.Inc()
|
getCounter.Inc()
|
||||||
|
getDuration.Add(float64(time.Since(t)))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return m.next.Get(req, stream)
|
return m.next.Get(req, stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MetricCollector) Put(ctx context.Context) (object.PutObjectStreamer, error) {
|
func (m MetricCollector) Put(ctx context.Context) (object.PutObjectStreamer, error) {
|
||||||
|
t := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
putCounter.Inc()
|
putCounter.Inc()
|
||||||
|
putDuration.Add(float64(time.Since(t)))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return m.next.Put(ctx)
|
return m.next.Put(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MetricCollector) Head(ctx context.Context, request *object.HeadRequest) (*object.HeadResponse, error) {
|
func (m MetricCollector) Head(ctx context.Context, request *object.HeadRequest) (*object.HeadResponse, error) {
|
||||||
|
t := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
headCounter.Inc()
|
headCounter.Inc()
|
||||||
|
headDuration.Add(float64(time.Since(t)))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return m.next.Head(ctx, request)
|
return m.next.Head(ctx, request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MetricCollector) Search(req *object.SearchRequest, stream SearchStream) error {
|
func (m MetricCollector) Search(req *object.SearchRequest, stream SearchStream) error {
|
||||||
|
t := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
searchCounter.Inc()
|
searchCounter.Inc()
|
||||||
|
searchDuration.Add(float64(time.Since(t)))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return m.next.Search(req, stream)
|
return m.next.Search(req, stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MetricCollector) Delete(ctx context.Context, request *object.DeleteRequest) (*object.DeleteResponse, error) {
|
func (m MetricCollector) Delete(ctx context.Context, request *object.DeleteRequest) (*object.DeleteResponse, error) {
|
||||||
|
t := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
deleteCounter.Inc()
|
deleteCounter.Inc()
|
||||||
|
deleteDuration.Add(float64(time.Since(t)))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return m.next.Delete(ctx, request)
|
return m.next.Delete(ctx, request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MetricCollector) GetRange(req *object.GetRangeRequest, stream GetObjectRangeStream) error {
|
func (m MetricCollector) GetRange(req *object.GetRangeRequest, stream GetObjectRangeStream) error {
|
||||||
|
t := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
rangeCounter.Inc()
|
rangeCounter.Inc()
|
||||||
|
rangeDuration.Add(float64(time.Since(t)))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return m.next.GetRange(req, stream)
|
return m.next.GetRange(req, stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MetricCollector) GetRangeHash(ctx context.Context, request *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
func (m MetricCollector) GetRangeHash(ctx context.Context, request *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
||||||
|
t := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
rangeHashCounter.Inc()
|
rangeHashCounter.Inc()
|
||||||
|
rangeHashDuration.Add(float64(time.Since(t)))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return m.next.GetRangeHash(ctx, request)
|
return m.next.GetRangeHash(ctx, request)
|
||||||
|
|
Loading…
Reference in a new issue