Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Dec 27, 2021
1 parent 1b700cf commit 125fe6e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 31 deletions.
20 changes: 5 additions & 15 deletions pkg/networkservice/common/refresh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
}
16 changes: 3 additions & 13 deletions pkg/networkservice/common/updatetoken/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/tools/jaeger/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion pkg/tools/opentelemetry/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion pkg/tools/zipkin/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 125fe6e

Please sign in to comment.