2021-03-15 13:01:35 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-03-15 13:04:13 +00:00
|
|
|
"time"
|
2021-03-15 13:01:35 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
MetricCollector struct {
|
|
|
|
next ServiceServer
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
namespace = "neofs_node"
|
|
|
|
subsystem = "object"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Request counter metrics.
|
|
|
|
var (
|
|
|
|
getCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "get_req_count",
|
|
|
|
Help: "Number of get request processed",
|
|
|
|
ConstLabels: nil,
|
|
|
|
})
|
|
|
|
|
|
|
|
putCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "put_req_count",
|
|
|
|
Help: "Number of put request processed",
|
|
|
|
})
|
|
|
|
|
|
|
|
headCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "head_req_count",
|
|
|
|
Help: "Number of head request processed",
|
|
|
|
})
|
|
|
|
|
|
|
|
searchCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "search_req_count",
|
|
|
|
Help: "Number of search request processed",
|
|
|
|
})
|
|
|
|
|
|
|
|
deleteCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "delete_req_count",
|
|
|
|
Help: "Number of delete request processed",
|
|
|
|
})
|
|
|
|
|
|
|
|
rangeCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "range_req_count",
|
|
|
|
Help: "Number of range request processed",
|
|
|
|
})
|
|
|
|
|
|
|
|
rangeHashCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystem,
|
|
|
|
Name: "range_hash_req_count",
|
|
|
|
Help: "Number of range hash request processed",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2021-03-15 13:04:13 +00:00
|
|
|
// 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",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2021-03-15 13:01:35 +00:00
|
|
|
func registerMetrics() {
|
|
|
|
prometheus.MustRegister(getCounter) // todo: replace with for loop over map
|
|
|
|
prometheus.MustRegister(putCounter)
|
|
|
|
prometheus.MustRegister(headCounter)
|
|
|
|
prometheus.MustRegister(searchCounter)
|
|
|
|
prometheus.MustRegister(deleteCounter)
|
|
|
|
prometheus.MustRegister(rangeCounter)
|
|
|
|
prometheus.MustRegister(rangeHashCounter)
|
2021-03-15 13:04:13 +00:00
|
|
|
|
|
|
|
prometheus.MustRegister(getDuration)
|
|
|
|
prometheus.MustRegister(putDuration)
|
|
|
|
prometheus.MustRegister(headDuration)
|
|
|
|
prometheus.MustRegister(searchDuration)
|
|
|
|
prometheus.MustRegister(deleteDuration)
|
|
|
|
prometheus.MustRegister(rangeDuration)
|
|
|
|
prometheus.MustRegister(rangeHashDuration)
|
2021-03-15 13:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMetricCollector(next ServiceServer) *MetricCollector {
|
|
|
|
registerMetrics()
|
|
|
|
|
|
|
|
return &MetricCollector{
|
|
|
|
next: next,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m MetricCollector) Get(req *object.GetRequest, stream GetObjectStream) error {
|
2021-03-15 13:04:13 +00:00
|
|
|
t := time.Now()
|
2021-03-15 13:01:35 +00:00
|
|
|
defer func() {
|
|
|
|
getCounter.Inc()
|
2021-03-15 13:04:13 +00:00
|
|
|
getDuration.Add(float64(time.Since(t)))
|
2021-03-15 13:01:35 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
return m.next.Get(req, stream)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m MetricCollector) Put(ctx context.Context) (object.PutObjectStreamer, error) {
|
2021-03-15 13:04:13 +00:00
|
|
|
t := time.Now()
|
2021-03-15 13:01:35 +00:00
|
|
|
defer func() {
|
|
|
|
putCounter.Inc()
|
2021-03-15 13:04:13 +00:00
|
|
|
putDuration.Add(float64(time.Since(t)))
|
2021-03-15 13:01:35 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
return m.next.Put(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m MetricCollector) Head(ctx context.Context, request *object.HeadRequest) (*object.HeadResponse, error) {
|
2021-03-15 13:04:13 +00:00
|
|
|
t := time.Now()
|
2021-03-15 13:01:35 +00:00
|
|
|
defer func() {
|
|
|
|
headCounter.Inc()
|
2021-03-15 13:04:13 +00:00
|
|
|
headDuration.Add(float64(time.Since(t)))
|
2021-03-15 13:01:35 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
return m.next.Head(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m MetricCollector) Search(req *object.SearchRequest, stream SearchStream) error {
|
2021-03-15 13:04:13 +00:00
|
|
|
t := time.Now()
|
2021-03-15 13:01:35 +00:00
|
|
|
defer func() {
|
|
|
|
searchCounter.Inc()
|
2021-03-15 13:04:13 +00:00
|
|
|
searchDuration.Add(float64(time.Since(t)))
|
2021-03-15 13:01:35 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
return m.next.Search(req, stream)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m MetricCollector) Delete(ctx context.Context, request *object.DeleteRequest) (*object.DeleteResponse, error) {
|
2021-03-15 13:04:13 +00:00
|
|
|
t := time.Now()
|
2021-03-15 13:01:35 +00:00
|
|
|
defer func() {
|
|
|
|
deleteCounter.Inc()
|
2021-03-15 13:04:13 +00:00
|
|
|
deleteDuration.Add(float64(time.Since(t)))
|
2021-03-15 13:01:35 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
return m.next.Delete(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m MetricCollector) GetRange(req *object.GetRangeRequest, stream GetObjectRangeStream) error {
|
2021-03-15 13:04:13 +00:00
|
|
|
t := time.Now()
|
2021-03-15 13:01:35 +00:00
|
|
|
defer func() {
|
|
|
|
rangeCounter.Inc()
|
2021-03-15 13:04:13 +00:00
|
|
|
rangeDuration.Add(float64(time.Since(t)))
|
2021-03-15 13:01:35 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
return m.next.GetRange(req, stream)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m MetricCollector) GetRangeHash(ctx context.Context, request *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
2021-03-15 13:04:13 +00:00
|
|
|
t := time.Now()
|
2021-03-15 13:01:35 +00:00
|
|
|
defer func() {
|
|
|
|
rangeHashCounter.Inc()
|
2021-03-15 13:04:13 +00:00
|
|
|
rangeHashDuration.Add(float64(time.Since(t)))
|
2021-03-15 13:01:35 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
return m.next.GetRangeHash(ctx, request)
|
|
|
|
}
|