Bump k8s deps to v0.24

This requires dropping otel down to v0.20 because the apiserver package
is importing it and some packages moved around with otel v1.
Even k8s v0.25 still uses this old version of otel, so we are stuck for
a bit (v0.26 will, as of now, use a newer otel version).

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff
2022-09-26 18:25:35 +00:00
parent c668ae6ab6
commit 70848cfdae
6 changed files with 486 additions and 344 deletions

96
go.mod
View File

@@ -5,86 +5,94 @@ go 1.17
require ( require (
contrib.go.opencensus.io/exporter/jaeger v0.2.1 contrib.go.opencensus.io/exporter/jaeger v0.2.1
contrib.go.opencensus.io/exporter/ocagent v0.7.0 contrib.go.opencensus.io/exporter/ocagent v0.7.0
github.com/bombsimon/logrusr v1.0.0 github.com/bombsimon/logrusr/v3 v3.0.0
github.com/docker/spdystream v0.0.0-20170912183627-bc6354cbbc29 // indirect
github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f // indirect github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f // indirect
github.com/google/go-cmp v0.5.8 github.com/google/go-cmp v0.5.8
github.com/gorilla/mux v1.7.3 github.com/gorilla/mux v1.8.0
github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.13.0 github.com/prometheus/client_golang v1.13.0
github.com/sirupsen/logrus v1.6.0 github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.5.0 github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
go.opencensus.io v0.22.4 go.opencensus.io v0.23.0
go.opentelemetry.io/otel v1.2.0 go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/sdk v1.2.0 go.opentelemetry.io/otel/sdk v0.20.0
go.opentelemetry.io/otel/trace v1.2.0 go.opentelemetry.io/otel/trace v0.20.0
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
gotest.tools v2.2.0+incompatible gotest.tools v2.2.0+incompatible
k8s.io/api v0.19.10 k8s.io/api v0.24.6
k8s.io/apimachinery v0.19.10 k8s.io/apimachinery v0.24.6
k8s.io/apiserver v0.19.10 k8s.io/apiserver v0.24.6
k8s.io/client-go v0.19.10 k8s.io/client-go v0.24.6
k8s.io/klog/v2 v2.80.0 k8s.io/klog/v2 v2.80.0
k8s.io/utils v0.0.0-20200912215256-4140de9c8800 k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
sigs.k8s.io/controller-runtime v0.7.1 sigs.k8s.io/controller-runtime v0.12.3
) )
require ( require (
github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.0+incompatible // indirect github.com/blang/semver/v4 v4.0.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.2.1 // indirect github.com/census-instrumentation/opencensus-proto v0.2.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v4.9.0+incompatible // indirect github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.3 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.3 // indirect github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/spec v0.19.3 // indirect github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-openapi/swag v0.19.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.1.0 // indirect github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.1.1 // indirect github.com/google/uuid v1.1.2 // indirect
github.com/googleapis/gnostic v0.5.1 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.14.6 // indirect github.com/imdario/mergo v0.3.12 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imdario/mergo v0.3.10 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect github.com/mailru/easyjson v0.7.6 // indirect
github.com/mailru/easyjson v0.7.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/gomega v1.10.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect
github.com/uber/jaeger-client-go v2.25.0+incompatible // indirect github.com/uber/jaeger-client-go v2.25.0+incompatible // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect go.opentelemetry.io/contrib v0.20.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp v0.20.0 // indirect
go.opentelemetry.io/otel/metric v0.20.0 // indirect
go.opentelemetry.io/otel/sdk/export/metric v0.20.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.20.0 // indirect
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/api v0.43.0 // indirect
google.golang.org/api v0.30.0 // indirect google.golang.org/appengine v1.6.7 // indirect
google.golang.org/appengine v1.6.6 // indirect google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect google.golang.org/grpc v1.40.0 // indirect
google.golang.org/grpc v1.31.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/apiextensions-apiserver v0.19.2 // indirect k8s.io/apiextensions-apiserver v0.24.2 // indirect
k8s.io/component-base v0.19.10 // indirect k8s.io/component-base v0.24.6 // indirect
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6 // indirect k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.15 // indirect sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.30 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.0.3 // indirect sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
) )

608
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/bombsimon/logrusr" "github.com/bombsimon/logrusr/v3"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/virtual-kubelet/virtual-kubelet/log" "github.com/virtual-kubelet/virtual-kubelet/log"
logruslogger "github.com/virtual-kubelet/virtual-kubelet/log/logrus" logruslogger "github.com/virtual-kubelet/virtual-kubelet/log/logrus"
@@ -65,7 +65,7 @@ func wrapE2ETest(ctx context.Context, env *envtest.Environment, f func(context.C
// The following requires that E2E tests are performed *sequentially* // The following requires that E2E tests are performed *sequentially*
log.L = logger log.L = logger
klogv2.SetLogger(logrusr.NewLogger(sl)) klogv2.SetLogger(logrusr.New(sl))
f(ctx, t, env) f(ctx, t, env)
} }
} }

View File

@@ -130,8 +130,8 @@ func WebhookAuth(client kubernetes.Interface, nodeName string, opts ...WebhookAu
} }
} }
cfg.AuthnConfig.TokenAccessReviewClient = client.AuthenticationV1().TokenReviews() cfg.AuthnConfig.TokenAccessReviewClient = client.AuthenticationV1()
cfg.AuthzConfig.SubjectAccessReviewClient = client.AuthorizationV1().SubjectAccessReviews() cfg.AuthzConfig.SubjectAccessReviewClient = client.AuthorizationV1()
authn, _, err := cfg.AuthnConfig.New() authn, _, err := cfg.AuthnConfig.New()
if err != nil { if err != nil {

View File

@@ -235,26 +235,26 @@ func makeAttribute(key string, val interface{}) (attr attribute.KeyValue) {
switch v := val.(type) { switch v := val.(type) {
case string: case string:
return attribute.String(key, v) return attribute.String(key, v)
case []string: // case []string:
return attribute.StringSlice(key, v) // return attribute.StringSlice(key, v)
case fmt.Stringer: case fmt.Stringer:
return attribute.Stringer(key, v) return attribute.Stringer(key, v)
case int: case int:
return attribute.Int(key, v) return attribute.Int(key, v)
case []int: // case []int:
return attribute.IntSlice(key, v) // return attribute.IntSlice(key, v)
case int64: case int64:
return attribute.Int64(key, v) return attribute.Int64(key, v)
case float64: case float64:
return attribute.Float64(key, v) return attribute.Float64(key, v)
case []float64: // case []float64:
return attribute.Float64Slice(key, v) // return attribute.Float64Slice(key, v)
case []int64: // case []int64:
return attribute.Int64Slice(key, v) // return attribute.Int64Slice(key, v)
case bool: case bool:
return attribute.Bool(key, v) return attribute.Bool(key, v)
case []bool: // case []bool:
return attribute.BoolSlice(key, v) // return attribute.BoolSlice(key, v)
case error: case error:
if v == nil { if v == nil {
attribute.String(key, "") attribute.String(key, "")

View File

@@ -16,6 +16,8 @@ package opentelemetry
import ( import (
"context" "context"
"fmt"
"sort"
"strconv" "strconv"
"sync" "sync"
"testing" "testing"
@@ -28,7 +30,8 @@ import (
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.7.0" semconv "go.opentelemetry.io/otel/semconv"
"go.opentelemetry.io/otel/trace"
"gotest.tools/assert" "gotest.tools/assert"
"gotest.tools/assert/cmp" "gotest.tools/assert/cmp"
) )
@@ -88,8 +91,8 @@ func TestSetStatus(t *testing.T) {
s.End() s.End()
assert.Assert(t, !s.s.IsRecording()) assert.Assert(t, !s.s.IsRecording())
assert.Assert(t, e.status.Code == tt.expectedCode) assert.Assert(t, e.status == tt.expectedCode)
assert.Assert(t, e.status.Description == tt.expectedDescription) assert.Assert(t, e.statusMessage == tt.expectedDescription)
s.SetStatus(tt.inputStatus) // should not be panic even if span is ended. s.SetStatus(tt.inputStatus) // should not be panic even if span is ended.
}) })
} }
@@ -200,7 +203,7 @@ func TestLog(t *testing.T) {
logLevel logLevel logLevel logLevel
fields log.Fields fields log.Fields
msg string msg string
expectedEvents []sdktrace.Event expectedEvents []trace.Event
expectedAttributes []attribute.KeyValue expectedAttributes []attribute.KeyValue
}{ }{
{ {
@@ -209,7 +212,7 @@ func TestLog(t *testing.T) {
logLevel: lDebug, logLevel: lDebug,
fields: log.Fields{"testKey1": "value1"}, fields: log.Fields{"testKey1": "value1"},
msg: "message", msg: "message",
expectedEvents: []sdktrace.Event{{Name: "message"}}, expectedEvents: []trace.Event{{Name: "message"}},
expectedAttributes: []attribute.KeyValue{{Key: "testKey1", Value: attribute.StringValue("value1")}}, expectedAttributes: []attribute.KeyValue{{Key: "testKey1", Value: attribute.StringValue("value1")}},
}, { }, {
description: "info", description: "info",
@@ -217,7 +220,7 @@ func TestLog(t *testing.T) {
logLevel: lInfo, logLevel: lInfo,
fields: log.Fields{"testKey1": "value1"}, fields: log.Fields{"testKey1": "value1"},
msg: "message", msg: "message",
expectedEvents: []sdktrace.Event{{Name: "message"}}, expectedEvents: []trace.Event{{Name: "message"}},
expectedAttributes: []attribute.KeyValue{{Key: "testKey1", Value: attribute.StringValue("value1")}}, expectedAttributes: []attribute.KeyValue{{Key: "testKey1", Value: attribute.StringValue("value1")}},
}, { }, {
description: "warn", description: "warn",
@@ -225,7 +228,7 @@ func TestLog(t *testing.T) {
logLevel: lWarn, logLevel: lWarn,
fields: log.Fields{"testKey1": "value1"}, fields: log.Fields{"testKey1": "value1"},
msg: "message", msg: "message",
expectedEvents: []sdktrace.Event{{Name: "message"}}, expectedEvents: []trace.Event{{Name: "message"}},
expectedAttributes: []attribute.KeyValue{{Key: "testKey1", Value: attribute.StringValue("value1")}}, expectedAttributes: []attribute.KeyValue{{Key: "testKey1", Value: attribute.StringValue("value1")}},
}, { }, {
description: "error", description: "error",
@@ -233,7 +236,7 @@ func TestLog(t *testing.T) {
logLevel: lErr, logLevel: lErr,
fields: log.Fields{"testKey1": "value1"}, fields: log.Fields{"testKey1": "value1"},
msg: "message", msg: "message",
expectedEvents: []sdktrace.Event{{Name: "message"}}, expectedEvents: []trace.Event{{Name: "message"}},
expectedAttributes: []attribute.KeyValue{{Key: "testKey1", Value: attribute.StringValue("value1")}}, expectedAttributes: []attribute.KeyValue{{Key: "testKey1", Value: attribute.StringValue("value1")}},
}, { }, {
description: "fatal", description: "fatal",
@@ -241,7 +244,7 @@ func TestLog(t *testing.T) {
logLevel: lFatal, logLevel: lFatal,
fields: log.Fields{"testKey1": "value1"}, fields: log.Fields{"testKey1": "value1"},
msg: "message", msg: "message",
expectedEvents: []sdktrace.Event{{Name: "message"}}, expectedEvents: []trace.Event{{Name: "message"}},
expectedAttributes: []attribute.KeyValue{{Key: "testKey1", Value: attribute.StringValue("value1")}}, expectedAttributes: []attribute.KeyValue{{Key: "testKey1", Value: attribute.StringValue("value1")}},
}, },
} }
@@ -293,7 +296,7 @@ func TestLogf(t *testing.T) {
msg string msg string
fields log.Fields fields log.Fields
args []interface{} args []interface{}
expectedEvents []sdktrace.Event expectedEvents []trace.Event
expectedAttributes []attribute.KeyValue expectedAttributes []attribute.KeyValue
}{ }{
{ {
@@ -303,12 +306,12 @@ func TestLogf(t *testing.T) {
msg: "k1: %s, k2: %v, k3: %d, k4: %v", msg: "k1: %s, k2: %v, k3: %d, k4: %v",
fields: map[string]interface{}{"k1": "test", "k2": []string{"test"}, "k3": 1, "k4": []int{1}}, fields: map[string]interface{}{"k1": "test", "k2": []string{"test"}, "k3": 1, "k4": []int{1}},
args: []interface{}{"test", []string{"test"}, int(1), []int{1}}, args: []interface{}{"test", []string{"test"}, int(1), []int{1}},
expectedEvents: []sdktrace.Event{{Name: "k1: test, k2: [test], k3: 1, k4: [1]"}}, expectedEvents: []trace.Event{{Name: "k1: test, k2: [test], k3: 1, k4: [1]"}},
expectedAttributes: []attribute.KeyValue{ expectedAttributes: []attribute.KeyValue{
attribute.String("k1", "test"), attribute.String("k1", "test"),
attribute.StringSlice("k2", []string{"test"}), attribute.String("k2", fmt.Sprintf("%+v", []string{"test"})),
attribute.Int("k3", 1), attribute.Int("k3", 1),
attribute.IntSlice("k4", []int{1}), attribute.String("k4", fmt.Sprintf("%+v", []int{1})),
}, },
}, { }, {
description: "info", description: "info",
@@ -317,12 +320,12 @@ func TestLogf(t *testing.T) {
msg: "k1: %d, k2: %v, k3: %f, k4: %v", msg: "k1: %d, k2: %v, k3: %f, k4: %v",
fields: map[string]interface{}{"k1": int64(3), "k2": []int64{4}, "k3": float64(2), "k4": []float64{4}}, fields: map[string]interface{}{"k1": int64(3), "k2": []int64{4}, "k3": float64(2), "k4": []float64{4}},
args: []interface{}{int64(3), []int64{4}, float64(2), []float64{4}}, args: []interface{}{int64(3), []int64{4}, float64(2), []float64{4}},
expectedEvents: []sdktrace.Event{{Name: "k1: 3, k2: [4], k3: 2.000000, k4: [4]"}}, expectedEvents: []trace.Event{{Name: "k1: 3, k2: [4], k3: 2.000000, k4: [4]"}},
expectedAttributes: []attribute.KeyValue{ expectedAttributes: []attribute.KeyValue{
attribute.Int64("k1", 1), attribute.Int64("k1", 1),
attribute.Int64Slice("k2", []int64{2}), attribute.String("k2", fmt.Sprintf("%+v", []int64{2})),
attribute.Float64("k3", 3), attribute.Float64("k3", 3),
attribute.Float64Slice("k2", []float64{4}), attribute.String("k4", fmt.Sprintf("%+v", []float64{4})),
}, },
}, { }, {
description: "warn", description: "warn",
@@ -331,7 +334,7 @@ func TestLogf(t *testing.T) {
msg: "k1: %v, k2: %v", msg: "k1: %v, k2: %v",
fields: map[string]interface{}{"k1": map[int]int{1: 1}, "k2": num(1)}, fields: map[string]interface{}{"k1": map[int]int{1: 1}, "k2": num(1)},
args: []interface{}{map[int]int{1: 1}, num(1)}, args: []interface{}{map[int]int{1: 1}, num(1)},
expectedEvents: []sdktrace.Event{{Name: "k1: map[1:1], k2: 1"}}, expectedEvents: []trace.Event{{Name: "k1: map[1:1], k2: 1"}},
expectedAttributes: []attribute.KeyValue{ expectedAttributes: []attribute.KeyValue{
attribute.String("k1", "{1:1}"), attribute.String("k1", "{1:1}"),
attribute.Stringer("k2", num(1)), attribute.Stringer("k2", num(1)),
@@ -343,22 +346,23 @@ func TestLogf(t *testing.T) {
msg: "k1: %t, k2: %v, k3: %s", msg: "k1: %t, k2: %v, k3: %s",
fields: map[string]interface{}{"k1": true, "k2": []bool{true}, "k3": errors.New("fake")}, fields: map[string]interface{}{"k1": true, "k2": []bool{true}, "k3": errors.New("fake")},
args: []interface{}{true, []bool{true}, errors.New("fake")}, args: []interface{}{true, []bool{true}, errors.New("fake")},
expectedEvents: []sdktrace.Event{{Name: "k1: true, k2: [true], k3: fake"}}, expectedEvents: []trace.Event{{Name: "k1: true, k2: [true], k3: fake"}},
expectedAttributes: []attribute.KeyValue{ expectedAttributes: []attribute.KeyValue{
attribute.Bool("k1", true), attribute.Bool("k1", true),
attribute.BoolSlice("k2", []bool{true}), attribute.String("k2", fmt.Sprintf("%+v", []bool{true})),
attribute.String("k3", "fake"), attribute.String("k3", "fake"),
}, },
}, { }, {
description: "fatal", description: "fatal",
spanName: "test", spanName: "test",
logLevel: lFatal, logLevel: lFatal,
expectedEvents: []sdktrace.Event{{Name: ""}}, expectedEvents: []trace.Event{{Name: ""}},
expectedAttributes: []attribute.KeyValue{}, expectedAttributes: []attribute.KeyValue{},
}, },
} }
for _, tt := range testCases { for _, tt := range testCases {
tt := tt
t.Run(tt.description, func(t *testing.T) { t.Run(tt.description, func(t *testing.T) {
tearDown, p, e := setupSuite() tearDown, p, e := setupSuite()
defer tearDown(p) defer tearDown(p)
@@ -385,13 +389,28 @@ func TestLogf(t *testing.T) {
assert.Assert(t, len(e.events) == len(tt.expectedEvents)) assert.Assert(t, len(e.events) == len(tt.expectedEvents))
for i, event := range tt.expectedEvents { for i, event := range tt.expectedEvents {
assert.Assert(t, e.events[i].Name == event.Name, e.events[i].Name) event := event
assert.Assert(t, !e.events[i].Time.IsZero()) i := i
t.Run(fmt.Sprintf("event %s", event.Name), func(t *testing.T) {
assert.Check(t, cmp.Equal(e.events[i].Name, event.Name))
assert.Check(t, !e.events[i].Time.IsZero())
})
} }
assert.Assert(t, len(fl.a) == len(tt.expectedAttributes)) assert.Assert(t, cmp.Len(fl.a, len(tt.expectedAttributes)))
for _, a := range tt.expectedAttributes { sort.Slice(tt.expectedAttributes, func(i, j int) bool {
cmp.Contains(fl.a, a) return tt.expectedAttributes[i].Key < tt.expectedAttributes[j].Key
})
sort.Slice(fl.a, func(i, j int) bool {
return fl.a[i].Key < fl.a[j].Key
})
for i, a := range tt.expectedAttributes {
a := a
t.Run(fmt.Sprintf("attribute %s", a.Key), func(t *testing.T) {
assert.Assert(t, fl.a[i].Key == a.Key)
assert.Assert(t, cmp.Equal(fl.a[i].Value.Type(), a.Value.Type()))
// TODO: check value, this is harder to do since the types are unknown
})
} }
l.Debugf(tt.msg, tt.args) // should not panic even if span is finished l.Debugf(tt.msg, tt.args) // should not panic even if span is finished
@@ -561,7 +580,6 @@ func setupSuite() (func(provider *sdktrace.TracerProvider), *sdktrace.TracerProv
func NewResource(name, version string) *resource.Resource { func NewResource(name, version string) *resource.Resource {
return resource.NewWithAttributes( return resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String(name), semconv.ServiceNameKey.String(name),
semconv.ServiceVersionKey.String(version), semconv.ServiceVersionKey.String(version),
) )
@@ -572,34 +590,36 @@ type fakeExporter struct {
// attributes describe the aspects of the spans. // attributes describe the aspects of the spans.
attributes []attribute.KeyValue attributes []attribute.KeyValue
// Links returns all the links the span has to other spans. // Links returns all the links the span has to other spans.
links []sdktrace.Link links []trace.Link
// Events returns all the events that occurred within in the spans // Events returns all the events that occurred within in the spans
// lifetime. // lifetime.
events []sdktrace.Event events []trace.Event
// Status returns the spans status. // Status returns the spans status.
status sdktrace.Status status codes.Code
statusMessage string
} }
func (f *fakeExporter) ExportSpans(_ context.Context, spans []sdktrace.ReadOnlySpan) (err error) { func (f *fakeExporter) ExportSpans(_ context.Context, spans []*sdktrace.SpanSnapshot) error {
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()
f.attributes = make([]attribute.KeyValue, 0) f.attributes = make([]attribute.KeyValue, 0)
f.links = make([]sdktrace.Link, 0) f.links = make([]trace.Link, 0)
f.events = make([]sdktrace.Event, 0) f.events = make([]trace.Event, 0)
for _, s := range spans { for _, s := range spans {
f.attributes = append(f.attributes, s.Attributes()...) f.attributes = append(f.attributes, s.Attributes...)
f.links = append(f.links, s.Links()...) f.links = append(f.links, s.Links...)
f.events = append(f.events, s.Events()...) f.events = append(f.events, s.MessageEvents...)
f.status = s.Status() f.status = s.StatusCode
f.statusMessage = s.StatusMessage
} }
return return nil
} }
func (f *fakeExporter) Shutdown(_ context.Context) (err error) { func (f *fakeExporter) Shutdown(_ context.Context) (err error) {
f.attributes = make([]attribute.KeyValue, 0) f.attributes = make([]attribute.KeyValue, 0)
f.links = make([]sdktrace.Link, 0) f.links = make([]trace.Link, 0)
f.events = make([]sdktrace.Event, 0) f.events = make([]trace.Event, 0)
return return
} }