Skip to content

Commit

Permalink
v3rpc: replace grpc metrics w/ go-grpc-prometheus
Browse files Browse the repository at this point in the history
And disable histogram
  • Loading branch information
gyuho committed Nov 14, 2016
1 parent d073512 commit 5e810e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 67 deletions.
33 changes: 4 additions & 29 deletions etcdserver/api/v3rpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/coreos/etcd/pkg/types"
"github.com/coreos/etcd/raft"

prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -53,7 +54,8 @@ func newUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerInterceptor {
}
}
}
return metricsUnaryInterceptor(ctx, req, info, handler)

return prometheus.UnaryServerInterceptor(ctx, req, info, handler)
}
}

Expand Down Expand Up @@ -88,36 +90,9 @@ func newStreamInterceptor(s *etcdserver.EtcdServer) grpc.StreamServerInterceptor

}
}
return metricsStreamInterceptor(srv, ss, info, handler)
}
}

func metricsUnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
service, method := splitMethodName(info.FullMethod)
receivedCounter.WithLabelValues(service, method).Inc()

start := time.Now()
resp, err = handler(ctx, req)
if err != nil {
failedCounter.WithLabelValues(service, method, grpc.Code(err).String()).Inc()
}
handlingDuration.WithLabelValues(service, method).Observe(time.Since(start).Seconds())

return resp, err
}

func metricsStreamInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
service, method := splitMethodName(info.FullMethod)
receivedCounter.WithLabelValues(service, method).Inc()

streamsGauage.WithLabelValues(service, method).Inc()
err := handler(srv, ss)
streamsGauage.WithLabelValues(service, method).Dec()
if err != nil {
failedCounter.WithLabelValues(service, method, grpc.Code(err).String()).Inc()
return prometheus.StreamServerInterceptor(srv, ss, info, handler)
}

return err
}

func splitMethodName(fullMethodName string) (string, string) {
Expand Down
38 changes: 0 additions & 38 deletions etcdserver/api/v3rpc/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,6 @@ package v3rpc
import "github.com/prometheus/client_golang/prometheus"

var (
receivedCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "etcd",
Subsystem: "grpc",
Name: "requests_total",
Help: "Counter of received requests.",
}, []string{"grpc_service", "grpc_method"})

failedCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "etcd",
Subsystem: "grpc",
Name: "requests_failed_total",
Help: "Counter of failed requests.",
}, []string{"grpc_service", "grpc_method", "grpc_code"})

streamsGauage = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "etcd",
Subsystem: "grpc",
Name: "active_streams",
Help: "Number of active streams.",
}, []string{"grpc_service", "grpc_method"})

handlingDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "etcd",
Subsystem: "grpc",
Name: "unary_requests_duration_seconds",
Help: "Bucketed histogram of processing time (s) of handled unary (non-stream) requests.",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13),
}, []string{"grpc_service", "grpc_method"})

sentBytes = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "etcd",
Subsystem: "network",
Expand All @@ -66,11 +33,6 @@ var (
)

func init() {
prometheus.MustRegister(receivedCounter)
prometheus.MustRegister(failedCounter)
prometheus.MustRegister(streamsGauage)
prometheus.MustRegister(handlingDuration)

prometheus.MustRegister(sentBytes)
prometheus.MustRegister(receivedBytes)
}

0 comments on commit 5e810e3

Please sign in to comment.