enable grpc retry
Change-Id: Id9f1cd18324e2788b2e6c4a9838ffff80ee49f0f
diff --git a/cmd/openonu-adapter/main.go b/cmd/openonu-adapter/main.go
index 3dc484b..8aa6c1c 100644
--- a/cmd/openonu-adapter/main.go
+++ b/cmd/openonu-adapter/main.go
@@ -28,6 +28,7 @@
"syscall"
"time"
+ grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
conf "github.com/opencord/voltha-lib-go/v7/pkg/config"
"github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
"github.com/opencord/voltha-lib-go/v7/pkg/events"
@@ -42,6 +43,7 @@
"github.com/opencord/voltha-protos/v5/go/onu_inter_adapter_service"
"github.com/opencord/voltha-protos/v5/go/voltha"
"google.golang.org/grpc"
+ codes "google.golang.org/grpc/codes"
"github.com/opencord/voltha-protos/v5/go/core_adapter"
@@ -136,8 +138,17 @@
a.coreRestarted); err != nil {
logger.Fatal(ctx, "grpc-client-not-created")
}
+ // 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(a.config.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(a.config.MaxRetries), grpc_retry.WithPerRetryTimeout(a.config.PerRPCRetryTimeout), grpc_retry.WithCodes(retryCodes...), backoffCtxOption)
+ logger.Debug(ctx, "Configuration values", log.Fields{"RETRY": a.config.MaxRetries, "TIMEOUT": a.config.PerRPCRetryTimeout})
// Start the core grpc client
- go a.coreClient.Start(ctx, getCoreServiceClientHandler)
+ go a.coreClient.Start(ctx, getCoreServiceClientHandler, grpcRetryOptions)
// Create the open ONU interface adapter
if a.onuAdapter, err = a.startONUAdapter(ctx, a.coreClient, a.eventProxy, a.config, cm); err != nil {