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

Upgrade OTel libraries #115

Merged
merged 1 commit into from
Jun 19, 2023
Merged
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
39 changes: 16 additions & 23 deletions api/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@
package grpc

import (
"fmt"
"net"
"time"

"google.golang.org/grpc/reflection"

"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/recovery"
"github.com/layer5io/meshery-adapter-library/adapter"
"github.com/layer5io/meshery-adapter-library/api/tracing"
"github.com/layer5io/meshery-adapter-library/meshes"
"github.com/layer5io/meshkit/utils/events"

"fmt"

middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
otelgrpc "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc"

apitrace "go.opentelemetry.io/otel/api/trace"
otelgrpc "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)

// Service object holds all the information about the server parameters.
Expand All @@ -64,37 +60,34 @@ func panicHandler(r interface{}) error {
}

// Start starts grpc server.
func Start(s *Service, tr tracing.Handler) error {
func Start(s *Service, _ tracing.Handler) error {
address := fmt.Sprintf(":%s", s.Port)
listener, err := net.Listen("tcp", address)
if err != nil {
return ErrGrpcListener(err)
}

middlewares := middleware.ChainUnaryServer(
grpc_recovery.UnaryServerInterceptor(
grpc_recovery.WithRecoveryHandler(panicHandler),
),
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
)
if tr != nil {
middlewares = middleware.ChainUnaryServer(
otelgrpc.UnaryServerInterceptor(tr.Tracer(s.Name).(apitrace.Tracer)),
)
}

otel.SetTracerProvider(tp)

server := grpc.NewServer(
grpc.UnaryInterceptor(middlewares),
grpc.ChainUnaryInterceptor(
otelgrpc.UnaryServerInterceptor(),
recovery.UnaryServerInterceptor(recovery.WithRecoveryHandler(panicHandler)),
),
)

// Reflection is enabled to simplify accessing the gRPC service using gRPCurl, e.g.
// grpcurl --plaintext localhost:10002 meshes.MeshService.SupportedOperations
// If the use of reflection is not desirable, the parameters '-import-path ./meshes/ -proto meshops.proto' have
// to be added to each grpcurl request, with the appropriate import path.
reflection.Register(server)

//Register Proto
meshes.RegisterMeshServiceServer(server, s)

// Start serving requests
if err = server.Serve(listener); err != nil {
return ErrGrpcServer(err)
}
Expand Down
52 changes: 26 additions & 26 deletions api/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ package tracing
import (
"context"

apitrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/exporters/trace/jaeger"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"
)

type KeyValue struct {
Expand All @@ -35,51 +37,49 @@ type Handler interface {
}

type handler struct {
provider apitrace.Provider
provider trace.TracerProvider
context context.Context
span apitrace.Span
span trace.Span
}

func New(service string, endpoint string) (Handler, error) {
if len(endpoint) < 2 {
return nil, nil
}

provider, flush, err := jaeger.NewExportPipeline(
jaeger.WithCollectorEndpoint(endpoint),
jaeger.WithProcess(jaeger.Process{
ServiceName: service,
Tags: []label.KeyValue{
label.Key("name").String(service),
label.Key("exporter").String("jaeger"),
},
}),
jaeger.WithSDK(&sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
)
provider, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(endpoint)))
if err != nil {
flush()
return nil, err
}

tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithBatcher(provider),
sdktrace.WithResource(resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceName(service),
)),
)
return &handler{
provider: provider,
}, nil
provider: tp,
}, err
}

func (h *handler) Tracer(name string) interface{} {
return h.provider.Tracer(name)
return otel.GetTracerProvider().Tracer(name)
}

func (h *handler) Span(ctx context.Context) {
h.span = apitrace.SpanFromContext(ctx)
h.span = trace.SpanFromContext(ctx)
h.context = ctx
}

func (h *handler) AddEvent(name string, attrs ...*KeyValue) {
kvstore := make([]label.KeyValue, 0)
for _, attr := range attrs {
kvstore = append(kvstore, label.String(attr.Key, attr.Value))
}
kvstore := make([]trace.EventOption, 0)
// @TODO still need to fix this portion
// for _, attr := range attrs {
// kvstore = append(kvstore, trace.WithAttributes(attribute.String(attr.Key, attr.Value)))
// }

h.span.AddEvent(h.context, name, kvstore...)
h.span.AddEvent(name, kvstore...)
}
71 changes: 33 additions & 38 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,23 @@ module github.com/layer5io/meshery-adapter-library

go 1.19

replace (
github.com/docker/docker => github.com/moby/moby v20.10.14+incompatible
github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200806180306-b7e46afd657f
github.com/spf13/afero => github.com/spf13/afero v1.5.1 // Until viper bug is resolved #1161
go.opentelemetry.io/otel => go.opentelemetry.io/otel v0.11.0
go.opentelemetry.io/otel/sdk => go.opentelemetry.io/otel/sdk v0.11.0
)
replace github.com/kudobuilder/kuttl => github.com/layer5io/kuttl v0.4.1-0.20200806180306-b7e46afd657f

require (
github.com/cenkalti/backoff/v4 v4.1.3
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.5
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34
github.com/layer5io/meshkit v0.6.31
github.com/layer5io/meshkit v0.6.45
github.com/layer5io/service-mesh-performance v0.3.4
github.com/spf13/viper v1.15.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc v0.11.0
go.opentelemetry.io/otel v1.10.0
go.opentelemetry.io/otel/exporters/trace/jaeger v0.11.0
go.opentelemetry.io/otel/sdk v1.10.0
golang.org/x/text v0.6.0
google.golang.org/grpc v1.52.0
google.golang.org/protobuf v1.28.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.35.0
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/exporters/jaeger v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
go.opentelemetry.io/otel/trace v1.16.0
golang.org/x/text v0.9.0
google.golang.org/grpc v1.54.0
google.golang.org/protobuf v1.30.0
)

require (
Expand All @@ -35,36 +30,36 @@ require (
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Masterminds/squirrel v1.5.3 // indirect
github.com/apache/thrift v0.13.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/cockroachdb/apd/v2 v2.0.1 // indirect
github.com/containerd/containerd v1.6.18 // indirect
github.com/containerd/containerd v1.6.19 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v20.10.21+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v20.10.21+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-gorp/gorp/v3 v3.0.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
Expand All @@ -76,8 +71,8 @@ require (
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
Expand All @@ -101,7 +96,7 @@ require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-sqlite3 v1.14.14 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
Expand All @@ -121,35 +116,35 @@ require (
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_golang v1.15.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rubenv/sql-migrate v1.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/term v0.4.0 // indirect
golang.org/x/time v0.1.0 // indirect
google.golang.org/api v0.107.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading