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

Accept both B3 and TraceContext style tracing #3388

Merged
merged 7 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
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-20200623024526-fb0320d9287e
knative.dev/test-infra v0.0.0-20200623005026-1f7e5f05c52b
knative.dev/pkg v0.0.0-20200623173527-5658d93fb07e
knative.dev/test-infra v0.0.0-20200623145727-e9ff5263be06
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-20200619020725-7df8fc5d7743 h1:W1NKMizoXYYX5e2mkFXnn21T7X6ROKKwL8YetGu7xCQ=
knative.dev/pkg v0.0.0-20200619020725-7df8fc5d7743/go.mod h1:DquzK0hsLDcg2q63Sn+CngAyRwv4cKMpt5F19YzBfb0=
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-20200623173527-5658d93fb07e h1:MhQNsqYZ5BuDyZT/Q5MQMTMYTmkLcwq6MY+gGvPkymY=
knative.dev/pkg v0.0.0-20200623173527-5658d93fb07e/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-20200623005026-1f7e5f05c52b h1:qQTd9xCiV3/PVt2LsmELMVL2gT4eAScMaFrPqiQnt1I=
knative.dev/test-infra v0.0.0-20200623005026-1f7e5f05c52b/go.mod h1:H8QEB2Y35+vAuVtDbn7QBD+NQr9zQbbxNiovCLNH7F4=
knative.dev/test-infra v0.0.0-20200623145727-e9ff5263be06 h1:6LNkyjc5iPk+Q47wwixmc9CL/0GIL40wZWGlwHXTDRc=
knative.dev/test-infra v0.0.0-20200623145727-e9ff5263be06/go.mod h1:qKM6vO6hD6aa0ZYGDdyr5YiXPQMhbix1K8UWPUvVlIE=
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
7 changes: 5 additions & 2 deletions test/performance/infra/sender/http_load_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import (
"github.com/google/uuid"
"github.com/rogpeppe/fastuuid"
vegeta "github.com/tsenart/vegeta/lib"

"go.opencensus.io/plugin/ochttp"
"knative.dev/eventing/test/performance/infra/common"
"knative.dev/pkg/tracing/propagation/tracecontextb3"
)

func init() {
Expand Down Expand Up @@ -188,7 +189,9 @@ func vegetaAttackerTransport() *http.Transport {
func newCloudEventsClient(sinkUrl string) (cloudevents.Client, error) {
t, err := cloudevents.NewHTTP(
cloudevents.WithTarget(sinkUrl),
)
cloudevents.WithRoundTripper(&ochttp.Transport{
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need tracing in performance images, it's not even configured

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Propagation: tracecontextb3.TraceContextEgress,
}))
if err != nil {
return nil, fmt.Errorf("failed to create transport: %v", err)
}
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
8 changes: 7 additions & 1 deletion test/test_images/sequencestepper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"log"

cloudevents "github.com/cloudevents/sdk-go/v2"
"go.opencensus.io/plugin/ochttp"
"knative.dev/pkg/tracing/propagation/tracecontextb3"
)

var (
Expand Down Expand Up @@ -61,7 +63,11 @@ func main() {
// parse the command line flags
flag.Parse()

t, err := cloudevents.NewHTTP(cloudevents.WithPort(8080))
t, err := cloudevents.NewHTTP(
cloudevents.WithPort(8080),
cloudevents.WithRoundTripper(&ochttp.Transport{
Copy link
Contributor

Choose a reason for hiding this comment

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

This image uses only the receiver, so you don't need WithRoundTripper, because it's used only for the underlying HTTP client, for the server side you need to use WithMiddleware (you could easily reuse kncloudevents.CreateHandler for this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Propagation: tracecontextb3.TraceContextEgress,
}))
if err != nil {
log.Fatalf("failed to create transport, %v", err)
}
Expand Down
9 changes: 7 additions & 2 deletions test/test_images/transformevents/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
"log"

cloudevents "github.com/cloudevents/sdk-go/v2"
"go.opencensus.io/plugin/ochttp"
"go.uber.org/zap"

"knative.dev/eventing/pkg/tracing"
"knative.dev/pkg/tracing/propagation/tracecontextb3"
)

var (
Expand Down Expand Up @@ -72,7 +73,11 @@ 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.WithRoundTripper(&ochttp.Transport{
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as comment above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Propagation: tracecontextb3.TraceContextEgress,
}))
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
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func isKRShaped(tags map[string]map[string]string) bool {
if !has {
return false
}
return vals["krshapedlogic"] == "true"
return vals["krshapedlogic"] != "false"
}

func isNonNamespaced(tags map[string]map[string]string) bool {
Expand Down
4 changes: 2 additions & 2 deletions vendor/knative.dev/pkg/test/spoof/spoof.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (
"knative.dev/pkg/test/ingress"
"knative.dev/pkg/test/logging"
"knative.dev/pkg/test/zipkin"
"knative.dev/pkg/tracing/propagation/tracecontextb3"

"go.opencensus.io/plugin/ochttp"
"go.opencensus.io/plugin/ochttp/propagation/b3"
"go.opencensus.io/trace"
)

Expand Down Expand Up @@ -135,7 +135,7 @@ func New(
// Enable Zipkin tracing
roundTripper := &ochttp.Transport{
Base: transport,
Propagation: &b3.HTTPFormat{},
Propagation: tracecontextb3.TraceContextEgress,
}

sc := SpoofingClient{
Expand Down
2 changes: 2 additions & 0 deletions vendor/knative.dev/pkg/tracing/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go.opencensus.io/plugin/ochttp"
"go.opencensus.io/trace"
"k8s.io/apimachinery/pkg/util/sets"
"knative.dev/pkg/tracing/propagation/tracecontextb3"
)

var (
Expand Down Expand Up @@ -50,6 +51,7 @@ func HTTPSpanIgnoringPaths(pathsToIgnore ...string) func(http.Handler) http.Hand
}
return underlyingSampling
},
Propagation: tracecontextb3.TraceContextEgress,
}
}
}
53 changes: 53 additions & 0 deletions vendor/knative.dev/pkg/tracing/propagation/http_format_sequence.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2020 The Knative Authors

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 propagation

import (
"net/http"

"go.opencensus.io/trace"
"go.opencensus.io/trace/propagation"
)

// HTTPFormatSequence is a propagation.HTTPFormat that applies multiple other propagation formats.
// For incoming requests, it will use the first SpanContext it can find, checked in the order of
// HTTPFormatSequence.Ingress.
// For outgoing requests, it will apply all the formats to the outgoing request, in the order of
// HTTPFormatSequence.Egress.
type HTTPFormatSequence struct {
Ingress []propagation.HTTPFormat
Egress []propagation.HTTPFormat
}

var _ propagation.HTTPFormat = (*HTTPFormatSequence)(nil)

// SpanContextFromRequest satisfies the propagation.HTTPFormat interface.
func (h *HTTPFormatSequence) SpanContextFromRequest(req *http.Request) (trace.SpanContext, bool) {
for _, format := range h.Ingress {
if sc, ok := format.SpanContextFromRequest(req); ok {
return sc, true
}
}
return trace.SpanContext{}, false
}

// SpanContextToRequest satisfies the propagation.HTTPFormat interface.
func (h *HTTPFormatSequence) SpanContextToRequest(sc trace.SpanContext, req *http.Request) {
for _, format := range h.Egress {
format.SpanContextToRequest(sc, req)
}
}
Loading