Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt cmd-forwarder-sriov to use opentracing #22

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
env:
GOLANGCI_LINT_CONTAINER: golangci/golangci-lint:v1.23.2
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Pull golangci-lint docker container
run: docker pull ${GOLANGCI_LINT_CONTAINER}
- name: Run golangci-lint
run: docker run --rm -v $(pwd):/app -w /app ${GOLANGCI_LINT_CONTAINER} golangci-lint run
uses: actions/checkout@v2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look at #21
This file is part of the config that updates from cmd-template.

Let's figure out why #21 is not applying

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#21 is not applying because ci job "Push docker image" failed. The reason of it is lack of runtime stage in Dockerfile.
PR with fix: #23

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.31

excludeFmtErrorf:
name: exclude fmt.Errorf
Expand Down Expand Up @@ -67,7 +65,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-go@v1
with:
go-version: 1.13.4
go-version: 1.15
- run: go mod tidy
- name: Check for changes in go.mod or go.sum
run: |
Expand All @@ -80,7 +78,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-go@v1
with:
go-version: 1.13.4
go-version: 1.15
- name: Install go-header
run: 'go get github.com/denis-tingajkin/go-header@v0.2.2'
- name: Run go-header
Expand Down Expand Up @@ -111,7 +109,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.13.4
go-version: 1.15
- name: Generate files
run: go generate ./...
- name: Check for changes in generated code
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM golang:1.13.8-stretch as go
COPY --from=golang:1.13.8-stretch /usr/local/go/ /go
FROM golang:1.15-buster as go
COPY --from=golang:1.15-buster /usr/local/go/ /go
ENV PATH ${PATH}:/go/bin
ENV GO111MODULE=on
ENV CGO_ENABLED=0
ENV GOBIN=/bin
RUN go get github.com/go-delve/delve/cmd/dlv@v1.4.0
RUN go run github.com/edwarnicke/dl \
https://github.com/spiffe/spire/releases/download/v0.9.3/spire-0.9.3-linux-x86_64-glibc.tar.gz | \
tar -xzvf - -C /bin --strip=3 ./spire-0.9.3/bin/spire-server ./spire-0.9.3/bin/spire-agent
RUN go get github.com/go-delve/delve/cmd/dlv@v1.5.0
RUN go get github.com/edwarnicke/dl
RUN dl https://github.com/spiffe/spire/releases/download/v0.11.1/spire-0.11.1-linux-x86_64-glibc.tar.gz | \
tar -xzvf - -C /bin --strip=3 ./spire-0.11.1/bin/spire-server ./spire-0.11.1/bin/spire-agent

FROM go as build
WORKDIR /build
Expand Down
19 changes: 9 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
module github.com/networkservicemesh/cmd-forwarder-sriov

go 1.14
go 1.15

require (
github.com/antonfisher/nested-logrus-formatter v1.1.0
github.com/edwarnicke/exechelper v1.0.1
github.com/fsnotify/fsnotify v1.4.7
github.com/google/uuid v1.1.1
github.com/edwarnicke/exechelper v1.0.2
github.com/fsnotify/fsnotify v1.4.9
github.com/google/uuid v1.1.2
github.com/kelseyhightower/envconfig v1.4.0
github.com/networkservicemesh/api v0.0.0-20200525170518-89690ec70489
github.com/networkservicemesh/sdk v0.0.0-20200608153620-b31fd268b04f
github.com/networkservicemesh/api v0.0.0-20201108204718-89d65b3605cf
github.com/networkservicemesh/sdk v0.0.0-20201110143151-4a6442d84a9b
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.6.0
github.com/sirupsen/logrus v1.7.0
github.com/spiffe/go-spiffe/v2 v2.0.0-alpha.4.0.20200528145730-dc11d0c74e85
github.com/stretchr/testify v1.5.1
google.golang.org/grpc v1.29.1
gopkg.in/yaml.v2 v2.3.0 // indirect
github.com/stretchr/testify v1.6.1
google.golang.org/grpc v1.33.2
k8s.io/kubelet v0.18.6
k8s.io/kubernetes v1.18.6
)
Expand Down
294 changes: 270 additions & 24 deletions go.sum

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions internal/imports/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package imports

//go:generate bash -c "cd $(mktemp -d) && GO111MODULE=on go get github.com/edwarnicke/imports-gen@v1.0.0"
//go:generate ${GOPATH}/bin/imports-gen
54 changes: 30 additions & 24 deletions internal/imports/imports.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package imports used for priming Docker builds to maximize layer caching
// DO NOT EDIT - generated by github.com/edwarnicke/imports-gen
package imports

import (
_ "context" // we need it
_ "context"
_ "errors"
_ "fmt"
_ "io"
_ "io/ioutil"
_ "net"
_ "net/url"
_ "os"
_ "path"
_ "path/filepath"
_ "sync"
_ "testing"
_ "time"

_ "github.com/antonfisher/nested-logrus-formatter" // we need it
_ "github.com/antonfisher/nested-logrus-formatter"
_ "github.com/edwarnicke/exechelper"
_ "github.com/fsnotify/fsnotify"
_ "github.com/google/uuid"
_ "github.com/kelseyhightower/envconfig"
_ "github.com/networkservicemesh/sdk/pkg/tools/debug"
_ "github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
_ "github.com/networkservicemesh/sdk/pkg/tools/log"
_ "github.com/networkservicemesh/sdk/pkg/tools/signalctx"
_ "github.com/networkservicemesh/sdk/pkg/tools/spire"
_ "github.com/pkg/errors"
_ "github.com/sirupsen/logrus"
_ "github.com/spiffe/go-spiffe/v2/bundle/x509bundle"
_ "github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig"
_ "github.com/spiffe/go-spiffe/v2/svid/x509svid"
_ "github.com/spiffe/go-spiffe/v2/workloadapi"
_ "github.com/stretchr/testify/assert"
_ "github.com/stretchr/testify/require"
_ "github.com/stretchr/testify/suite"
_ "google.golang.org/grpc"
_ "google.golang.org/grpc/credentials"
_ "google.golang.org/grpc/health/grpc_health_v1"
_ "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
_ "k8s.io/kubernetes/pkg/kubelet/apis/podresources/v1alpha1"

_ "github.com/networkservicemesh/api/pkg/api/networkservice"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/chains/client"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/clienturl"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/connect"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters"
_ "github.com/networkservicemesh/sdk/pkg/tools/addressof"
_ "github.com/networkservicemesh/sdk/pkg/tools/debug"
_ "github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
_ "github.com/networkservicemesh/sdk/pkg/tools/jaeger"
_ "github.com/networkservicemesh/sdk/pkg/tools/log"
_ "github.com/networkservicemesh/sdk/pkg/tools/signalctx"
_ "github.com/networkservicemesh/sdk/pkg/tools/spanhelper"
_ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
_ "github.com/networkservicemesh/sdk/pkg/tools/spire"
_ "github.com/networkservicemesh/sdk/pkg/tools/token"
)
19 changes: 12 additions & 7 deletions local/sdk-sriov/pkg/networkservice/chains/sriov/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
package sriov

import (
"context"
"net/url"

"github.com/networkservicemesh/api/pkg/api/networkservice"

"google.golang.org/grpc"

"github.com/networkservicemesh/sdk/pkg/networkservice/chains/client"
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/clienturl"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/connect"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters"
"github.com/networkservicemesh/sdk/pkg/tools/addressof"
"github.com/networkservicemesh/sdk/pkg/tools/token"
"google.golang.org/grpc"
)

type sriovServer struct {
Expand All @@ -42,18 +44,21 @@ type sriovServer struct {
// -tokenGenerator - token.GeneratorFunc - generates tokens for use in Path
// -clientUrl - *url.URL for the talking to the NSMgr
// -...clientDialOptions - dialOptions for dialing the NSMgr
func NewServer(name string, authzServer networkservice.NetworkServiceServer, tokenGenerator token.GeneratorFunc, clientURL *url.URL, clientDialOptions ...grpc.DialOption) endpoint.Endpoint {
func NewServer(ctx context.Context, name string, authzServer networkservice.NetworkServiceServer, tokenGenerator token.GeneratorFunc, clientURL *url.URL, clientDialOptions ...grpc.DialOption) endpoint.Endpoint {
rv := sriovServer{}
rv.Endpoint = endpoint.NewServer(
ctx,
name,
authzServer,
tokenGenerator,
clienturl.NewServer(clientURL),
connect.NewServer(client.NewClientFactory(
name,
// What to call onHeal
addressof.NetworkServiceClient(adapters.NewServerToClient(rv)),
tokenGenerator),
connect.NewServer(
ctx,
client.NewClientFactory(
name,
// What to call onHeal
addressof.NetworkServiceClient(adapters.NewServerToClient(rv)),
tokenGenerator),
clientDialOptions...,
),
)
Expand Down
31 changes: 27 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"os"
"time"

"github.com/networkservicemesh/sdk/pkg/tools/jaeger"
"github.com/networkservicemesh/sdk/pkg/tools/spanhelper"

nested "github.com/antonfisher/nested-logrus-formatter"
"github.com/kelseyhightower/envconfig"
"github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig"
Expand Down Expand Up @@ -72,6 +75,10 @@ func main() {
log.Entry(ctx).Infof("%s", err)
}

// Configure open tracing
jaegerCloser := jaeger.InitJaeger("cmd-forwarder-sriov")
defer func() { _ = jaegerCloser.Close() }()

starttime := time.Now()

// Get config from environment
Expand Down Expand Up @@ -107,19 +114,35 @@ func main() {
}
logrus.Infof("SVID: %q", svid.ID)

dialOptions := append(
spanhelper.WithTracingDial(),
grpc.WithTransportCredentials(
credentials.NewTLS(
tlsconfig.MTLSClientConfig(source, source, tlsconfig.AuthorizeAny()),
),
),
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
)
// XConnect Network Service Endpoint
endpoint := sriov.NewServer(
ctx,
config.Name,
authorize.NewServer(),
spiffejwt.TokenGeneratorFunc(source, config.MaxTokenLifetime),
&config.ConnectTo,
grpc.WithTransportCredentials(credentials.NewTLS(tlsconfig.MTLSClientConfig(source, source, tlsconfig.AuthorizeAny()))),
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
dialOptions...,
)

// Create GRPC Server
// TODO - add ServerOptions for Tracing
server := grpc.NewServer(grpc.Creds(credentials.NewTLS(tlsconfig.MTLSServerConfig(source, source, tlsconfig.AuthorizeAny()))))
serverOptions := append(
spanhelper.WithTracing(),
grpc.Creds(
credentials.NewTLS(
tlsconfig.MTLSServerConfig(source, source, tlsconfig.AuthorizeAny()),
),
),
)
server := grpc.NewServer(serverOptions...)
endpoint.Register(server)
srvErrCh := grpcutils.ListenAndServe(ctx, &config.ListenOn, server)
exitOnErr(ctx, cancel, srvErrCh)
Expand Down