feat: add bounded operational metrics
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1"
|
||||
"github.com/rvbox/rvbox/internal/agentproto"
|
||||
"github.com/rvbox/rvbox/internal/domain"
|
||||
"github.com/rvbox/rvbox/internal/observability"
|
||||
"github.com/rvbox/rvbox/internal/server/store"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -48,6 +49,8 @@ type Options struct {
|
||||
Now func() time.Time
|
||||
CursorKey []byte
|
||||
WakeClient func(string) bool
|
||||
// Metrics is optional and receives only static metric names.
|
||||
Metrics *observability.Health
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
@@ -59,6 +62,7 @@ type Service struct {
|
||||
now func() time.Time
|
||||
cursors *domain.CursorCodec
|
||||
wakeClient func(string) bool
|
||||
metrics *observability.Health
|
||||
}
|
||||
|
||||
func NewService(options Options) (*Service, error) {
|
||||
@@ -94,7 +98,7 @@ func NewService(options Options) (*Service, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Service{store: options.Store, defaultQueueTTL: options.DefaultQueueTTL, takeoverTTL: options.TakeoverTTL, limits: options.Limits, now: options.Now, cursors: codec, wakeClient: options.WakeClient}, nil
|
||||
return &Service{store: options.Store, defaultQueueTTL: options.DefaultQueueTTL, takeoverTTL: options.TakeoverTTL, limits: options.Limits, now: options.Now, cursors: codec, wakeClient: options.WakeClient, metrics: options.Metrics}, nil
|
||||
}
|
||||
|
||||
func (service *Service) ListClients(ctx context.Context, request *rvboxv1.ListClientsRequest) (*rvboxv1.ListClientsResponse, error) {
|
||||
@@ -676,11 +680,19 @@ func (service *Service) AuthorizeClientTakeover(ctx context.Context, request *rv
|
||||
expires := service.now().UTC().Add(service.takeoverTTL)
|
||||
value, _, err := service.store.AuthorizeClientTakeover(ctx, store.TakeoverAuthorization{ClientID: request.GetClientId(), ClientInstanceID: [16]byte(instance), RequestID: [16]byte(requestID), ExpiresAt: expires})
|
||||
if err != nil {
|
||||
service.incMetric("client_takeover_rejected")
|
||||
return nil, mapStoreError(err)
|
||||
}
|
||||
service.incMetric("client_takeover_authorized")
|
||||
return &rvboxv1.AuthorizeClientTakeoverResponse{ExpiresAt: timestamppb.New(value)}, nil
|
||||
}
|
||||
|
||||
func (service *Service) incMetric(name string) {
|
||||
if service != nil && service.metrics != nil {
|
||||
service.metrics.Inc(name)
|
||||
}
|
||||
}
|
||||
|
||||
func incidentRecord(view store.IncidentView) *rvboxv1.StorageIncident {
|
||||
result := &rvboxv1.StorageIncident{IncidentId: domain.UUID(view.IncidentUUID).String(), DetectedAt: timestamppb.New(view.DetectedAt), State: rvboxv1.StorageIncidentState(view.State), Scope: string(view.Scope), ClientId: view.ClientID, Summary: view.Summary, DataLoss: view.DataLoss, AutomaticallyRepairable: view.AutomaticallyRepairable}
|
||||
if view.ResolvedAt != nil {
|
||||
|
||||
Reference in New Issue
Block a user