rename prommetric to prometheous, add unit tests

This commit is contained in:
kevin
2020-09-27 16:14:16 +08:00
parent 015716d1b5
commit a958400595
11 changed files with 119 additions and 9 deletions

View File

@@ -74,7 +74,7 @@ func buildDialOptions(opts ...ClientOption) []grpc.DialOption {
clientinterceptors.TracingInterceptor,
clientinterceptors.DurationInterceptor,
clientinterceptors.BreakerInterceptor,
clientinterceptors.PromMetricInterceptor,
clientinterceptors.PrometheousInterceptor,
clientinterceptors.TimeoutInterceptor(clientOptions.Timeout),
),
}

View File

@@ -32,7 +32,7 @@ var (
})
)
func PromMetricInterceptor(ctx context.Context, method string, req, reply interface{},
func PrometheousInterceptor(ctx context.Context, method string, req, reply interface{},
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
startTime := timex.Now()
err := invoker(ctx, method, req, reply, cc, opts...)

View File

@@ -26,7 +26,7 @@ func TestPromMetricInterceptor(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cc := new(grpc.ClientConn)
err := PromMetricInterceptor(context.Background(), "/foo", nil, nil, cc,
err := PrometheousInterceptor(context.Background(), "/foo", nil, nil, cc,
func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
opts ...grpc.CallOption) error {
return test.err

View File

@@ -55,7 +55,7 @@ func (s *rpcServer) Start(register RegisterFn) error {
serverinterceptors.UnaryTracingInterceptor(s.name),
serverinterceptors.UnaryCrashInterceptor(),
serverinterceptors.UnaryStatInterceptor(s.metrics),
serverinterceptors.UnaryPromMetricInterceptor(),
serverinterceptors.UnaryPrometheousInterceptor(),
}
unaryInterceptors = append(unaryInterceptors, s.unaryInterceptors...)
streamInterceptors := []grpc.StreamServerInterceptor{

View File

@@ -32,7 +32,7 @@ var (
})
)
func UnaryPromMetricInterceptor() grpc.UnaryServerInterceptor {
func UnaryPrometheousInterceptor() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (
interface{}, error) {
startTime := timex.Now()

View File

@@ -9,7 +9,7 @@ import (
)
func TestUnaryPromMetricInterceptor(t *testing.T) {
interceptor := UnaryPromMetricInterceptor()
interceptor := UnaryPrometheousInterceptor()
_, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
FullMethod: "/",
}, func(ctx context.Context, req interface{}) (interface{}, error) {