Skip to content

Commit

Permalink
Accept both B3 and TraceContext style tracing (knative#3388)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Harwayne authored and lberk committed Jun 26, 2020
1 parent 15422e0 commit d0a288e
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 27 deletions.
9 changes: 7 additions & 2 deletions cmd/sendevent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
6 changes: 6 additions & 0 deletions pkg/adapter/v2/cloudevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion pkg/channel/message_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pkg/kncloudevents/message_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
}
}
4 changes: 2 additions & 2 deletions pkg/kncloudevents/message_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
}

Expand Down
5 changes: 2 additions & 3 deletions test/test_images/event-sender/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -114,7 +113,7 @@ func main() {
httpOpts,
cloudevents.WithRoundTripper(&ochttp.Transport{
Base: nethttp.DefaultTransport,
Propagation: &tracecontext.HTTPFormat{},
Propagation: tracecontextb3.TraceContextEgress,
}),
)
}
Expand Down
11 changes: 8 additions & 3 deletions test/test_images/heartbeats/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
}
Expand Down
7 changes: 6 additions & 1 deletion test/test_images/sequencestepper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"flag"
"log"

"knative.dev/eventing/pkg/kncloudevents"

cloudevents "github.com/cloudevents/sdk-go/v2"
)

Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions test/test_images/transformevents/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions test/upgrade/prober/wathola/client/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion vendor/knative.dev/pkg/webhook/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d0a288e

Please sign in to comment.