enabling grpc retry
Change-Id: I3e83654980386cca080f5ff5f2168e9b405fee1f
diff --git a/rw_core/core/adapter/agent.go b/rw_core/core/adapter/agent.go
index 973f767..c25c793 100644
--- a/rw_core/core/adapter/agent.go
+++ b/rw_core/core/adapter/agent.go
@@ -19,14 +19,15 @@
import (
"context"
"errors"
- "sync"
- "time"
-
+ grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
"github.com/opencord/voltha-lib-go/v7/pkg/log"
"github.com/opencord/voltha-protos/v5/go/adapter_service"
"github.com/opencord/voltha-protos/v5/go/voltha"
"google.golang.org/grpc"
+ codes "google.golang.org/grpc/codes"
+ "sync"
+ "time"
)
// agent represents adapter agent
@@ -39,6 +40,8 @@
onAdapterRestart vgrpc.RestartedHandler
liveProbeInterval time.Duration
coreEndpoint string
+ maxRetries uint
+ perRPCRetryTimeout time.Duration
}
func getAdapterServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} {
@@ -48,13 +51,15 @@
return adapter_service.NewAdapterServiceClient(conn)
}
-func newAdapterAgent(coreEndpoint string, adapter *voltha.Adapter, onAdapterRestart vgrpc.RestartedHandler, liveProbeInterval time.Duration) *agent {
+func newAdapterAgent(coreEndpoint string, adapter *voltha.Adapter, onAdapterRestart vgrpc.RestartedHandler, liveProbeInterval time.Duration, maxRetries uint, perRPCRetryTimeout time.Duration) *agent {
return &agent{
adapter: adapter,
onAdapterRestart: onAdapterRestart,
adapterAPIEndPoint: adapter.Endpoint,
liveProbeInterval: liveProbeInterval,
coreEndpoint: coreEndpoint,
+ maxRetries: maxRetries,
+ perRPCRetryTimeout: perRPCRetryTimeout,
}
}
@@ -71,8 +76,15 @@
// Add a liveness communication update
aa.vClient.SubscribeForLiveness(aa.updateCommunicationTime)
-
- go aa.vClient.Start(ctx, getAdapterServiceClientHandler)
+ // the backoff function sets the wait time bw each grpc retries, if not set it will take the deafault value of 50ms which is too low, the jitter sets the rpc retry wait time to be in a range of[PerRPCRetryTimeout-0.2, PerRPCRetryTimeout+0.2]
+ backoffCtxOption := grpc_retry.WithBackoff(grpc_retry.BackoffLinearWithJitter(aa.perRPCRetryTimeout, 0.2))
+ retryCodes := []codes.Code{
+ codes.Unavailable, // server is currently unavailable
+ codes.DeadlineExceeded, // deadline for the operation was exceeded
+ }
+ grpcRetryOptions := grpc_retry.UnaryClientInterceptor(grpc_retry.WithMax(aa.maxRetries), grpc_retry.WithPerRetryTimeout(aa.perRPCRetryTimeout), grpc_retry.WithCodes(retryCodes...), backoffCtxOption)
+ logger.Debug(ctx, "Configuration values", log.Fields{"RETRY": aa.maxRetries, "TIMEOUT": aa.perRPCRetryTimeout})
+ go aa.vClient.Start(ctx, getAdapterServiceClientHandler, grpcRetryOptions)
return nil
}