frostfs-node/pkg/network/transport/metrics/grpc/service.go

61 lines
1.2 KiB
Go
Raw Normal View History

package metrics
import (
"context"
2020-07-24 13:54:03 +00:00
"errors"
2020-07-24 13:54:03 +00:00
"github.com/nspcc-dev/neofs-node/pkg/network/transport/grpc"
"github.com/nspcc-dev/neofs-node/pkg/services/metrics"
"go.uber.org/zap"
)
type (
// Service is an interface of the server of Metrics service.
Service interface {
MetricsServer
grpc.Service
}
// Params groups the parameters of Metrics service server's constructor.
Params struct {
Logger *zap.Logger
Collector metrics.Collector
}
serviceMetrics struct {
log *zap.Logger
col metrics.Collector
}
)
2020-07-24 13:54:03 +00:00
var (
errEmptyLogger = errors.New("empty logger")
errEmptyCollector = errors.New("empty metrics collector")
)
// New is a Metrics service server's constructor.
func New(p Params) (Service, error) {
switch {
case p.Logger == nil:
return nil, errEmptyLogger
case p.Collector == nil:
return nil, errEmptyCollector
}
return &serviceMetrics{
log: p.Logger,
col: p.Collector,
}, nil
}
func (s *serviceMetrics) ResetSpaceCounter(_ context.Context, _ *ResetSpaceRequest) (*ResetSpaceResponse, error) {
s.col.UpdateSpaceUsage()
return &ResetSpaceResponse{}, nil
}
func (s *serviceMetrics) Name() string { return "metrics" }
func (s *serviceMetrics) Register(srv *grpc.Server) {
RegisterMetricsServer(srv, s)
}