From eb8ec3099f90f2f4939985c3cc0f7e085aff92ee Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Wed, 24 Jun 2020 12:00:27 -0700 Subject: [PATCH] Accept both B3 and TraceContext style tracing (#3388) * hack/update-deps.sh * Accept both TraceContext and B3 style trace formats. Send only TraceContext style. Egressing only TraceContext style is done for backwards compatibility with the existing system, which sends TraceContext style. We could output both styles, but it was determined that the additional overhead of ~100 bytes on every outgoing message was not worth it. * Update CE clients. * hack/update-deps.sh * PR comments. * Undo changes to http_load_generator.go. --- cmd/sendevent/main.go | 9 +++++++-- go.mod | 4 ++-- go.sum | 8 ++++---- pkg/adapter/v2/cloudevents.go | 6 ++++++ pkg/channel/message_receiver_test.go | 6 +++++- pkg/kncloudevents/message_receiver.go | 4 ++-- pkg/kncloudevents/message_sender.go | 4 ++-- test/test_images/event-sender/main.go | 5 ++--- test/test_images/heartbeats/main.go | 11 ++++++++--- test/test_images/sequencestepper/main.go | 7 ++++++- test/test_images/transformevents/main.go | 8 ++++++-- test/upgrade/prober/wathola/client/receiver.go | 8 ++++++-- vendor/knative.dev/pkg/webhook/admission.go | 8 +++++++- vendor/modules.txt | 4 ++-- 14 files changed, 65 insertions(+), 27 deletions(-) diff --git a/cmd/sendevent/main.go b/cmd/sendevent/main.go index 33a90cadcea..73ce93a72bd 100644 --- a/cmd/sendevent/main.go +++ b/cmd/sendevent/main.go @@ -26,8 +26,9 @@ import ( "os" cloudevents "github.com/cloudevents/sdk-go/v2" - + "go.opencensus.io/plugin/ochttp" "knative.dev/eventing/pkg/utils" + "knative.dev/pkg/tracing/propagation/tracecontextb3" ) var ( @@ -64,7 +65,11 @@ func main() { source = fmt.Sprintf("http://%s", utils.GetClusterDomainName()) } - t, err := cloudevents.NewHTTP(cloudevents.WithTarget(target)) + t, err := cloudevents.NewHTTP( + cloudevents.WithTarget(target), + cloudevents.WithRoundTripper(&ochttp.Transport{ + Propagation: tracecontextb3.TraceContextEgress, + })) if err != nil { log.Printf("failed to create transport, %v", err) os.Exit(1) diff --git a/go.mod b/go.mod index 5778c6022f5..1ec05346d0c 100644 --- a/go.mod +++ b/go.mod @@ -38,8 +38,8 @@ require ( k8s.io/apiserver v0.17.6 k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible k8s.io/utils v0.0.0-20200124190032-861946025e34 - knative.dev/pkg v0.0.0-20200623204627-e0a0d63a9e86 - knative.dev/test-infra v0.0.0-20200623231727-6d5d6aeb457c + knative.dev/pkg v0.0.0-20200624155427-5be32bbb99ab + knative.dev/test-infra v0.0.0-20200624170028-94d227b0f50c sigs.k8s.io/yaml v1.2.0 ) diff --git a/go.sum b/go.sum index cdd789fcb4b..39de80122fe 100644 --- a/go.sum +++ b/go.sum @@ -1427,10 +1427,10 @@ knative.dev/pkg v0.0.0-20200515002500-16d7b963416f/go.mod h1:tMOHGbxtRz8zYFGEGpV knative.dev/pkg v0.0.0-20200520073958-94316e20e860/go.mod h1:QgNZTxnwpB/oSpNcfnLVlw+WpEwwyKAvJlvR3hgeltA= knative.dev/pkg v0.0.0-20200603222317-b79e4a24ca50/go.mod h1:8IfPj/lpuKHHg82xZCl2wuFZ3BM96To72sN1W8T9wjQ= knative.dev/pkg v0.0.0-20200611204322-2ddcfef739a2/go.mod h1:rA+FklsrVahwF4a+D63NyHJlzDoAFH81K4J5CYuE3bA= -knative.dev/pkg v0.0.0-20200623024526-fb0320d9287e h1:fmsw4i/We4S9yyaZadL2z8DKDIz7XzcY/v4yPGUmUA4= -knative.dev/pkg v0.0.0-20200623024526-fb0320d9287e/go.mod h1:DquzK0hsLDcg2q63Sn+CngAyRwv4cKMpt5F19YzBfb0= knative.dev/pkg v0.0.0-20200623204627-e0a0d63a9e86 h1:Ihxd/dMGFtVxrURj7NknkQlA7QmgCh63o10eQ8BlO/4= knative.dev/pkg v0.0.0-20200623204627-e0a0d63a9e86/go.mod h1:DquzK0hsLDcg2q63Sn+CngAyRwv4cKMpt5F19YzBfb0= +knative.dev/pkg v0.0.0-20200624155427-5be32bbb99ab h1:Alotvu0cJmIfbSitcmcCe39M2WZ430DO9GnsidpR7CM= +knative.dev/pkg v0.0.0-20200624155427-5be32bbb99ab/go.mod h1:DquzK0hsLDcg2q63Sn+CngAyRwv4cKMpt5F19YzBfb0= knative.dev/test-infra v0.0.0-20200407185800-1b88cb3b45a5/go.mod h1:xcdUkMJrLlBswIZqL5zCuBFOC22WIPMQoVX1L35i0vQ= knative.dev/test-infra v0.0.0-20200505052144-5ea2f705bb55/go.mod h1:WqF1Azka+FxPZ20keR2zCNtiQA1MP9ZB4BH4HuI+SIU= knative.dev/test-infra v0.0.0-20200513011557-d03429a76034/go.mod h1:aMif0KXL4g19YCYwsy4Ocjjz5xgPlseYV+B95Oo4JGE= @@ -1440,8 +1440,8 @@ knative.dev/test-infra v0.0.0-20200606045118-14ebc4a42974 h1:CrZmlbB+j3ZF/aTrfyy knative.dev/test-infra v0.0.0-20200606045118-14ebc4a42974/go.mod h1://I6IZIF0QDgs5wotU243ZZ5cTpm6/GthayjUenBBc0= knative.dev/test-infra v0.0.0-20200617235125-6382dba95484 h1:5D1Fm6aA1T1QQXLb1HkJ5t8gB9pTkhLYak1CCqIP+pE= knative.dev/test-infra v0.0.0-20200617235125-6382dba95484/go.mod h1:+BfrTJpc++rH30gX/C0QY6NT2eYVzycll52uw6CrQnc= -knative.dev/test-infra v0.0.0-20200623231727-6d5d6aeb457c h1:L8S12EWelqzc2HXY0gPg4H/3EqF3BN0v/ZyaHKzP5oU= -knative.dev/test-infra v0.0.0-20200623231727-6d5d6aeb457c/go.mod h1:qKM6vO6hD6aa0ZYGDdyr5YiXPQMhbix1K8UWPUvVlIE= +knative.dev/test-infra v0.0.0-20200624170028-94d227b0f50c h1:rnbevMO69+CbzbY+hNbariG9k/jicgTIDKPFvfp0hcc= +knative.dev/test-infra v0.0.0-20200624170028-94d227b0f50c/go.mod h1:6w3uf0+KfozLkrysBm3QqONrEMC6Uo/oEgS2BCdHJXo= modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw= modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk= modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k= diff --git a/pkg/adapter/v2/cloudevents.go b/pkg/adapter/v2/cloudevents.go index 7185da52cf4..0872b8b8c4e 100644 --- a/pkg/adapter/v2/cloudevents.go +++ b/pkg/adapter/v2/cloudevents.go @@ -21,6 +21,9 @@ import ( "fmt" "net/url" + "go.opencensus.io/plugin/ochttp" + "knative.dev/pkg/tracing/propagation/tracecontextb3" + cloudevents "github.com/cloudevents/sdk-go/v2" "github.com/cloudevents/sdk-go/v2/event" "github.com/cloudevents/sdk-go/v2/protocol" @@ -36,6 +39,9 @@ func NewCloudEventsClient(target string, ceOverrides *duckv1.CloudEventOverrides if len(target) > 0 { pOpts = append(pOpts, cloudevents.WithTarget(target)) } + pOpts = append(pOpts, cloudevents.WithRoundTripper(&ochttp.Transport{ + Propagation: tracecontextb3.TraceContextEgress, + })) p, err := cloudevents.NewHTTP(pOpts...) if err != nil { diff --git a/pkg/channel/message_receiver_test.go b/pkg/channel/message_receiver_test.go index 741dd4b7a45..26b2033ad95 100644 --- a/pkg/channel/message_receiver_test.go +++ b/pkg/channel/message_receiver_test.go @@ -31,8 +31,10 @@ import ( "github.com/cloudevents/sdk-go/v2/test" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" + "go.opencensus.io/plugin/ochttp" "go.opencensus.io/trace" _ "knative.dev/pkg/system/testing" + "knative.dev/pkg/tracing/propagation/tracecontextb3" "knative.dev/eventing/pkg/kncloudevents" "knative.dev/eventing/pkg/tracing" @@ -220,7 +222,9 @@ func TestMessageReceiver_ServerStart_trace_propagation(t *testing.T) { p, err := cloudevents.NewHTTP( http.WithTarget(server.URL), http.WithMethod(method), - ) + cloudevents.WithRoundTripper(&ochttp.Transport{ + Propagation: tracecontextb3.TraceContextEgress, + })) require.NoError(t, err) p.RequestTemplate.Host = host diff --git a/pkg/kncloudevents/message_receiver.go b/pkg/kncloudevents/message_receiver.go index 2f6f9857396..fb22daeeb72 100644 --- a/pkg/kncloudevents/message_receiver.go +++ b/pkg/kncloudevents/message_receiver.go @@ -23,7 +23,7 @@ import ( "time" "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/plugin/ochttp/propagation/tracecontext" + "knative.dev/pkg/tracing/propagation/tracecontextb3" ) const ( @@ -92,7 +92,7 @@ func WithShutdownTimeout(ctx context.Context, timeout time.Duration) context.Con func CreateHandler(handler nethttp.Handler) nethttp.Handler { return &ochttp.Handler{ - Propagation: &tracecontext.HTTPFormat{}, + Propagation: tracecontextb3.TraceContextEgress, Handler: handler, } } diff --git a/pkg/kncloudevents/message_sender.go b/pkg/kncloudevents/message_sender.go index bc110781553..cc6e757f3d7 100644 --- a/pkg/kncloudevents/message_sender.go +++ b/pkg/kncloudevents/message_sender.go @@ -21,7 +21,7 @@ import ( nethttp "net/http" "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/plugin/ochttp/propagation/tracecontext" + "knative.dev/pkg/tracing/propagation/tracecontextb3" ) // ConnectionArgs allow to configure connection parameters to the underlying @@ -54,7 +54,7 @@ func NewHttpMessageSender(connectionArgs *ConnectionArgs, target string) (*HttpM client := &nethttp.Client{ Transport: &ochttp.Transport{ Base: base, - Propagation: &tracecontext.HTTPFormat{}, + Propagation: tracecontextb3.TraceContextEgress, }, } diff --git a/test/test_images/event-sender/main.go b/test/test_images/event-sender/main.go index c218fb76bf3..89e8d98bcaa 100644 --- a/test/test_images/event-sender/main.go +++ b/test/test_images/event-sender/main.go @@ -30,10 +30,9 @@ import ( cloudevents "github.com/cloudevents/sdk-go/v2" cehttp "github.com/cloudevents/sdk-go/v2/protocol/http" "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/plugin/ochttp/propagation/tracecontext" "go.uber.org/zap" - "knative.dev/eventing/pkg/tracing" + "knative.dev/pkg/tracing/propagation/tracecontextb3" ) var ( @@ -114,7 +113,7 @@ func main() { httpOpts, cloudevents.WithRoundTripper(&ochttp.Transport{ Base: nethttp.DefaultTransport, - Propagation: &tracecontext.HTTPFormat{}, + Propagation: tracecontextb3.TraceContextEgress, }), ) } diff --git a/test/test_images/heartbeats/main.go b/test/test_images/heartbeats/main.go index 5986c6f8e1f..1ef0544c218 100644 --- a/test/test_images/heartbeats/main.go +++ b/test/test_images/heartbeats/main.go @@ -26,10 +26,11 @@ import ( "strconv" "time" - duckv1 "knative.dev/pkg/apis/duck/v1" - cloudevents "github.com/cloudevents/sdk-go/v2" "github.com/kelseyhightower/envconfig" + "go.opencensus.io/plugin/ochttp" + duckv1 "knative.dev/pkg/apis/duck/v1" + "knative.dev/pkg/tracing/propagation/tracecontextb3" ) type Heartbeat struct { @@ -89,7 +90,11 @@ func main() { ceOverrides = &overrides } - p, err := cloudevents.NewHTTP(cloudevents.WithTarget(sink)) + p, err := cloudevents.NewHTTP( + cloudevents.WithTarget(sink), + cloudevents.WithRoundTripper(&ochttp.Transport{ + Propagation: tracecontextb3.TraceContextEgress, + })) if err != nil { log.Fatalf("failed to create protocol: %s", err.Error()) } diff --git a/test/test_images/sequencestepper/main.go b/test/test_images/sequencestepper/main.go index ca98622d676..02dfa946b0d 100644 --- a/test/test_images/sequencestepper/main.go +++ b/test/test_images/sequencestepper/main.go @@ -22,6 +22,8 @@ import ( "flag" "log" + "knative.dev/eventing/pkg/kncloudevents" + cloudevents "github.com/cloudevents/sdk-go/v2" ) @@ -61,7 +63,10 @@ func main() { // parse the command line flags flag.Parse() - t, err := cloudevents.NewHTTP(cloudevents.WithPort(8080)) + t, err := cloudevents.NewHTTP( + cloudevents.WithPort(8080), + cloudevents.WithMiddleware(kncloudevents.CreateHandler), + ) if err != nil { log.Fatalf("failed to create transport, %v", err) } diff --git a/test/test_images/transformevents/main.go b/test/test_images/transformevents/main.go index 55e712f61a7..502e995d68d 100644 --- a/test/test_images/transformevents/main.go +++ b/test/test_images/transformevents/main.go @@ -21,9 +21,10 @@ import ( "flag" "log" + "knative.dev/eventing/pkg/kncloudevents" + cloudevents "github.com/cloudevents/sdk-go/v2" "go.uber.org/zap" - "knative.dev/eventing/pkg/tracing" ) @@ -72,7 +73,10 @@ func main() { log.Fatalf("Unable to setup trace publishing: %v", err) } - t, err := cloudevents.NewHTTP(cloudevents.WithPort(8080)) + t, err := cloudevents.NewHTTP( + cloudevents.WithPort(8080), + cloudevents.WithMiddleware(kncloudevents.CreateHandler), + ) if err != nil { log.Fatalf("failed to create transport, %v", err) } diff --git a/test/upgrade/prober/wathola/client/receiver.go b/test/upgrade/prober/wathola/client/receiver.go index 0571abfada9..ed73e67794b 100644 --- a/test/upgrade/prober/wathola/client/receiver.go +++ b/test/upgrade/prober/wathola/client/receiver.go @@ -23,7 +23,9 @@ import ( cloudevents "github.com/cloudevents/sdk-go/v2" cloudeventshttp "github.com/cloudevents/sdk-go/v2/protocol/http" "github.com/wavesoftware/go-ensure" + "go.opencensus.io/plugin/ochttp" "knative.dev/eventing/test/upgrade/prober/wathola/config" + "knative.dev/pkg/tracing/propagation/tracecontextb3" ) var log = config.Log @@ -38,9 +40,11 @@ func Receive( receiveEvent ReceiveEvent, middlewares ...cloudeventshttp.Middleware, ) { - portOpt := cloudevents.WithPort(port) opts := make([]cloudeventshttp.Option, 0) - opts = append(opts, portOpt) + opts = append(opts, cloudevents.WithPort(port)) + opts = append(opts, cloudevents.WithRoundTripper(&ochttp.Transport{ + Propagation: tracecontextb3.TraceContextEgress, + })) if config.Instance.Readiness.Enabled { readyOpt := cloudevents.WithMiddleware(readinessMiddleware) opts = append(opts, readyOpt) diff --git a/vendor/knative.dev/pkg/webhook/admission.go b/vendor/knative.dev/pkg/webhook/admission.go index 086f39dab14..46d4c08c4e9 100644 --- a/vendor/knative.dev/pkg/webhook/admission.go +++ b/vendor/knative.dev/pkg/webhook/admission.go @@ -88,7 +88,13 @@ func admissionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c Admi ctx := logging.WithLogger(r.Context(), logger) - var response admissionv1.AdmissionReview + response := admissionv1.AdmissionReview{ + // Use the same type meta as the request - this is required by the K8s API + // note: v1beta1 & v1 AdmissionReview shapes are identical so even though + // we're using v1 types we still support v1beta1 admission requests + TypeMeta: review.TypeMeta, + } + reviewResponse := c.Admit(ctx, review.Request) var patchType string if reviewResponse.PatchType != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index b81f8d016d3..3c310437f17 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -944,7 +944,7 @@ k8s.io/utils/buffer k8s.io/utils/integer k8s.io/utils/pointer k8s.io/utils/trace -# knative.dev/pkg v0.0.0-20200623204627-e0a0d63a9e86 +# knative.dev/pkg v0.0.0-20200624155427-5be32bbb99ab ## explicit knative.dev/pkg/apiextensions/storageversion knative.dev/pkg/apiextensions/storageversion/cmd/migrate @@ -1060,7 +1060,7 @@ knative.dev/pkg/webhook/resourcesemantics knative.dev/pkg/webhook/resourcesemantics/conversion knative.dev/pkg/webhook/resourcesemantics/defaulting knative.dev/pkg/webhook/resourcesemantics/validation -# knative.dev/test-infra v0.0.0-20200623231727-6d5d6aeb457c +# knative.dev/test-infra v0.0.0-20200624170028-94d227b0f50c ## explicit knative.dev/test-infra/scripts # sigs.k8s.io/yaml v1.2.0