From 125fe6ee530f307d3e6ca086dae9c73104c70ef8 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Mon, 27 Dec 2021 18:15:03 +0700 Subject: [PATCH] lint fixes Signed-off-by: Nikita Skrynnik --- pkg/networkservice/common/refresh/client.go | 20 +++++-------------- .../common/updatetoken/server.go | 16 +++------------ pkg/tools/jaeger/exporter.go | 3 ++- pkg/tools/opentelemetry/exporter.go | 3 ++- pkg/tools/zipkin/exporter.go | 3 ++- 5 files changed, 14 insertions(+), 31 deletions(-) diff --git a/pkg/networkservice/common/refresh/client.go b/pkg/networkservice/common/refresh/client.go index 4bd21f0d71..1784386e25 100644 --- a/pkg/networkservice/common/refresh/client.go +++ b/pkg/networkservice/common/refresh/client.go @@ -24,9 +24,7 @@ import ( "context" "time" - "github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes/empty" - "github.com/pkg/errors" "google.golang.org/grpc" "github.com/networkservicemesh/api/pkg/api/networkservice" @@ -59,12 +57,7 @@ func (t *refreshClient) Request(ctx context.Context, request *networkservice.Net } // Compute refreshAfter - refreshAfter, err := after(ctx, conn) - if err != nil { - // If we can't refresh, we should close down chain - _, _ = t.Close(ctx, conn) - return nil, err - } + refreshAfter := after(ctx, conn) // Create a cancel context. cancelCtx, cancel := context.WithCancel(t.chainCtx) @@ -105,16 +98,13 @@ func (t *refreshClient) Close(ctx context.Context, conn *networkservice.Connecti return next.Client(ctx).Close(ctx, conn, opts...) } -func after(ctx context.Context, conn *networkservice.Connection) (time.Duration, error) { +func after(ctx context.Context, conn *networkservice.Connection) time.Duration { clockTime := clock.FromContext(ctx) var minTimeout *time.Duration var expireTime time.Time for _, segment := range conn.GetPath().GetPathSegments() { - expTime, err := ptypes.Timestamp(segment.GetExpires()) - if err != nil { - return 0, errors.WithStack(err) - } + expTime := segment.GetExpires().AsTime() timeout := clockTime.Until(expTime) @@ -133,7 +123,7 @@ func after(ctx context.Context, conn *networkservice.Connection) (time.Duration, } if minTimeout == nil || *minTimeout <= 0 { - return 1, nil + return 1 } // A heuristic to reduce the number of redundant requests in a chain @@ -147,5 +137,5 @@ func after(ctx context.Context, conn *networkservice.Connection) (time.Duration, } duration := time.Duration(float64(*minTimeout) * scale) - return duration, nil + return duration } diff --git a/pkg/networkservice/common/updatetoken/server.go b/pkg/networkservice/common/updatetoken/server.go index 74ea626714..201f426306 100644 --- a/pkg/networkservice/common/updatetoken/server.go +++ b/pkg/networkservice/common/updatetoken/server.go @@ -20,11 +20,9 @@ package updatetoken import ( "context" - "github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes/empty" - "github.com/golang/protobuf/ptypes/timestamp" "github.com/networkservicemesh/api/pkg/api/networkservice" - "github.com/pkg/errors" + "google.golang.org/protobuf/types/known/timestamppb" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/tools/log" @@ -50,11 +48,7 @@ func (u *updateTokenServer) Request(ctx context.Context, request *networkservice if err != nil { log.FromContext(ctx).Warnf("an error during getting token from the context: %+v", err) } else { - var expires *timestamp.Timestamp - expires, err = ptypes.TimestampProto(expireTime.Local()) - if err != nil { - return nil, errors.WithStack(err) - } + expires := timestamppb.New(expireTime.Local()) prev.Expires = expires prev.Token = tok @@ -77,11 +71,7 @@ func (u *updateTokenServer) Close(ctx context.Context, conn *networkservice.Conn if err != nil { log.FromContext(ctx).Warnf("an error during getting token from the context: %+v", err) } else { - var expires *timestamp.Timestamp - expires, err = ptypes.TimestampProto(expireTime.Local()) - if err != nil { - return nil, errors.WithStack(err) - } + expires := timestamppb.New(expireTime.Local()) prev.Expires = expires prev.Token = tok diff --git a/pkg/tools/jaeger/exporter.go b/pkg/tools/jaeger/exporter.go index 44ed0a0ada..9b3a79e9a7 100644 --- a/pkg/tools/jaeger/exporter.go +++ b/pkg/tools/jaeger/exporter.go @@ -22,9 +22,10 @@ package jaeger import ( "context" - "github.com/networkservicemesh/sdk/pkg/tools/log" "go.opentelemetry.io/otel/exporters/jaeger" "go.opentelemetry.io/otel/sdk/trace" + + "github.com/networkservicemesh/sdk/pkg/tools/log" ) // InitExporter - returns an instance of Jaeger Exporter. diff --git a/pkg/tools/opentelemetry/exporter.go b/pkg/tools/opentelemetry/exporter.go index d1e5d071b4..727d683a88 100644 --- a/pkg/tools/opentelemetry/exporter.go +++ b/pkg/tools/opentelemetry/exporter.go @@ -20,13 +20,14 @@ package opentelemetry import ( "context" - "github.com/networkservicemesh/sdk/pkg/tools/log" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" "go.opentelemetry.io/otel/sdk/trace" "google.golang.org/grpc" + + "github.com/networkservicemesh/sdk/pkg/tools/log" ) // InitSpanExporter - returns an instance of OpenTelemetry Span Exporter. diff --git a/pkg/tools/zipkin/exporter.go b/pkg/tools/zipkin/exporter.go index b83246f422..88344d5f7d 100644 --- a/pkg/tools/zipkin/exporter.go +++ b/pkg/tools/zipkin/exporter.go @@ -22,9 +22,10 @@ package zipkin import ( "context" - "github.com/networkservicemesh/sdk/pkg/tools/log" "go.opentelemetry.io/otel/exporters/zipkin" "go.opentelemetry.io/otel/sdk/trace" + + "github.com/networkservicemesh/sdk/pkg/tools/log" ) // InitExporter - returns an instance of Zipkin Exporter.