From 097daafeacee6a61880fb934dd8c45ebcea70e51 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Mon, 30 Sep 2019 10:58:19 -0700 Subject: [PATCH 01/20] Copied verbatim from @daisy-ycguo's https://github.com/knative/eventing/pull/1878. --- test/conformance/broker_tracing_test.go | 26 ++++ .../helpers/broker_tracing_test_helper.go | 145 ++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 test/conformance/broker_tracing_test.go create mode 100644 test/conformance/helpers/broker_tracing_test_helper.go diff --git a/test/conformance/broker_tracing_test.go b/test/conformance/broker_tracing_test.go new file mode 100644 index 00000000000..e193d266c60 --- /dev/null +++ b/test/conformance/broker_tracing_test.go @@ -0,0 +1,26 @@ +// +build e2e + +/* +Copyright 2019 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 conformance + +import ( + "testing" + + "knative.dev/eventing/test/conformance/helpers" +) + +func TestBrokerTracing(t *testing.T) { + helpers.BrokerTracingTestHelper(t, channelTestRunner) +} diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go new file mode 100644 index 00000000000..9bb43630c2c --- /dev/null +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -0,0 +1,145 @@ +/* +Copyright 2019 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 helpers + +import ( + "fmt" + "testing" + "time" + + "k8s.io/apimachinery/pkg/util/uuid" + "knative.dev/eventing/pkg/apis/eventing/v1alpha1" + "knative.dev/eventing/test/base/resources" + "knative.dev/eventing/test/common" + tracinghelper "knative.dev/eventing/test/conformance/helpers/tracing" + "knative.dev/pkg/test/zipkin" +) + +func BrokerTracingTestHelper(t *testing.T, channelTestRunner common.ChannelTestRunner) { + testCases := map[string]struct { + incomingTraceId bool + istio bool + }{ + "no incoming trace id": {}, + "includes incoming trace id": { + incomingTraceId: true, + }, /* + "caller has istio": { + istio: true, + },*/ + } + + for n, tc := range testCases { + loggerPodName := "logger" + t.Run(n, func(t *testing.T) { + channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel string) { + // Don't accidentally use t, use st instead. To ensure this, shadow 't' to some a + // useless type. + t := struct{}{} + _ = fmt.Sprintf("%s", t) + + client := common.Setup(st, true) + defer common.TearDown(client) + + // Do NOT call zipkin.CleanupZipkinTracingSetup. That will be called exactly once in + // TestMain. + tracinghelper.Setup(st, client) + + mustContain := setupBrokerTracing(st, channel, client, loggerPodName, tc.incomingTraceId) + assertLogContents(st, client, loggerPodName, mustContain) + + traceID := getTraceID(st, client, loggerPodName) + expectedNumSpans := 11 + if tc.incomingTraceId { + expectedNumSpans = 12 + } + trace, err := zipkin.JSONTrace(traceID, expectedNumSpans, 15*time.Second) + if err != nil { + st.Fatalf("Unable to get trace %q: %v", traceID, err) + } + st.Logf("I got the trace, %q!\n%+v", traceID, trace) + + // TODO: Assert information in the trace. + }) + }) + } +} + +// setupBrokerTracing is the general setup for TestBrokerTracing. It creates the following: +// SendEvents (Pod) -> Broker -> Subscription -> K8s Service -> LogEvents (Pod) +// It returns a string that is expected to be sent by the SendEvents Pod and should be present in +// the LogEvents Pod logs. +func setupBrokerTracing(t *testing.T, channel string, client *common.Client, loggerPodName string, incomingTraceId bool) string { + // Create the Broker. + const ( + brokerName = "br" + eventTypeFoo = "foo" + eventTypeBar = "bar" + mutatorPodName = "mutator" + any = v1alpha1.TriggerAnyFilter + ) + channelTypeMeta := common.GetChannelTypeMeta(channel) + client.CreateBrokerOrFail(brokerName, channelTypeMeta) + + // Create a LogEvents Pod and a K8s Service that points to it. + logPod := resources.EventDetailsPod(loggerPodName) + client.CreatePodOrFail(logPod, common.WithService(loggerPodName)) + + // Create a Trigger that receive events (type=bar) and send to logger Pod. + client.CreateTriggerOrFail( + "trigger-trace", + resources.WithBroker(brokerName), + resources.WithDeprecatedSourceAndTypeTriggerFilter(any, eventTypeBar), + resources.WithSubscriberRefForTrigger(loggerPodName), + ) + + // Create an event mutator to response an event with type bar + eventMutatorPod := resources.EventMutatorPod(mutatorPodName, eventTypeBar) + client.CreatePodOrFail(eventMutatorPod, common.WithService(mutatorPodName)) + + // Create a Trigger that receive events (type=foo) and send to event mutator Pod. + client.CreateTriggerOrFail( + "trigger-trace", + resources.WithBroker(brokerName), + resources.WithDeprecatedSourceAndTypeTriggerFilter(any, eventTypeBar), + resources.WithSubscriberRefForTrigger(loggerPodName), + ) + + // Wait for all test resources to be ready, so that we can start sending events. + if err := client.WaitForAllTestResourcesReady(); err != nil { + t.Fatalf("Failed to get all test resources ready: %v", err) + } + + // Everything is setup to receive an event. Generate a CloudEvent. + senderName := "sender" + eventID := fmt.Sprintf("%s", uuid.NewUUID()) + body := fmt.Sprintf("TestBrokerTracing %s", eventID) + event := &resources.CloudEvent{ + ID: eventID, + Source: senderName, + Type: eventTypeFoo, + Data: fmt.Sprintf(`{"msg":%q}`, body), + Encoding: resources.CloudEventEncodingBinary, + } + + // Send the CloudEvent (either with or without tracing inside the SendEvents Pod). + sendEvent := client.SendFakeEventToAddressable + if incomingTraceId { + sendEvent = client.SendFakeEventWithTracingToAddressable + } + if err := sendEvent(senderName, brokerName, common.BrokerTypeMeta, event); err != nil { + t.Fatalf("Failed to send fake CloudEvent to the broker %q", brokerName) + } + return body +} From f61cc37a4d59f99a1e527e16e7d17b5584b4c99c Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Mon, 30 Sep 2019 11:47:42 -0700 Subject: [PATCH 02/20] Trace outline. --- test/common/creation.go | 5 +- .../helpers/broker_tracing_test_helper.go | 407 ++++++++++++++++-- 2 files changed, 377 insertions(+), 35 deletions(-) diff --git a/test/common/creation.go b/test/common/creation.go index eae37959fa6..0634bd74329 100644 --- a/test/common/creation.go +++ b/test/common/creation.go @@ -19,6 +19,8 @@ package common import ( "fmt" + "knative.dev/eventing/pkg/apis/eventing/v1alpha1" + corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -117,7 +119,7 @@ func (client *Client) CreateBrokersOrFail(names []string, channelTypeMeta *metav } // CreateTriggerOrFail will create a Trigger or fail the test if there is an error. -func (client *Client) CreateTriggerOrFail(name string, options ...resources.TriggerOption) { +func (client *Client) CreateTriggerOrFail(name string, options ...resources.TriggerOption) *v1alpha1.Trigger { namespace := client.Namespace trigger := resources.Trigger(name, options...) @@ -128,6 +130,7 @@ func (client *Client) CreateTriggerOrFail(name string, options ...resources.Trig client.T.Fatalf("Failed to create trigger %q: %v", name, err) } client.Tracker.AddObj(trigger) + return trigger } // CreateSequenceOrFail will create a Sequence or fail the test if there is an error. diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 9bb43630c2c..41cb0ac84d1 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -18,6 +18,7 @@ import ( "testing" "time" + "github.com/openzipkin/zipkin-go/model" "k8s.io/apimachinery/pkg/util/uuid" "knative.dev/eventing/pkg/apis/eventing/v1alpha1" "knative.dev/eventing/test/base/resources" @@ -31,13 +32,9 @@ func BrokerTracingTestHelper(t *testing.T, channelTestRunner common.ChannelTestR incomingTraceId bool istio bool }{ - "no incoming trace id": {}, "includes incoming trace id": { incomingTraceId: true, - }, /* - "caller has istio": { - istio: true, - },*/ + }, } for n, tc := range testCases { @@ -56,64 +53,64 @@ func BrokerTracingTestHelper(t *testing.T, channelTestRunner common.ChannelTestR // TestMain. tracinghelper.Setup(st, client) - mustContain := setupBrokerTracing(st, channel, client, loggerPodName, tc.incomingTraceId) + expected, mustContain := setupBrokerTracing(st, channel, client, loggerPodName, tc.incomingTraceId) assertLogContents(st, client, loggerPodName, mustContain) - traceID := getTraceID(st, client, loggerPodName) - expectedNumSpans := 11 - if tc.incomingTraceId { - expectedNumSpans = 12 - } - trace, err := zipkin.JSONTrace(traceID, expectedNumSpans, 15*time.Second) + trace, err := zipkin.JSONTrace(traceID, expected.SpanCount(), 60*time.Second) if err != nil { - st.Fatalf("Unable to get trace %q: %v", traceID, err) + st.Fatalf("Unable to get trace %q: %v. Trace so far %+v", traceID, err, tracinghelper.PrettyPrintTrace(trace)) } - st.Logf("I got the trace, %q!\n%+v", traceID, trace) + st.Logf("I got the trace, %q!\n%+v", traceID, tracinghelper.PrettyPrintTrace(trace)) - // TODO: Assert information in the trace. + tree := tracinghelper.GetTraceTree(st, trace) + if err := expected.Matches(tree); err != nil { + st.Fatalf("Trace Tree did not match expected: %v", err) + } }) }) } } // setupBrokerTracing is the general setup for TestBrokerTracing. It creates the following: -// SendEvents (Pod) -> Broker -> Subscription -> K8s Service -> LogEvents (Pod) +// 1. Broker. +// 2. Trigger on 'foo' events -> K8s Service -> transformer Pod (which replies with a 'bar' event). +// 3. Trigger on 'bar' events -> K8s Service -> eventdetails Pod. // It returns a string that is expected to be sent by the SendEvents Pod and should be present in // the LogEvents Pod logs. -func setupBrokerTracing(t *testing.T, channel string, client *common.Client, loggerPodName string, incomingTraceId bool) string { +func setupBrokerTracing(t *testing.T, channel string, client *common.Client, loggerPodName string, incomingTraceId bool) (tracinghelper.TestSpanTree, string) { // Create the Broker. const ( - brokerName = "br" - eventTypeFoo = "foo" - eventTypeBar = "bar" - mutatorPodName = "mutator" - any = v1alpha1.TriggerAnyFilter + brokerName = "br" + etTransformer = "transformer" + etLogger = "logger" ) channelTypeMeta := common.GetChannelTypeMeta(channel) client.CreateBrokerOrFail(brokerName, channelTypeMeta) - // Create a LogEvents Pod and a K8s Service that points to it. + // Create an logger (EventDetails) Pod and a K8s Service that points to it. logPod := resources.EventDetailsPod(loggerPodName) client.CreatePodOrFail(logPod, common.WithService(loggerPodName)) // Create a Trigger that receive events (type=bar) and send to logger Pod. - client.CreateTriggerOrFail( - "trigger-trace", + loggerTrigger := client.CreateTriggerOrFail( + "logger", resources.WithBroker(brokerName), - resources.WithDeprecatedSourceAndTypeTriggerFilter(any, eventTypeBar), + resources.WithAttributesTriggerFilter(v1alpha1.TriggerAnyFilter, etLogger, map[string]interface{}{}), resources.WithSubscriberRefForTrigger(loggerPodName), ) // Create an event mutator to response an event with type bar - eventMutatorPod := resources.EventMutatorPod(mutatorPodName, eventTypeBar) - client.CreatePodOrFail(eventMutatorPod, common.WithService(mutatorPodName)) + eventTransformerPod := resources.EventTransformationPod("transformer", &resources.CloudEvent{ + Type: etLogger, + }) + client.CreatePodOrFail(eventTransformerPod, common.WithService(eventTransformerPod.Name)) // Create a Trigger that receive events (type=foo) and send to event mutator Pod. - client.CreateTriggerOrFail( - "trigger-trace", + transformerTrigger := client.CreateTriggerOrFail( + "transformer", resources.WithBroker(brokerName), - resources.WithDeprecatedSourceAndTypeTriggerFilter(any, eventTypeBar), - resources.WithSubscriberRefForTrigger(loggerPodName), + resources.WithAttributesTriggerFilter(v1alpha1.TriggerAnyFilter, etTransformer, map[string]interface{}{}), + resources.WithSubscriberRefForTrigger(eventTransformerPod.Name), ) // Wait for all test resources to be ready, so that we can start sending events. @@ -128,7 +125,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log event := &resources.CloudEvent{ ID: eventID, Source: senderName, - Type: eventTypeFoo, + Type: etTransformer, Data: fmt.Sprintf(`{"msg":%q}`, body), Encoding: resources.CloudEventEncodingBinary, } @@ -141,5 +138,347 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log if err := sendEvent(senderName, brokerName, common.BrokerTypeMeta, event); err != nil { t.Fatalf("Failed to send fake CloudEvent to the broker %q", brokerName) } - return body + + // TODO Actually determine the cluster's domain, similar to knative.dev/pkg/network/domain.go. + domain := "cluster.local" + + // We expect the following spans: + // 0. Artificial root span. + // 1. Send pod sends event to the Broker Ingress (only if the sending pod generates a span). + // 2. Broker Ingress receives the event from the sending pod. + // 3. Broker Ingress sends the event to the Broker's TrChannel (trigger channel). + // 4. Broker TrChannel receives the event from the Broker Ingress. + // 5. Broker TrChannel sends the event to the Broker Filter for the "logger" trigger. + // 6. Broker Filter for the "logger" trigger receives the event from the Broker TrChannel. + // This does not pass the filter, so this 'branch' ends here. + // 7. Broker TrChannel sends the event to the Broker Filter for the "transformer" trigger. + // 8. Broker Filter for the "transformer" trigger receives the event from the Broker TrChannel. + // 9. Broker Filter for the "transformer" trigger sends the event to the transformer pod. + // 10. Transformer pod receives the event from the Broker Filter for the "transformer" trigger. + // 11. Broker Filter for the "transformer" sends the transformer pod's reply to the Broker + // InChannel (Ingress Channel). + // 12. Broker InChannel receives the event from the Broker Filter for the "transformer" trigger. + // 13. Broker InChannel sends the event to the Broker Ingress. + // 14. Broker Ingress receives the event from the Broker InChannel. + // 15. Broker Ingress sends the event to the Broker's TrChannel. + // 16. Broker TrChannel receives the event from the Broker Ingress. + // 17. Broker TrChannel sends the event to the Broker Filter for the "transformer" trigger. + // 18. Broker Filter for the "transformer" trigger receives the event from the Broker + // TrChannel. This does not pass the filter, so this 'branch' ends here. + // 19. Broker TrChannel sends the event to the Broker Filter for the "logger" trigger. + // 20. Broker Filter for the "logger" trigger receives the event from the Broker TrChannel. + // 21. Broker Filter for the "logger" trigger sends the event to the logger pod. + // 22. Logger pod receives the event from the Broker Filter for the "logger" trigger. + + // Useful constants we will use below. + ingressHost := fmt.Sprintf("%s-broker.%s.svc.%s", brokerName, client.Namespace, domain) + triggerChanHost := fmt.Sprintf("%s-kne-trigger.%s.svc.%s", brokerName, client.Namespace, domain) + ingressChanHost := fmt.Sprintf("%s-kne-ingress.%s.svc.%s", brokerName, client.Namespace, domain) + filterHost := fmt.Sprintf("%s-broker-filter.%s.svc.%s", brokerName, client.Namespace, domain) + loggerTriggerPath := fmt.Sprintf("/triggers/%s/%s/%s", client.Namespace, loggerTrigger.Name, loggerTrigger.UID) + transformerTriggerPath := fmt.Sprintf("/triggers/%s/%s/%s", client.Namespace, transformerTrigger.Name, transformerTrigger.UID) + loggerSVCHost := fmt.Sprintf("%s.%s.svc.%s", loggerPodName, client.Namespace, domain) + transformerSVCHost := fmt.Sprintf("%s.%s.svc.%s", eventTransformerPod.Name, client.Namespace, domain) + + // This is very hard to read when written directly, so we will build piece by piece. + + // Steps 17-18: 'logger' event being sent to the 'transformer' Trigger. + loggerEventSentFromTrChannelToTransformer := tracinghelper.TestSpanTree{ + // 17. Broker TrChannel sends the event to the Broker Filter for the "transformer" trigger. + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s/%s", filterHost, transformerTriggerPath), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 18. Broker Filter for the "transformer" trigger receives the event from the + // Broker TrChannel. This does not pass the filter, so this 'branch' ends here. + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.host": filterHost, + "http.path": transformerTriggerPath, + }, + }, + }, + } + + // Steps 19-22: 'logger' event being sent to the 'logger' Trigger. + loggerEventSentFromTrChannelToLogger := tracinghelper.TestSpanTree{ + // 19. Broker TrChannel sends the event to the Broker Filter for the "logger" trigger. + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s/%s", filterHost, loggerTriggerPath), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 20. Broker Filter for the "logger" trigger receives the event from the Broker TrChannel. + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.host": filterHost, + "http.path": transformerTriggerPath, + }, + Children: []tracinghelper.TestSpanTree{ + { + // 21. Broker Filter for the "logger" trigger sends the event to the logger pod. + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s/", loggerSVCHost), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 22. Logger pod receives the event from the Broker Filter for the "logger" trigger. + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.path": "/", + "http.status_code": "202", + "http.host": fmt.Sprintf("unknown-foobar="), + }, + }, + }, + }, + }, + }, + }, + } + + // Steps 13-22. Directly steps 13-16. 17-22 are included as children. + // Steps 13-16: Event in the Broker InChannel sent to the Broker Ingress to the Trigger Channel. + loggerEventIngressToTrigger := tracinghelper.TestSpanTree{ + // 13. Broker InChannel sends the event to the Broker Ingress. + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s/", ingressHost), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 14. Broker Ingress receives the event from the Broker InChannel. + Kind: model.Server, + Tags: map[string]string{ + + "http.method": "POST", + "http.path": "/", + "http.status_code": "202", + "http.host": ingressHost, + }, + Children: []tracinghelper.TestSpanTree{ + { + // 15. Broker Ingress sends the event to the Broker's TrChannel. + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s", triggerChanHost), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 16. Broker TrChannel receives the event from the Broker Ingress. + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.host": triggerChanHost, + "http.path": "/", + }, + Children: []tracinghelper.TestSpanTree{ + // Steps 17-18. + loggerEventSentFromTrChannelToTransformer, + // Steps 19-22. + loggerEventSentFromTrChannelToLogger, + }, + }, + }, + }, + }, + }, + }, + } + + // Steps 7-22. Directly steps 7-12. 13-22 are included as children. + // Steps 7-12: Event from TrChannel sent to transformer Trigger and its reply to the InChannel. + transformerEventSentFromTrChannelToTransformer := tracinghelper.TestSpanTree{ + // 7. Broker TrChannel sends the event to the Broker Filter for the "transformer" trigger. + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s/%s", filterHost, transformerTriggerPath), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 8. Broker Filter for the "transformer" trigger receives the event from the Broker + // TrChannel. + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.host": filterHost, + "http.path": transformerTriggerPath, + }, + Children: []tracinghelper.TestSpanTree{ + { + // 9. Broker Filter for the "transformer" trigger sends the event to the + // transformer pod. + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s/", transformerSVCHost), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 10. Transformer pod receives the event from the Broker Filter for + // the "transformer" trigger. + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.path": "/", + "http.status_code": "202", + "http.host": fmt.Sprintf("unknown-bazqux="), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 11. Broker Filter for the "transformer" sends the + // transformer pod's reply to the Broker InChannel. + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s", ingressChanHost), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 12. Broker InChannel receives the event from the + // Broker Filter for the "transformer" trigger. + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": ingressChanHost, + "http.path": "/", + }, + Children: []tracinghelper.TestSpanTree{ + // Steps 13-22. + loggerEventIngressToTrigger, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + + // Steps 5-6: Event from TrChannel sent to logger Trigger. + transformerEventSentFromTrChannelToLogger := tracinghelper.TestSpanTree{ + // 5. Broker TrChannel sends the event to the Broker Filter for the "logger" trigger. + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s/%s", filterHost, loggerTriggerPath), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 6. Broker Filter for the "logger" trigger receives the event from the Broker + // TrChannel. This does not pass the filter, so this 'branch' ends here. + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.host": filterHost, + "http.path": loggerTriggerPath, + }, + }, + }, + } + + // 0. Artificial root span. + // 1. Send pod sends event to the Broker Ingress (only if the sending pod generates a span). + // 2. Broker Ingress receives the event from the sending pod. + // 3. Broker Ingress sends the event to the Broker's TrChannel (trigger channel). + // 4. Broker TrChannel receives the event from the Broker Ingress. + + // Steps 0-22. Directly steps 0-4 (missing 1) + // Steps 0-4 (missing 1, which is optional and added below if present): Event sent to the Broker + // Ingress. + expected := tracinghelper.TestSpanTree{ + // 0. Artificial root span. + Root: true, + Children: []tracinghelper.TestSpanTree{ + { + // 2. Broker Ingress receives the event from the sending pod. + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.host": ingressHost, + "http.path": "/", + }, + Children: []tracinghelper.TestSpanTree{ + { + // 3. Broker Ingress sends the event to the Broker's TrChannel (trigger channel). + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s", triggerChanHost), + }, + Children: []tracinghelper.TestSpanTree{ + { + // 4. Broker TrChannel receives the event from the Broker Ingress. + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.host": triggerChanHost, + "http.path": "/", + }, + Children: []tracinghelper.TestSpanTree{ + // Steps 5-6. + transformerEventSentFromTrChannelToLogger, + // Steps 7-22. + transformerEventSentFromTrChannelToTransformer, + }, + }, + }, + }, + }, + }, + }, + } + + if incomingTraceId { + expected.Children = []tracinghelper.TestSpanTree{ + { + // 1. Send pod sends event to the Broker Ingress (only if the sending pod generates + // a span). + Kind: model.Client, + LocalEndpointServiceName: "sender", + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s-broker.%s.svc.cluster.local", brokerName, client.Namespace), + }, + Children: expected.Children, + }, + } + } + return expected, body } From b2a5e32a227809cfbf62bfed5b40e45093d86187 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Mon, 30 Sep 2019 16:42:19 -0700 Subject: [PATCH 03/20] Add a hacky sleep so the Broker comes online. --- test/common/operation.go | 4 +++- test/conformance/helpers/broker_tracing_test_helper.go | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/common/operation.go b/test/common/operation.go index f92df3e9e2e..c2fe5bfdd15 100644 --- a/test/common/operation.go +++ b/test/common/operation.go @@ -139,7 +139,9 @@ func (client *Client) WaitForResourcesReady(typemeta *metav1.TypeMeta) error { // WaitForAllTestResourcesReady waits until all test resources in the namespace are Ready. func (client *Client) WaitForAllTestResourcesReady() error { // wait for all Knative resources created in this test to become ready. - client.Tracker.WaitForKResourcesReady() + if err := client.Tracker.WaitForKResourcesReady(); err != nil { + return err + } // explicitly wait for all pods to become ready. if err := pkgTest.WaitForAllPodsRunning(client.Kube, client.Namespace); err != nil { return err diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 41cb0ac84d1..919731e3888 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -49,6 +49,11 @@ func BrokerTracingTestHelper(t *testing.T, channelTestRunner common.ChannelTestR client := common.Setup(st, true) defer common.TearDown(client) + // Label namespace so that it creates the default broker. + if err := client.LabelNamespace(map[string]string{"knative-eventing-injection": "enabled"}); err != nil { + st.Fatalf("Error annotating namespace: %v", err) + } + // Do NOT call zipkin.CleanupZipkinTracingSetup. That will be called exactly once in // TestMain. tracinghelper.Setup(st, client) @@ -87,6 +92,9 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log channelTypeMeta := common.GetChannelTypeMeta(channel) client.CreateBrokerOrFail(brokerName, channelTypeMeta) + // DO NOT SUBMIT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111!!!!!!!!!!!!!!!!!! + time.Sleep(10 * time.Second) + // Create an logger (EventDetails) Pod and a K8s Service that points to it. logPod := resources.EventDetailsPod(loggerPodName) client.CreatePodOrFail(logPod, common.WithService(loggerPodName)) From 56bd430db428017404eb2b6df4cd595b3e61325f Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Tue, 1 Oct 2019 16:06:10 -0700 Subject: [PATCH 04/20] Single trace! --- cmd/broker/ingress/main.go | 9 +++++++++ pkg/broker/filter/filter_handler.go | 14 ++++++++++++++ pkg/broker/ingress/ingress_handler.go | 9 ++++++++- pkg/tracing/names.go | 2 +- pkg/tracing/traceparent.go | 5 +++++ .../helpers/broker_tracing_test_helper.go | 4 ++-- 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/cmd/broker/ingress/main.go b/cmd/broker/ingress/main.go index 45cc42d0b6f..d4415cee247 100644 --- a/cmd/broker/ingress/main.go +++ b/cmd/broker/ingress/main.go @@ -23,6 +23,9 @@ import ( "net/url" "time" + "go.opencensus.io/plugin/ochttp" + "go.opencensus.io/plugin/ochttp/propagation/b3" + // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters). // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" @@ -124,6 +127,12 @@ func main() { writer.WriteHeader(http.StatusOK) }) + // Add output tracing. + httpTransport.Client = &http.Client{ + Transport: &ochttp.Transport{ + Propagation: &b3.HTTPFormat{}, + }, + } ceClient, err := cloudevents.NewClient(httpTransport, cloudevents.WithTimeNow(), cloudevents.WithUUIDs()) if err != nil { logger.Fatal("Unable to create CE client", zap.Error(err)) diff --git a/pkg/broker/filter/filter_handler.go b/pkg/broker/filter/filter_handler.go index 2ab6edfb927..09b029c29db 100644 --- a/pkg/broker/filter/filter_handler.go +++ b/pkg/broker/filter/filter_handler.go @@ -25,6 +25,11 @@ import ( "sync/atomic" "time" + "go.opencensus.io/plugin/ochttp" + "go.opencensus.io/plugin/ochttp/propagation/b3" + + "go.opencensus.io/trace" + cloudevents "github.com/cloudevents/sdk-go" cehttp "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http" "go.uber.org/zap" @@ -69,6 +74,13 @@ func NewHandler(logger *zap.Logger, triggerLister eventinglisters.TriggerNamespa return nil, err } + // Add output tracing. + httpTransport.Client = &http.Client{ + Transport: &ochttp.Transport{ + Propagation: &b3.HTTPFormat{}, + }, + } + ceClient, err := cloudevents.NewClient(httpTransport, cloudevents.WithTimeNow(), cloudevents.WithUUIDs()) if err != nil { return nil, err @@ -150,6 +162,8 @@ func (r *Handler) serveHTTP(ctx context.Context, event cloudevents.Event, resp * return nil } + r.logger.Info("QQQQQ - incoming span", zap.Any("traceID", trace.FromContext(ctx).SpanContext().TraceID.String()), zap.Any("traceparentAttribute", event.Extensions()["traceparent"])) + // tctx.URI is actually the path... triggerRef, err := path.Parse(tctx.URI) if err != nil { diff --git a/pkg/broker/ingress/ingress_handler.go b/pkg/broker/ingress/ingress_handler.go index 424c55c4355..f8d69c38418 100644 --- a/pkg/broker/ingress/ingress_handler.go +++ b/pkg/broker/ingress/ingress_handler.go @@ -8,6 +8,8 @@ import ( "reflect" "time" + "go.opencensus.io/trace" + cloudevents "github.com/cloudevents/sdk-go" "go.uber.org/zap" "knative.dev/eventing/pkg/broker" @@ -73,7 +75,7 @@ func (h *Handler) serveHTTP(ctx context.Context, event cloudevents.Event, resp * return nil } - tracing.AddTraceparentAttributeFromContext(ctx, event) + event = tracing.AddTraceparentAttributeFromContext(ctx, event) reporterArgs := &ReportArgs{ ns: h.Namespace, @@ -91,6 +93,11 @@ func (h *Handler) serveHTTP(ctx context.Context, event cloudevents.Event, resp * start := time.Now() sendingCTX := utils.ContextFrom(tctx, h.ChannelURI) + // Due to an issue in utils.ContextFrom, we don't retain the original trace context from ctx, so + // bring it in manually. + sendingCTX = trace.NewContext(sendingCTX, trace.FromContext(ctx)) + + h.Logger.Info("QQQQQQQQQQQ - sending with traceparent", zap.Any("traceparent", event.Extensions()["traceparent"])) rctx, _, err := h.CeClient.Send(sendingCTX, event) rtctx := cloudevents.HTTPTransportContextFrom(rctx) // Record the dispatch time. diff --git a/pkg/tracing/names.go b/pkg/tracing/names.go index f583530899c..4cb52165a70 100644 --- a/pkg/tracing/names.go +++ b/pkg/tracing/names.go @@ -27,7 +27,7 @@ type BrokerIngressNameArgs struct { // BrokerIngressName creates the service name for Broker Ingresses to use when writing Zipkin // traces. func BrokerIngressName(args BrokerIngressNameArgs) string { - return fmt.Sprintf("%s-broker-ingress.%s", args.BrokerName, args.Namespace) + return fmt.Sprintf("%s-broker.%s", args.BrokerName, args.Namespace) } // BrokerFilterNameArgs are the arguments needed to generate the BrokerFilterName. diff --git a/pkg/tracing/traceparent.go b/pkg/tracing/traceparent.go index 581042a125d..665fdfaaf8f 100644 --- a/pkg/tracing/traceparent.go +++ b/pkg/tracing/traceparent.go @@ -22,6 +22,10 @@ import ( "regexp" "strconv" + "go.uber.org/zap" + + "knative.dev/eventing/pkg/logging" + cloudevents "github.com/cloudevents/sdk-go" "go.opencensus.io/plugin/ochttp/propagation/b3" "go.opencensus.io/trace" @@ -44,6 +48,7 @@ func AddTraceparentAttributeFromContext(ctx context.Context, event cloudevents.E span := trace.FromContext(ctx) if span != nil { event.SetExtension(traceparentAttribute, traceparentAttributeValue(span)) + logging.FromContext(ctx).Info("QQQQQQQQQQQ - Added traceparent", zap.Any("traceparent", event.Extensions()[traceparentAttribute])) } return event } diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 919731e3888..421d02188fb 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -41,8 +41,8 @@ func BrokerTracingTestHelper(t *testing.T, channelTestRunner common.ChannelTestR loggerPodName := "logger" t.Run(n, func(t *testing.T) { channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel string) { - // Don't accidentally use t, use st instead. To ensure this, shadow 't' to some a - // useless type. + // Don't accidentally use t, use st instead. To ensure this, shadow 't' to a useless + // type. t := struct{}{} _ = fmt.Sprintf("%s", t) From d4477317c4fe03cf966f84e0abc013654f5f5353 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Tue, 1 Oct 2019 16:17:48 -0700 Subject: [PATCH 05/20] Single place adds all the outgoing tracing. --- cmd/broker/ingress/main.go | 19 +++++-------------- pkg/broker/filter/filter_handler.go | 16 +++------------- pkg/broker/ingress/ingress_handler.go | 3 +-- pkg/kncloudevents/good_client.go | 6 ++++++ pkg/tracing/traceparent.go | 6 ++---- test/common/creation.go | 3 +-- 6 files changed, 18 insertions(+), 35 deletions(-) diff --git a/cmd/broker/ingress/main.go b/cmd/broker/ingress/main.go index d4415cee247..9600621883b 100644 --- a/cmd/broker/ingress/main.go +++ b/cmd/broker/ingress/main.go @@ -23,9 +23,6 @@ import ( "net/url" "time" - "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/plugin/ochttp/propagation/b3" - // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters). // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" @@ -37,17 +34,17 @@ import ( "go.opencensus.io/stats/view" "knative.dev/eventing/pkg/broker/ingress" "knative.dev/eventing/pkg/channel" + "knative.dev/eventing/pkg/kncloudevents" "knative.dev/eventing/pkg/tracing" + kubeclient "knative.dev/pkg/client/injection/kube/client" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" + "knative.dev/pkg/injection" + "knative.dev/pkg/injection/sharedmain" "knative.dev/pkg/metrics" "knative.dev/pkg/signals" "knative.dev/pkg/system" pkgtracing "knative.dev/pkg/tracing" - - kubeclient "knative.dev/pkg/client/injection/kube/client" - "knative.dev/pkg/injection" - "knative.dev/pkg/injection/sharedmain" ) var ( @@ -127,13 +124,7 @@ func main() { writer.WriteHeader(http.StatusOK) }) - // Add output tracing. - httpTransport.Client = &http.Client{ - Transport: &ochttp.Transport{ - Propagation: &b3.HTTPFormat{}, - }, - } - ceClient, err := cloudevents.NewClient(httpTransport, cloudevents.WithTimeNow(), cloudevents.WithUUIDs()) + ceClient, err := kncloudevents.NewDefaultClientGivenHttpTransport(httpTransport) if err != nil { logger.Fatal("Unable to create CE client", zap.Error(err)) } diff --git a/pkg/broker/filter/filter_handler.go b/pkg/broker/filter/filter_handler.go index 09b029c29db..e15ff332eba 100644 --- a/pkg/broker/filter/filter_handler.go +++ b/pkg/broker/filter/filter_handler.go @@ -25,17 +25,14 @@ import ( "sync/atomic" "time" - "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/plugin/ochttp/propagation/b3" - - "go.opencensus.io/trace" - cloudevents "github.com/cloudevents/sdk-go" cehttp "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http" + "go.opencensus.io/trace" "go.uber.org/zap" eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" "knative.dev/eventing/pkg/broker" eventinglisters "knative.dev/eventing/pkg/client/listers/eventing/v1alpha1" + "knative.dev/eventing/pkg/kncloudevents" "knative.dev/eventing/pkg/logging" "knative.dev/eventing/pkg/reconciler/trigger/path" "knative.dev/eventing/pkg/tracing" @@ -74,14 +71,7 @@ func NewHandler(logger *zap.Logger, triggerLister eventinglisters.TriggerNamespa return nil, err } - // Add output tracing. - httpTransport.Client = &http.Client{ - Transport: &ochttp.Transport{ - Propagation: &b3.HTTPFormat{}, - }, - } - - ceClient, err := cloudevents.NewClient(httpTransport, cloudevents.WithTimeNow(), cloudevents.WithUUIDs()) + ceClient, err := kncloudevents.NewDefaultClientGivenHttpTransport(httpTransport) if err != nil { return nil, err } diff --git a/pkg/broker/ingress/ingress_handler.go b/pkg/broker/ingress/ingress_handler.go index f8d69c38418..8b851861854 100644 --- a/pkg/broker/ingress/ingress_handler.go +++ b/pkg/broker/ingress/ingress_handler.go @@ -8,9 +8,8 @@ import ( "reflect" "time" - "go.opencensus.io/trace" - cloudevents "github.com/cloudevents/sdk-go" + "go.opencensus.io/trace" "go.uber.org/zap" "knative.dev/eventing/pkg/broker" "knative.dev/eventing/pkg/tracing" diff --git a/pkg/kncloudevents/good_client.go b/pkg/kncloudevents/good_client.go index 80af546d452..e19a24aaf20 100644 --- a/pkg/kncloudevents/good_client.go +++ b/pkg/kncloudevents/good_client.go @@ -25,6 +25,12 @@ func NewDefaultClient(target ...string) (cloudevents.Client, error) { if err != nil { return nil, err } + return NewDefaultClientGivenHttpTransport(t) +} + +// NewDefaultClientGivenHttpTransport creates a new CloudEvents client using the provided HTTP +// transport. Note that it does modify the provided HTTP Transport by adding tracing to its Client. +func NewDefaultClientGivenHttpTransport(t *cloudevents.HTTPTransport) (cloudevents.Client, error) { // Add output tracing. t.Client = &gohttp.Client{ Transport: &ochttp.Transport{ diff --git a/pkg/tracing/traceparent.go b/pkg/tracing/traceparent.go index 665fdfaaf8f..227a170566b 100644 --- a/pkg/tracing/traceparent.go +++ b/pkg/tracing/traceparent.go @@ -22,13 +22,11 @@ import ( "regexp" "strconv" - "go.uber.org/zap" - - "knative.dev/eventing/pkg/logging" - cloudevents "github.com/cloudevents/sdk-go" "go.opencensus.io/plugin/ochttp/propagation/b3" "go.opencensus.io/trace" + "go.uber.org/zap" + "knative.dev/eventing/pkg/logging" ) const ( diff --git a/test/common/creation.go b/test/common/creation.go index 0634bd74329..d621f61dd55 100644 --- a/test/common/creation.go +++ b/test/common/creation.go @@ -19,12 +19,11 @@ package common import ( "fmt" - "knative.dev/eventing/pkg/apis/eventing/v1alpha1" - corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/eventing/pkg/apis/eventing/v1alpha1" messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1" sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" "knative.dev/eventing/test/base" From c35f14038ec6b4062a788e1a41ce2f084175dc4c Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Tue, 1 Oct 2019 16:58:31 -0700 Subject: [PATCH 06/20] Random --- test/common/tracker.go | 10 ++++------ test/conformance/helpers/tracing/traces.go | 5 ++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/test/common/tracker.go b/test/common/tracker.go index 0c3746daf6f..56efccae50a 100644 --- a/test/common/tracker.go +++ b/test/common/tracker.go @@ -20,8 +20,6 @@ limitations under the License. package common import ( - "encoding/json" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" @@ -115,17 +113,17 @@ func (t *Tracker) AddObj(obj kmeta.OwnerRefable) { // Clean will delete all registered resources func (t *Tracker) Clean(awaitDeletion bool) error { for _, deleter := range t.resourcesToClean { - r, err := deleter.Resource.Get(deleter.Name, metav1.GetOptions{}) + _, err := deleter.Resource.Get(deleter.Name, metav1.GetOptions{}) if err != nil { t.logf("Failed to get to-be cleaned resource %q : %v", deleter.Name, err) } else { - bytes, _ := json.MarshalIndent(r, "", " ") - t.logf("Cleaning resource: %q\n%+v", deleter.Name, string(bytes)) + // bytes, _ := json.MarshalIndent(r, "", " ") + // t.logf("Cleaning resource: %q\n%+v", deleter.Name, string(bytes)) } if err := deleter.Resource.Delete(deleter.Name, nil); err != nil { t.logf("Failed to clean the resource %q : %v", deleter.Name, err) } else if awaitDeletion { - t.logf("Waiting for %s to be deleted", deleter.Name) + // t.logf("Waiting for %s to be deleted", deleter.Name) if err := wait.PollImmediate(interval, timeout, func() (bool, error) { if _, err := deleter.Resource.Get(deleter.Name, metav1.GetOptions{}); err != nil { return true, nil diff --git a/test/conformance/helpers/tracing/traces.go b/test/conformance/helpers/tracing/traces.go index 62aeeeb1876..8eb6948c3d3 100644 --- a/test/conformance/helpers/tracing/traces.go +++ b/test/conformance/helpers/tracing/traces.go @@ -144,9 +144,12 @@ func (t TestSpanTree) SpanCount() int { // Matches checks to see if this TestSpanTree matches an actual SpanTree. It is intended to be used // for assertions while testing. func (t TestSpanTree) Matches(actual SpanTree) error { + if g, w := actual.ToTestSpanTree().SpanCount(), t.SpanCount(); g != w { + return fmt.Errorf("unexpected number of spans") + } err := traceTreeMatches(".", t, actual) if err != nil { - return fmt.Errorf("spanTree did not match: %v. Actual %v, Expected %v", err, actual.ToTestSpanTree().String(), t.String()) + return fmt.Errorf("spanTree did not match: %v. \n*****Actual***** %v\n*****Expected***** %v", err, actual.ToTestSpanTree().String(), t.String()) } return nil } From 89d1595ce102013c1932e8b1325acb24a38f69a8 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Wed, 2 Oct 2019 10:35:44 -0700 Subject: [PATCH 07/20] TestSpanTrace.Notes. --- .../helpers/broker_tracing_test_helper.go | 54 ++++++++----------- test/conformance/helpers/tracing/traces.go | 11 ++-- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 421d02188fb..85dabf10b09 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -192,7 +192,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Steps 17-18: 'logger' event being sent to the 'transformer' Trigger. loggerEventSentFromTrChannelToTransformer := tracinghelper.TestSpanTree{ - // 17. Broker TrChannel sends the event to the Broker Filter for the "transformer" trigger. + Note: "17. Broker TrChannel sends the event to the Broker Filter for the 'transformer' trigger.", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", @@ -201,8 +201,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 18. Broker Filter for the "transformer" trigger receives the event from the - // Broker TrChannel. This does not pass the filter, so this 'branch' ends here. + Note: "18. Broker Filter for the 'transformer' trigger receives the event from the Broker TrChannel. This does not pass the filter, so this 'branch' ends here.", Kind: model.Server, Tags: map[string]string{ "http.method": "POST", @@ -216,7 +215,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Steps 19-22: 'logger' event being sent to the 'logger' Trigger. loggerEventSentFromTrChannelToLogger := tracinghelper.TestSpanTree{ - // 19. Broker TrChannel sends the event to the Broker Filter for the "logger" trigger. + Note: "19. Broker TrChannel sends the event to the Broker Filter for the 'logger' trigger.", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", @@ -225,7 +224,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 20. Broker Filter for the "logger" trigger receives the event from the Broker TrChannel. + Note: "20. Broker Filter for the 'logger' trigger receives the event from the Broker TrChannel.", Kind: model.Server, Tags: map[string]string{ "http.method": "POST", @@ -235,7 +234,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 21. Broker Filter for the "logger" trigger sends the event to the logger pod. + Note: "21. Broker Filter for the 'logger' trigger sends the event to the logger pod.", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", @@ -244,7 +243,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 22. Logger pod receives the event from the Broker Filter for the "logger" trigger. + Note: "22. Logger pod receives the event from the Broker Filter for the 'logger' trigger.", Kind: model.Server, Tags: map[string]string{ "http.method": "POST", @@ -263,7 +262,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Steps 13-22. Directly steps 13-16. 17-22 are included as children. // Steps 13-16: Event in the Broker InChannel sent to the Broker Ingress to the Trigger Channel. loggerEventIngressToTrigger := tracinghelper.TestSpanTree{ - // 13. Broker InChannel sends the event to the Broker Ingress. + Note: "13. Broker InChannel sends the event to the Broker Ingress.", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", @@ -272,7 +271,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 14. Broker Ingress receives the event from the Broker InChannel. + Note: "14. Broker Ingress receives the event from the Broker InChannel.", Kind: model.Server, Tags: map[string]string{ @@ -283,7 +282,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 15. Broker Ingress sends the event to the Broker's TrChannel. + Note: "15. Broker Ingress sends the event to the Broker's TrChannel.", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", @@ -292,7 +291,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 16. Broker TrChannel receives the event from the Broker Ingress. + Note: "16. Broker TrChannel receives the event from the Broker Ingress.", Kind: model.Server, Tags: map[string]string{ "http.method": "POST", @@ -317,7 +316,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Steps 7-22. Directly steps 7-12. 13-22 are included as children. // Steps 7-12: Event from TrChannel sent to transformer Trigger and its reply to the InChannel. transformerEventSentFromTrChannelToTransformer := tracinghelper.TestSpanTree{ - // 7. Broker TrChannel sends the event to the Broker Filter for the "transformer" trigger. + Note: "7. Broker TrChannel sends the event to the Broker Filter for the 'transformer' trigger.", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", @@ -326,8 +325,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 8. Broker Filter for the "transformer" trigger receives the event from the Broker - // TrChannel. + Note: "8. Broker Filter for the 'transformer' trigger receives the event from the Broker TrChannel.", Kind: model.Server, Tags: map[string]string{ "http.method": "POST", @@ -337,8 +335,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 9. Broker Filter for the "transformer" trigger sends the event to the - // transformer pod. + Note: "9. Broker Filter for the 'transformer' trigger sends the event to the transformer pod.", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", @@ -347,8 +344,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 10. Transformer pod receives the event from the Broker Filter for - // the "transformer" trigger. + Note: "10. Transformer pod receives the event from the Broker Filter for the 'transformer' trigger.", Kind: model.Server, Tags: map[string]string{ "http.method": "POST", @@ -358,8 +354,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 11. Broker Filter for the "transformer" sends the - // transformer pod's reply to the Broker InChannel. + Note: "11. Broker Filter for the 'transformer' sends the transformer pod's reply to the Broker InChannel.", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", @@ -368,8 +363,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 12. Broker InChannel receives the event from the - // Broker Filter for the "transformer" trigger. + Note: "12. Broker InChannel receives the event from the Broker Filter for the 'transformer' trigger.", Kind: model.Server, Tags: map[string]string{ "http.method": "POST", @@ -395,7 +389,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Steps 5-6: Event from TrChannel sent to logger Trigger. transformerEventSentFromTrChannelToLogger := tracinghelper.TestSpanTree{ - // 5. Broker TrChannel sends the event to the Broker Filter for the "logger" trigger. + Note: "5. Broker TrChannel sends the event to the Broker Filter for the 'logger' trigger.", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", @@ -404,8 +398,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 6. Broker Filter for the "logger" trigger receives the event from the Broker - // TrChannel. This does not pass the filter, so this 'branch' ends here. + Note: "6. Broker Filter for the 'logger' trigger receives the event from the Broker TrChannel. This does not pass the filter, so this 'branch' ends here.", Kind: model.Server, Tags: map[string]string{ "http.method": "POST", @@ -427,11 +420,11 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Steps 0-4 (missing 1, which is optional and added below if present): Event sent to the Broker // Ingress. expected := tracinghelper.TestSpanTree{ - // 0. Artificial root span. + Note: "0. Artificial root span.", Root: true, Children: []tracinghelper.TestSpanTree{ { - // 2. Broker Ingress receives the event from the sending pod. + Note: "2. Broker Ingress receives the event from the sending pod.", Kind: model.Server, Tags: map[string]string{ "http.method": "POST", @@ -441,7 +434,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 3. Broker Ingress sends the event to the Broker's TrChannel (trigger channel). + Note: "3. Broker Ingress sends the event to the Broker's TrChannel (trigger channel).", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", @@ -450,7 +443,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, Children: []tracinghelper.TestSpanTree{ { - // 4. Broker TrChannel receives the event from the Broker Ingress. + Note: "4. Broker TrChannel receives the event from the Broker Ingress.", Kind: model.Server, Tags: map[string]string{ "http.method": "POST", @@ -475,8 +468,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log if incomingTraceId { expected.Children = []tracinghelper.TestSpanTree{ { - // 1. Send pod sends event to the Broker Ingress (only if the sending pod generates - // a span). + Note: "1. Send pod sends event to the Broker Ingress (only if the sending pod generates a span).", Kind: model.Client, LocalEndpointServiceName: "sender", Tags: map[string]string{ diff --git a/test/conformance/helpers/tracing/traces.go b/test/conformance/helpers/tracing/traces.go index 8eb6948c3d3..b10f470bea4 100644 --- a/test/conformance/helpers/tracing/traces.go +++ b/test/conformance/helpers/tracing/traces.go @@ -72,12 +72,13 @@ func (t SpanTree) toTestSpanTreeHelper() TestSpanTree { // TestSpanTree is the expected version of SpanTree used for assertions in testing. type TestSpanTree struct { - Root bool - Kind model.Kind - LocalEndpointServiceName string - Tags map[string]string + Note string `json:"aaNote,omitempty"` + Root bool `json:"root,omitempty"` + Kind model.Kind `json:"aKind,omitempty"` + LocalEndpointServiceName string `json:"aName,omitempty"` + Tags map[string]string `json:"tags,omitempty"` - Children []TestSpanTree + Children []TestSpanTree `json:"zChildren,omitempty"` } func (t TestSpanTree) String() string { From 0e6028196736602c4839bd24d97c1dc0a1f15427 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Wed, 2 Oct 2019 16:35:44 -0700 Subject: [PATCH 08/20] Small Changes. --- test/conformance/helpers/broker_tracing_test_helper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 85dabf10b09..043b34d144a 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -180,7 +180,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Useful constants we will use below. ingressHost := fmt.Sprintf("%s-broker.%s.svc.%s", brokerName, client.Namespace, domain) - triggerChanHost := fmt.Sprintf("%s-kne-trigger.%s.svc.%s", brokerName, client.Namespace, domain) + triggerChanHost := fmt.Sprintf("%s-kne-trigger-kn-channel.%s.svc.%s", brokerName, client.Namespace, domain) ingressChanHost := fmt.Sprintf("%s-kne-ingress.%s.svc.%s", brokerName, client.Namespace, domain) filterHost := fmt.Sprintf("%s-broker-filter.%s.svc.%s", brokerName, client.Namespace, domain) loggerTriggerPath := fmt.Sprintf("/triggers/%s/%s/%s", client.Namespace, loggerTrigger.Name, loggerTrigger.UID) @@ -394,7 +394,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Tags: map[string]string{ "http.method": "POST", "http.status_code": "202", - "http.url": fmt.Sprintf("http://%s/%s", filterHost, loggerTriggerPath), + "http.url": fmt.Sprintf("http://%s%s", filterHost, loggerTriggerPath), }, Children: []tracinghelper.TestSpanTree{ { From 1b1e7c6bf800cb9ab41cec7b7063a43315cd6e39 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Thu, 3 Oct 2019 15:31:07 -0700 Subject: [PATCH 09/20] In the right direction. --- pkg/broker/filter/filter_handler.go | 8 +-- test/common/tracker.go | 4 +- .../helpers/broker_tracing_test_helper.go | 64 +++++++++---------- .../helpers/channel_tracing_test_helper.go | 2 +- test/conformance/helpers/tracing/traces.go | 42 +++++++++++- 5 files changed, 80 insertions(+), 40 deletions(-) diff --git a/pkg/broker/filter/filter_handler.go b/pkg/broker/filter/filter_handler.go index e15ff332eba..2f77587c82d 100644 --- a/pkg/broker/filter/filter_handler.go +++ b/pkg/broker/filter/filter_handler.go @@ -35,7 +35,6 @@ import ( "knative.dev/eventing/pkg/kncloudevents" "knative.dev/eventing/pkg/logging" "knative.dev/eventing/pkg/reconciler/trigger/path" - "knative.dev/eventing/pkg/tracing" "knative.dev/eventing/pkg/utils" pkgtracing "knative.dev/pkg/tracing" ) @@ -256,10 +255,9 @@ func (r *Handler) sendEvent(ctx context.Context, tctx cloudevents.HTTPTransportC } sendingCTX := utils.ContextFrom(tctx, subscriberURI) - sendingCTX, err = tracing.AddSpanFromTraceparentAttribute(sendingCTX, "name", *event) - if err != nil { - r.logger.Info("Unable to attach trace", zap.Error(err)) - } + // Due to an issue in utils.ContextFrom, we don't retain the original trace context from ctx, so + // bring it in manually. + sendingCTX = trace.NewContext(sendingCTX, trace.FromContext(ctx)) start := time.Now() rctx, replyEvent, err := r.ceClient.Send(sendingCTX, *event) diff --git a/test/common/tracker.go b/test/common/tracker.go index 56efccae50a..9a2dabdd453 100644 --- a/test/common/tracker.go +++ b/test/common/tracker.go @@ -20,6 +20,8 @@ limitations under the License. package common import ( + "fmt" + "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" @@ -142,7 +144,7 @@ func (t *Tracker) WaitForKResourcesReady() error { t.logf("Waiting for all KResources to become ready") for _, metaResource := range t.resourcesToCheckStatus { if err := base.WaitForResourceReady(t.dynamicClient, &metaResource); err != nil { - return err + return fmt.Errorf("waiting for %+v to become ready: %v", metaResource, err) } } return nil diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 043b34d144a..ee314ca36b0 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -61,7 +61,7 @@ func BrokerTracingTestHelper(t *testing.T, channelTestRunner common.ChannelTestR expected, mustContain := setupBrokerTracing(st, channel, client, loggerPodName, tc.incomingTraceId) assertLogContents(st, client, loggerPodName, mustContain) traceID := getTraceID(st, client, loggerPodName) - trace, err := zipkin.JSONTrace(traceID, expected.SpanCount(), 60*time.Second) + trace, err := zipkin.JSONTrace(traceID, expected.SpanCount(), 160*time.Second) if err != nil { st.Fatalf("Unable to get trace %q: %v. Trace so far %+v", traceID, err, tracinghelper.PrettyPrintTrace(trace)) } @@ -197,7 +197,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Tags: map[string]string{ "http.method": "POST", "http.status_code": "202", - "http.url": fmt.Sprintf("http://%s/%s", filterHost, transformerTriggerPath), + "http.url": fmt.Sprintf("http://%s%s", filterHost, transformerTriggerPath), }, Children: []tracinghelper.TestSpanTree{ { @@ -220,7 +220,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Tags: map[string]string{ "http.method": "POST", "http.status_code": "202", - "http.url": fmt.Sprintf("http://%s/%s", filterHost, loggerTriggerPath), + "http.url": fmt.Sprintf("http://%s%s", filterHost, loggerTriggerPath), }, Children: []tracinghelper.TestSpanTree{ { @@ -321,7 +321,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Tags: map[string]string{ "http.method": "POST", "http.status_code": "202", - "http.url": fmt.Sprintf("http://%s/%s", filterHost, transformerTriggerPath), + "http.url": fmt.Sprintf("http://%s%s", filterHost, transformerTriggerPath), }, Children: []tracinghelper.TestSpanTree{ { @@ -352,33 +352,6 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log "http.status_code": "202", "http.host": fmt.Sprintf("unknown-bazqux="), }, - Children: []tracinghelper.TestSpanTree{ - { - Note: "11. Broker Filter for the 'transformer' sends the transformer pod's reply to the Broker InChannel.", - Kind: model.Client, - Tags: map[string]string{ - "http.method": "POST", - "http.status_code": "202", - "http.url": fmt.Sprintf("http://%s", ingressChanHost), - }, - Children: []tracinghelper.TestSpanTree{ - { - Note: "12. Broker InChannel receives the event from the Broker Filter for the 'transformer' trigger.", - Kind: model.Server, - Tags: map[string]string{ - "http.method": "POST", - "http.status_code": "202", - "http.url": ingressChanHost, - "http.path": "/", - }, - Children: []tracinghelper.TestSpanTree{ - // Steps 13-22. - loggerEventIngressToTrigger, - }, - }, - }, - }, - }, }, }, }, @@ -387,6 +360,32 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, } + transformerEventResponseFromTrChannel := tracinghelper.TestSpanTree{ + Note: "11. Broker TrChannel for the 'transformer' sends the transformer pod's reply to the Broker InChannel.", + Kind: model.Client, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": fmt.Sprintf("http://%s", ingressChanHost), + }, + Children: []tracinghelper.TestSpanTree{ + { + Note: "12. Broker InChannel receives the event from the Broker TrChannel for the 'transformer' trigger.", + Kind: model.Server, + Tags: map[string]string{ + "http.method": "POST", + "http.status_code": "202", + "http.url": ingressChanHost, + "http.path": "/", + }, + Children: []tracinghelper.TestSpanTree{ + // Steps 13-22. + loggerEventIngressToTrigger, + }, + }, + }, + } + // Steps 5-6: Event from TrChannel sent to logger Trigger. transformerEventSentFromTrChannelToLogger := tracinghelper.TestSpanTree{ Note: "5. Broker TrChannel sends the event to the Broker Filter for the 'logger' trigger.", @@ -454,8 +453,9 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Children: []tracinghelper.TestSpanTree{ // Steps 5-6. transformerEventSentFromTrChannelToLogger, - // Steps 7-22. + // Steps 7-10. transformerEventSentFromTrChannelToTransformer, + transformerEventResponseFromTrChannel, }, }, }, diff --git a/test/conformance/helpers/channel_tracing_test_helper.go b/test/conformance/helpers/channel_tracing_test_helper.go index 99ca60067d3..ea0d9d9d4a6 100644 --- a/test/conformance/helpers/channel_tracing_test_helper.go +++ b/test/conformance/helpers/channel_tracing_test_helper.go @@ -244,7 +244,7 @@ func ChannelTracingTestHelperWithReply(t *testing.T, channelTestRunner common.Ch assertLogContents(st, client, loggerPodName, mustContain) traceID := getTraceID(st, client, loggerPodName) - trace, err := zipkin.JSONTrace(traceID, expected.SpanCount(), 60*time.Second) + trace, err := zipkin.JSONTrace(traceID, expected.SpanCount(), 2*time.Minute) if err != nil { st.Fatalf("Unable to get trace %q: %v. Trace so far %+v", traceID, err, tracinghelper.PrettyPrintTrace(trace)) } diff --git a/test/conformance/helpers/tracing/traces.go b/test/conformance/helpers/tracing/traces.go index b10f470bea4..8529380afff 100644 --- a/test/conformance/helpers/tracing/traces.go +++ b/test/conformance/helpers/tracing/traces.go @@ -19,6 +19,7 @@ package tracing import ( "encoding/json" "fmt" + "sort" "testing" "github.com/openzipkin/zipkin-go/model" @@ -62,12 +63,14 @@ func (t SpanTree) toTestSpanTreeHelper() TestSpanTree { for i := range t.Children { children[i] = t.Children[i].toTestSpanTreeHelper() } - return TestSpanTree{ + tst := TestSpanTree{ Kind: t.Span.Kind, LocalEndpointServiceName: name, Tags: t.Span.Tags, Children: children, } + tst.SortChildren() + return tst } // TestSpanTree is the expected version of SpanTree used for assertions in testing. @@ -86,6 +89,42 @@ func (t TestSpanTree) String() string { return string(b) } +func (t *TestSpanTree) SortChildren() { + for _, child := range t.Children { + child.SortChildren() + } + sort.Slice(t.Children, func(i, j int) bool { + ic := t.Children[i] + jc := t.Children[j] + + if ic.height() != jc.height() { + return ic.height() < jc.height() + } + + if ic.Kind != jc.Kind { + return ic.Kind < jc.Kind + } + it := ic.Tags + jt := jc.Tags + for _, key := range []string{"http.url", "http.host", "http.path"} { + if it[key] != jt[key] { + return it[key] < jt[key] + } + } + panic(fmt.Errorf("can't tell the difference between %v, %v", ic, jc)) + }) +} + +func (t TestSpanTree) height() int { + height := 0 + for _, child := range t.Children { + if ch := child.height(); ch > height { + height = ch + 1 + } + } + return height +} + // GetTraceTree converts a set slice of spans into a SpanTree. func GetTraceTree(t *testing.T, trace []model.SpanModel) SpanTree { var roots []model.SpanModel @@ -148,6 +187,7 @@ func (t TestSpanTree) Matches(actual SpanTree) error { if g, w := actual.ToTestSpanTree().SpanCount(), t.SpanCount(); g != w { return fmt.Errorf("unexpected number of spans") } + t.SortChildren() err := traceTreeMatches(".", t, actual) if err != nil { return fmt.Errorf("spanTree did not match: %v. \n*****Actual***** %v\n*****Expected***** %v", err, actual.ToTestSpanTree().String(), t.String()) From 0cff4edf15070f44cc49eda61f54905250781484 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Thu, 3 Oct 2019 16:20:22 -0700 Subject: [PATCH 10/20] Close to working. --- .../helpers/broker_tracing_test_helper.go | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index ee314ca36b0..9ba54697e1f 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -181,7 +181,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Useful constants we will use below. ingressHost := fmt.Sprintf("%s-broker.%s.svc.%s", brokerName, client.Namespace, domain) triggerChanHost := fmt.Sprintf("%s-kne-trigger-kn-channel.%s.svc.%s", brokerName, client.Namespace, domain) - ingressChanHost := fmt.Sprintf("%s-kne-ingress.%s.svc.%s", brokerName, client.Namespace, domain) + ingressChanHost := fmt.Sprintf("%s-kne-ingress-kn-channel.%s.svc.%s", brokerName, client.Namespace, domain) filterHost := fmt.Sprintf("%s-broker-filter.%s.svc.%s", brokerName, client.Namespace, domain) loggerTriggerPath := fmt.Sprintf("/triggers/%s/%s/%s", client.Namespace, loggerTrigger.Name, loggerTrigger.UID) transformerTriggerPath := fmt.Sprintf("/triggers/%s/%s/%s", client.Namespace, transformerTrigger.Name, transformerTrigger.UID) @@ -230,7 +230,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log "http.method": "POST", "http.status_code": "202", "http.host": filterHost, - "http.path": transformerTriggerPath, + "http.path": loggerTriggerPath, }, Children: []tracinghelper.TestSpanTree{ { @@ -249,7 +249,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log "http.method": "POST", "http.path": "/", "http.status_code": "202", - "http.host": fmt.Sprintf("unknown-foobar="), + "http.host": loggerSVCHost, }, }, }, @@ -287,7 +287,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Tags: map[string]string{ "http.method": "POST", "http.status_code": "202", - "http.url": fmt.Sprintf("http://%s", triggerChanHost), + "http.url": fmt.Sprintf("http://%s/", triggerChanHost), }, Children: []tracinghelper.TestSpanTree{ { @@ -314,13 +314,13 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log } // Steps 7-22. Directly steps 7-12. 13-22 are included as children. - // Steps 7-12: Event from TrChannel sent to transformer Trigger and its reply to the InChannel. + // Steps 7-10: Event from TrChannel sent to transformer Trigger and its reply to the InChannel. transformerEventSentFromTrChannelToTransformer := tracinghelper.TestSpanTree{ Note: "7. Broker TrChannel sends the event to the Broker Filter for the 'transformer' trigger.", Kind: model.Client, Tags: map[string]string{ "http.method": "POST", - "http.status_code": "202", + "http.status_code": "200", ///////////////////////////////////////////////////////////////// Weird, probably should be 200 "http.url": fmt.Sprintf("http://%s%s", filterHost, transformerTriggerPath), }, Children: []tracinghelper.TestSpanTree{ @@ -339,7 +339,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Kind: model.Client, Tags: map[string]string{ "http.method": "POST", - "http.status_code": "202", + "http.status_code": "200", "http.url": fmt.Sprintf("http://%s/", transformerSVCHost), }, Children: []tracinghelper.TestSpanTree{ @@ -349,8 +349,8 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Tags: map[string]string{ "http.method": "POST", "http.path": "/", - "http.status_code": "202", - "http.host": fmt.Sprintf("unknown-bazqux="), + "http.status_code": "200", + "http.host": transformerSVCHost, }, }, }, @@ -360,6 +360,9 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, } + // Step 11-22. Directly steps 11-12. Steps 13-22 are children. + // Steps 11-12 Reply from the 'transformer' is sent by the Broker TrChannel to the Broker + // InChannel. transformerEventResponseFromTrChannel := tracinghelper.TestSpanTree{ Note: "11. Broker TrChannel for the 'transformer' sends the transformer pod's reply to the Broker InChannel.", Kind: model.Client, @@ -375,7 +378,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Tags: map[string]string{ "http.method": "POST", "http.status_code": "202", - "http.url": ingressChanHost, + "http.host": ingressChanHost, "http.path": "/", }, Children: []tracinghelper.TestSpanTree{ @@ -386,7 +389,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, } - // Steps 5-6: Event from TrChannel sent to logger Trigger. + // Steps 5-6: Event from TrChannel sent to logger Trigger. transformerEventSentFromTrChannelToLogger := tracinghelper.TestSpanTree{ Note: "5. Broker TrChannel sends the event to the Broker Filter for the 'logger' trigger.", Kind: model.Client, @@ -409,12 +412,6 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, } - // 0. Artificial root span. - // 1. Send pod sends event to the Broker Ingress (only if the sending pod generates a span). - // 2. Broker Ingress receives the event from the sending pod. - // 3. Broker Ingress sends the event to the Broker's TrChannel (trigger channel). - // 4. Broker TrChannel receives the event from the Broker Ingress. - // Steps 0-22. Directly steps 0-4 (missing 1) // Steps 0-4 (missing 1, which is optional and added below if present): Event sent to the Broker // Ingress. @@ -438,7 +435,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Tags: map[string]string{ "http.method": "POST", "http.status_code": "202", - "http.url": fmt.Sprintf("http://%s", triggerChanHost), + "http.url": fmt.Sprintf("http://%s/", triggerChanHost), }, Children: []tracinghelper.TestSpanTree{ { @@ -455,6 +452,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log transformerEventSentFromTrChannelToLogger, // Steps 7-10. transformerEventSentFromTrChannelToTransformer, + // Steps 11-22 transformerEventResponseFromTrChannel, }, }, From 2710b02f5fda4043f5bdcf72ac3d8ac1e7fa806f Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Thu, 3 Oct 2019 16:42:28 -0700 Subject: [PATCH 11/20] It works! --- test/conformance/helpers/tracing/traces.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/conformance/helpers/tracing/traces.go b/test/conformance/helpers/tracing/traces.go index 8529380afff..19ddfba7d1d 100644 --- a/test/conformance/helpers/tracing/traces.go +++ b/test/conformance/helpers/tracing/traces.go @@ -34,6 +34,7 @@ func PrettyPrintTrace(trace []model.SpanModel) string { // SpanTree is the tree of Spans representation of a Trace. type SpanTree struct { + Root bool Span model.SpanModel Children []SpanTree } @@ -49,7 +50,7 @@ func (t SpanTree) ToTestSpanTree() TestSpanTree { children[i] = t.Children[i].toTestSpanTreeHelper() } return TestSpanTree{ - Root: true, + Root: t.Root, Children: children, } } @@ -143,6 +144,7 @@ func GetTraceTree(t *testing.T, trace []model.SpanModel) SpanTree { } tree := SpanTree{ + Root: true, Children: children, } if len(parents) != 0 { @@ -185,7 +187,7 @@ func (t TestSpanTree) SpanCount() int { // for assertions while testing. func (t TestSpanTree) Matches(actual SpanTree) error { if g, w := actual.ToTestSpanTree().SpanCount(), t.SpanCount(); g != w { - return fmt.Errorf("unexpected number of spans") + return fmt.Errorf("unexpected number of spans. got %d want %d", g, w) } t.SortChildren() err := traceTreeMatches(".", t, actual) @@ -230,16 +232,17 @@ func unorderedTraceTreesMatch(pos string, want []TestSpanTree, got []SpanTree) e // so n should be small (say 50 in the largest cases). OuterLoop: for i, w := range want { + var lastErr error for ug := range unmatchedGot { - err := w.Matches(got[ug]) + lastErr = w.Matches(got[ug]) // If there is no error, then it matched successfully. - if err == nil { + if lastErr == nil { unmatchedGot.Delete(ug) continue OuterLoop } } // Nothing matched. - return fmt.Errorf("unable to find child match %s[%d]: Want: %s **** Got: %s", pos, i, w.String(), got) + return fmt.Errorf("unable to find child match %s[%d]: Last Err %v. Want: %s **** Got: %s", pos, i, lastErr, w.String(), got) } // Everything matched. return nil From 7c934a6ea825e4066d84cbf1f3eae29039f76614 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Thu, 3 Oct 2019 16:49:12 -0700 Subject: [PATCH 12/20] Remove debug logging. --- pkg/broker/filter/filter_handler.go | 2 -- pkg/broker/ingress/ingress_handler.go | 3 +-- pkg/tracing/traceparent.go | 3 --- test/common/tracker.go | 9 +++++---- test/conformance/helpers/tracing/traces.go | 2 +- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pkg/broker/filter/filter_handler.go b/pkg/broker/filter/filter_handler.go index 2f77587c82d..238a71782df 100644 --- a/pkg/broker/filter/filter_handler.go +++ b/pkg/broker/filter/filter_handler.go @@ -151,8 +151,6 @@ func (r *Handler) serveHTTP(ctx context.Context, event cloudevents.Event, resp * return nil } - r.logger.Info("QQQQQ - incoming span", zap.Any("traceID", trace.FromContext(ctx).SpanContext().TraceID.String()), zap.Any("traceparentAttribute", event.Extensions()["traceparent"])) - // tctx.URI is actually the path... triggerRef, err := path.Parse(tctx.URI) if err != nil { diff --git a/pkg/broker/ingress/ingress_handler.go b/pkg/broker/ingress/ingress_handler.go index 8b851861854..fb6a19fdf65 100644 --- a/pkg/broker/ingress/ingress_handler.go +++ b/pkg/broker/ingress/ingress_handler.go @@ -74,7 +74,7 @@ func (h *Handler) serveHTTP(ctx context.Context, event cloudevents.Event, resp * return nil } - event = tracing.AddTraceparentAttributeFromContext(ctx, event) + event = tracing.AddTraceparentAttributeFromContext(ctx, event) ///////////////////////////////// Is this needed? reporterArgs := &ReportArgs{ ns: h.Namespace, @@ -96,7 +96,6 @@ func (h *Handler) serveHTTP(ctx context.Context, event cloudevents.Event, resp * // bring it in manually. sendingCTX = trace.NewContext(sendingCTX, trace.FromContext(ctx)) - h.Logger.Info("QQQQQQQQQQQ - sending with traceparent", zap.Any("traceparent", event.Extensions()["traceparent"])) rctx, _, err := h.CeClient.Send(sendingCTX, event) rtctx := cloudevents.HTTPTransportContextFrom(rctx) // Record the dispatch time. diff --git a/pkg/tracing/traceparent.go b/pkg/tracing/traceparent.go index e603b6595a9..adb7856d949 100644 --- a/pkg/tracing/traceparent.go +++ b/pkg/tracing/traceparent.go @@ -25,8 +25,6 @@ import ( cloudevents "github.com/cloudevents/sdk-go" "go.opencensus.io/plugin/ochttp/propagation/b3" "go.opencensus.io/trace" - "go.uber.org/zap" - "knative.dev/eventing/pkg/logging" ) const ( @@ -46,7 +44,6 @@ func AddTraceparentAttributeFromContext(ctx context.Context, event cloudevents.E span := trace.FromContext(ctx) if span != nil { event.SetExtension(traceparentAttribute, traceparentAttributeValue(span)) - logging.FromContext(ctx).Info("QQQQQQQQQQQ - Added traceparent", zap.Any("traceparent", event.Extensions()[traceparentAttribute])) } return event } diff --git a/test/common/tracker.go b/test/common/tracker.go index 9a2dabdd453..100219bf816 100644 --- a/test/common/tracker.go +++ b/test/common/tracker.go @@ -20,6 +20,7 @@ limitations under the License. package common import ( + "encoding/json" "fmt" "k8s.io/apimachinery/pkg/api/meta" @@ -115,17 +116,17 @@ func (t *Tracker) AddObj(obj kmeta.OwnerRefable) { // Clean will delete all registered resources func (t *Tracker) Clean(awaitDeletion bool) error { for _, deleter := range t.resourcesToClean { - _, err := deleter.Resource.Get(deleter.Name, metav1.GetOptions{}) + r, err := deleter.Resource.Get(deleter.Name, metav1.GetOptions{}) if err != nil { t.logf("Failed to get to-be cleaned resource %q : %v", deleter.Name, err) } else { - // bytes, _ := json.MarshalIndent(r, "", " ") - // t.logf("Cleaning resource: %q\n%+v", deleter.Name, string(bytes)) + bytes, _ := json.MarshalIndent(r, "", " ") + t.logf("Cleaning resource: %q\n%+v", deleter.Name, string(bytes)) } if err := deleter.Resource.Delete(deleter.Name, nil); err != nil { t.logf("Failed to clean the resource %q : %v", deleter.Name, err) } else if awaitDeletion { - // t.logf("Waiting for %s to be deleted", deleter.Name) + t.logf("Waiting for %s to be deleted", deleter.Name) if err := wait.PollImmediate(interval, timeout, func() (bool, error) { if _, err := deleter.Resource.Get(deleter.Name, metav1.GetOptions{}); err != nil { return true, nil diff --git a/test/conformance/helpers/tracing/traces.go b/test/conformance/helpers/tracing/traces.go index 19ddfba7d1d..aa26a6a1b6e 100644 --- a/test/conformance/helpers/tracing/traces.go +++ b/test/conformance/helpers/tracing/traces.go @@ -119,7 +119,7 @@ func (t *TestSpanTree) SortChildren() { func (t TestSpanTree) height() int { height := 0 for _, child := range t.Children { - if ch := child.height(); ch > height { + if ch := child.height(); ch >= height { height = ch + 1 } } From bd97735099ecca7c8fa50eaa6f88bf3f2f1859b3 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Thu, 3 Oct 2019 16:57:32 -0700 Subject: [PATCH 13/20] 2 minutes. --- test/conformance/helpers/broker_tracing_test_helper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 9ba54697e1f..310e3d04c9a 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -61,7 +61,7 @@ func BrokerTracingTestHelper(t *testing.T, channelTestRunner common.ChannelTestR expected, mustContain := setupBrokerTracing(st, channel, client, loggerPodName, tc.incomingTraceId) assertLogContents(st, client, loggerPodName, mustContain) traceID := getTraceID(st, client, loggerPodName) - trace, err := zipkin.JSONTrace(traceID, expected.SpanCount(), 160*time.Second) + trace, err := zipkin.JSONTrace(traceID, expected.SpanCount(), 2*time.Minute) if err != nil { st.Fatalf("Unable to get trace %q: %v. Trace so far %+v", traceID, err, tracinghelper.PrettyPrintTrace(trace)) } From fc7509d29dcda4cc52423f7947675504f5805e72 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Thu, 3 Oct 2019 16:59:25 -0700 Subject: [PATCH 14/20] Remove unneeded addition of the traceparent attribute. --- pkg/broker/ingress/ingress_handler.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/broker/ingress/ingress_handler.go b/pkg/broker/ingress/ingress_handler.go index fb6a19fdf65..0963eb7f061 100644 --- a/pkg/broker/ingress/ingress_handler.go +++ b/pkg/broker/ingress/ingress_handler.go @@ -12,7 +12,6 @@ import ( "go.opencensus.io/trace" "go.uber.org/zap" "knative.dev/eventing/pkg/broker" - "knative.dev/eventing/pkg/tracing" "knative.dev/eventing/pkg/utils" ) @@ -74,8 +73,6 @@ func (h *Handler) serveHTTP(ctx context.Context, event cloudevents.Event, resp * return nil } - event = tracing.AddTraceparentAttributeFromContext(ctx, event) ///////////////////////////////// Is this needed? - reporterArgs := &ReportArgs{ ns: h.Namespace, broker: h.BrokerName, From e253e96cb098f65ab8975eb6a70430f5d11404ed Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Thu, 3 Oct 2019 17:01:59 -0700 Subject: [PATCH 15/20] Fix trace name unit test. --- pkg/tracing/names_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/tracing/names_test.go b/pkg/tracing/names_test.go index 8304da8bad4..ad24a8c4747 100644 --- a/pkg/tracing/names_test.go +++ b/pkg/tracing/names_test.go @@ -25,7 +25,7 @@ func TestBrokerIngressName(t *testing.T) { Namespace: testNS, BrokerName: broker, } - if got, want := BrokerIngressName(args), "my-broker-broker-ingress.test-namespace"; got != want { + if got, want := BrokerIngressName(args), "my-broker-broker.test-namespace"; got != want { t.Errorf("BrokerIngressName = %q, want %q", got, want) } } From 16e81047efacccad0d0a924c6c18da5bb0722837 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Fri, 4 Oct 2019 10:23:17 -0700 Subject: [PATCH 16/20] Improve comments. --- .../helpers/broker_tracing_test_helper.go | 21 +++++++++---------- test/conformance/helpers/tracing/traces.go | 4 +++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 310e3d04c9a..3631b1b1c5f 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -65,7 +65,6 @@ func BrokerTracingTestHelper(t *testing.T, channelTestRunner common.ChannelTestR if err != nil { st.Fatalf("Unable to get trace %q: %v. Trace so far %+v", traceID, err, tracinghelper.PrettyPrintTrace(trace)) } - st.Logf("I got the trace, %q!\n%+v", traceID, tracinghelper.PrettyPrintTrace(trace)) tree := tracinghelper.GetTraceTree(st, trace) if err := expected.Matches(tree); err != nil { @@ -80,6 +79,7 @@ func BrokerTracingTestHelper(t *testing.T, channelTestRunner common.ChannelTestR // 1. Broker. // 2. Trigger on 'foo' events -> K8s Service -> transformer Pod (which replies with a 'bar' event). // 3. Trigger on 'bar' events -> K8s Service -> eventdetails Pod. +// 4. Sender Pod which sends a 'foo' event. // It returns a string that is expected to be sent by the SendEvents Pod and should be present in // the LogEvents Pod logs. func setupBrokerTracing(t *testing.T, channel string, client *common.Client, loggerPodName string, incomingTraceId bool) (tracinghelper.TestSpanTree, string) { @@ -95,11 +95,11 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // DO NOT SUBMIT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111!!!!!!!!!!!!!!!!!! time.Sleep(10 * time.Second) - // Create an logger (EventDetails) Pod and a K8s Service that points to it. + // Create a logger (EventDetails) Pod and a K8s Service that points to it. logPod := resources.EventDetailsPod(loggerPodName) client.CreatePodOrFail(logPod, common.WithService(loggerPodName)) - // Create a Trigger that receive events (type=bar) and send to logger Pod. + // Create a Trigger that receives events (type=bar) and sends them to the logger Pod. loggerTrigger := client.CreateTriggerOrFail( "logger", resources.WithBroker(brokerName), @@ -107,13 +107,14 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log resources.WithSubscriberRefForTrigger(loggerPodName), ) - // Create an event mutator to response an event with type bar + // Create a transformer (EventTransfrmer) Pod that replies with the same event as the input, + // except the reply's event's type is changed to bar. eventTransformerPod := resources.EventTransformationPod("transformer", &resources.CloudEvent{ Type: etLogger, }) client.CreatePodOrFail(eventTransformerPod, common.WithService(eventTransformerPod.Name)) - // Create a Trigger that receive events (type=foo) and send to event mutator Pod. + // Create a Trigger that receives events (type=foo) and sends them to the transformer Pod. transformerTrigger := client.CreateTriggerOrFail( "transformer", resources.WithBroker(brokerName), @@ -180,8 +181,8 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Useful constants we will use below. ingressHost := fmt.Sprintf("%s-broker.%s.svc.%s", brokerName, client.Namespace, domain) - triggerChanHost := fmt.Sprintf("%s-kne-trigger-kn-channel.%s.svc.%s", brokerName, client.Namespace, domain) ingressChanHost := fmt.Sprintf("%s-kne-ingress-kn-channel.%s.svc.%s", brokerName, client.Namespace, domain) + triggerChanHost := fmt.Sprintf("%s-kne-trigger-kn-channel.%s.svc.%s", brokerName, client.Namespace, domain) filterHost := fmt.Sprintf("%s-broker-filter.%s.svc.%s", brokerName, client.Namespace, domain) loggerTriggerPath := fmt.Sprintf("/triggers/%s/%s/%s", client.Namespace, loggerTrigger.Name, loggerTrigger.UID) transformerTriggerPath := fmt.Sprintf("/triggers/%s/%s/%s", client.Namespace, transformerTrigger.Name, transformerTrigger.UID) @@ -313,15 +314,13 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, } - // Steps 7-22. Directly steps 7-12. 13-22 are included as children. // Steps 7-10: Event from TrChannel sent to transformer Trigger and its reply to the InChannel. transformerEventSentFromTrChannelToTransformer := tracinghelper.TestSpanTree{ Note: "7. Broker TrChannel sends the event to the Broker Filter for the 'transformer' trigger.", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", - "http.status_code": "200", ///////////////////////////////////////////////////////////////// Weird, probably should be 200 - "http.url": fmt.Sprintf("http://%s%s", filterHost, transformerTriggerPath), + "http.method": "POST", + "http.url": fmt.Sprintf("http://%s%s", filterHost, transformerTriggerPath), }, Children: []tracinghelper.TestSpanTree{ { @@ -412,7 +411,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log }, } - // Steps 0-22. Directly steps 0-4 (missing 1) + // Steps 0-22. Directly steps 0-4 (missing 1). // Steps 0-4 (missing 1, which is optional and added below if present): Event sent to the Broker // Ingress. expected := tracinghelper.TestSpanTree{ diff --git a/test/conformance/helpers/tracing/traces.go b/test/conformance/helpers/tracing/traces.go index aa26a6a1b6e..5a56a7b7c7e 100644 --- a/test/conformance/helpers/tracing/traces.go +++ b/test/conformance/helpers/tracing/traces.go @@ -112,7 +112,9 @@ func (t *TestSpanTree) SortChildren() { return it[key] < jt[key] } } - panic(fmt.Errorf("can't tell the difference between %v, %v", ic, jc)) + // We don't have anything to reliably differentiate by. So this isn't going to really be + // sorted, just leave the existing one first arbitrarily. + return i < j }) } From 85cd1b7eb7f07d08e0be068cb308957622643887 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Fri, 4 Oct 2019 12:15:32 -0700 Subject: [PATCH 17/20] Swtich the sleep to waiting for the Broker to be ready. --- .../helpers/broker_tracing_test_helper.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 3631b1b1c5f..1992a1410e8 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -19,6 +19,7 @@ import ( "time" "github.com/openzipkin/zipkin-go/model" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/uuid" "knative.dev/eventing/pkg/apis/eventing/v1alpha1" "knative.dev/eventing/test/base/resources" @@ -92,8 +93,15 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log channelTypeMeta := common.GetChannelTypeMeta(channel) client.CreateBrokerOrFail(brokerName, channelTypeMeta) - // DO NOT SUBMIT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111!!!!!!!!!!!!!!!!!! - time.Sleep(10 * time.Second) + // Due to https://github.com/knative/eventing/issues/1998, wait for the Broker to become ready + // before creating the Triggers. + err := client.WaitForResourceReady(brokerName, &metav1.TypeMeta{ + APIVersion: resources.EventingAPIVersion, + Kind: "Broker", + }) + if err != nil { + t.Fatalf("Broker did not become ready: %v", err) + } // Create a logger (EventDetails) Pod and a K8s Service that points to it. logPod := resources.EventDetailsPod(loggerPodName) From 99e436846e51d6c2c4ab9471caec769c116da53e Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Tue, 8 Oct 2019 15:50:31 -0700 Subject: [PATCH 18/20] PR comments. --- test/common/creation.go | 3 +- test/common/tracker.go | 2 +- .../helpers/broker_tracing_test_helper.go | 84 +++++++++---------- test/conformance/helpers/constants.go | 48 +++++++++++ test/conformance/helpers/tracing/traces.go | 29 +++++-- 5 files changed, 111 insertions(+), 55 deletions(-) create mode 100644 test/conformance/helpers/constants.go diff --git a/test/common/creation.go b/test/common/creation.go index d621f61dd55..7b9b11b90a2 100644 --- a/test/common/creation.go +++ b/test/common/creation.go @@ -97,7 +97,7 @@ func (client *Client) CreateSubscriptionsOrFail( } // CreateBrokerOrFail will create a Broker or fail the test if there is an error. -func (client *Client) CreateBrokerOrFail(name string, channelTypeMeta *metav1.TypeMeta) { +func (client *Client) CreateBrokerOrFail(name string, channelTypeMeta *metav1.TypeMeta) *v1alpha1.Broker { namespace := client.Namespace broker := resources.Broker(name, resources.WithChannelTemplateForBroker(*channelTypeMeta)) @@ -108,6 +108,7 @@ func (client *Client) CreateBrokerOrFail(name string, channelTypeMeta *metav1.Ty client.T.Fatalf("Failed to create broker %q: %v", name, err) } client.Tracker.AddObj(broker) + return broker } // CreateBrokersOrFail will create a list of Brokers. diff --git a/test/common/tracker.go b/test/common/tracker.go index 100219bf816..160c4fd6672 100644 --- a/test/common/tracker.go +++ b/test/common/tracker.go @@ -145,7 +145,7 @@ func (t *Tracker) WaitForKResourcesReady() error { t.logf("Waiting for all KResources to become ready") for _, metaResource := range t.resourcesToCheckStatus { if err := base.WaitForResourceReady(t.dynamicClient, &metaResource); err != nil { - return fmt.Errorf("waiting for %+v to become ready: %v", metaResource, err) + return fmt.Errorf("failed waiting for %+v to become ready: %v", metaResource, err) } } return nil diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 1992a1410e8..2cc1cefbe2d 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -15,11 +15,11 @@ package helpers import ( "fmt" + "net/http" "testing" "time" "github.com/openzipkin/zipkin-go/model" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/uuid" "knative.dev/eventing/pkg/apis/eventing/v1alpha1" "knative.dev/eventing/test/base/resources" @@ -86,20 +86,14 @@ func BrokerTracingTestHelper(t *testing.T, channelTestRunner common.ChannelTestR func setupBrokerTracing(t *testing.T, channel string, client *common.Client, loggerPodName string, incomingTraceId bool) (tracinghelper.TestSpanTree, string) { // Create the Broker. const ( - brokerName = "br" etTransformer = "transformer" etLogger = "logger" ) channelTypeMeta := common.GetChannelTypeMeta(channel) - client.CreateBrokerOrFail(brokerName, channelTypeMeta) + broker := client.CreateBrokerOrFail("br", channelTypeMeta) - // Due to https://github.com/knative/eventing/issues/1998, wait for the Broker to become ready - // before creating the Triggers. - err := client.WaitForResourceReady(brokerName, &metav1.TypeMeta{ - APIVersion: resources.EventingAPIVersion, - Kind: "Broker", - }) - if err != nil { + // TODO Remove this wait once https://github.com/knative/eventing/issues/1998 is fixed. + if err := client.WaitForResourceReady(broker.Name, common.BrokerTypeMeta); err != nil { t.Fatalf("Broker did not become ready: %v", err) } @@ -110,7 +104,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Create a Trigger that receives events (type=bar) and sends them to the logger Pod. loggerTrigger := client.CreateTriggerOrFail( "logger", - resources.WithBroker(brokerName), + resources.WithBroker(broker.Name), resources.WithAttributesTriggerFilter(v1alpha1.TriggerAnyFilter, etLogger, map[string]interface{}{}), resources.WithSubscriberRefForTrigger(loggerPodName), ) @@ -125,7 +119,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // Create a Trigger that receives events (type=foo) and sends them to the transformer Pod. transformerTrigger := client.CreateTriggerOrFail( "transformer", - resources.WithBroker(brokerName), + resources.WithBroker(broker.Name), resources.WithAttributesTriggerFilter(v1alpha1.TriggerAnyFilter, etTransformer, map[string]interface{}{}), resources.WithSubscriberRefForTrigger(eventTransformerPod.Name), ) @@ -152,8 +146,8 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log if incomingTraceId { sendEvent = client.SendFakeEventWithTracingToAddressable } - if err := sendEvent(senderName, brokerName, common.BrokerTypeMeta, event); err != nil { - t.Fatalf("Failed to send fake CloudEvent to the broker %q", brokerName) + if err := sendEvent(senderName, broker.Name, common.BrokerTypeMeta, event); err != nil { + t.Fatalf("Failed to send fake CloudEvent to the broker %q", broker.Name) } // TODO Actually determine the cluster's domain, similar to knative.dev/pkg/network/domain.go. @@ -188,14 +182,14 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log // 22. Logger pod receives the event from the Broker Filter for the "logger" trigger. // Useful constants we will use below. - ingressHost := fmt.Sprintf("%s-broker.%s.svc.%s", brokerName, client.Namespace, domain) - ingressChanHost := fmt.Sprintf("%s-kne-ingress-kn-channel.%s.svc.%s", brokerName, client.Namespace, domain) - triggerChanHost := fmt.Sprintf("%s-kne-trigger-kn-channel.%s.svc.%s", brokerName, client.Namespace, domain) - filterHost := fmt.Sprintf("%s-broker-filter.%s.svc.%s", brokerName, client.Namespace, domain) - loggerTriggerPath := fmt.Sprintf("/triggers/%s/%s/%s", client.Namespace, loggerTrigger.Name, loggerTrigger.UID) - transformerTriggerPath := fmt.Sprintf("/triggers/%s/%s/%s", client.Namespace, transformerTrigger.Name, transformerTrigger.UID) - loggerSVCHost := fmt.Sprintf("%s.%s.svc.%s", loggerPodName, client.Namespace, domain) - transformerSVCHost := fmt.Sprintf("%s.%s.svc.%s", eventTransformerPod.Name, client.Namespace, domain) + ingressHost := brokerIngressHost(domain, *broker) + ingressChanHost := brokerIngressChannelHost(domain, *broker) + triggerChanHost := brokerTriggerChannelHost(domain, *broker) + filterHost := brokerFilterHost(domain, *broker) + loggerTriggerPath := triggerPath(*loggerTrigger) + transformerTriggerPath := triggerPath(*transformerTrigger) + loggerSVCHost := k8sServiceHost(domain, client.Namespace, loggerPodName) + transformerSVCHost := k8sServiceHost(domain, client.Namespace, eventTransformerPod.Name) // This is very hard to read when written directly, so we will build piece by piece. @@ -204,7 +198,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "17. Broker TrChannel sends the event to the Broker Filter for the 'transformer' trigger.", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.url": fmt.Sprintf("http://%s%s", filterHost, transformerTriggerPath), }, @@ -213,7 +207,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "18. Broker Filter for the 'transformer' trigger receives the event from the Broker TrChannel. This does not pass the filter, so this 'branch' ends here.", Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.host": filterHost, "http.path": transformerTriggerPath, @@ -227,7 +221,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "19. Broker TrChannel sends the event to the Broker Filter for the 'logger' trigger.", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.url": fmt.Sprintf("http://%s%s", filterHost, loggerTriggerPath), }, @@ -236,7 +230,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "20. Broker Filter for the 'logger' trigger receives the event from the Broker TrChannel.", Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.host": filterHost, "http.path": loggerTriggerPath, @@ -246,7 +240,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "21. Broker Filter for the 'logger' trigger sends the event to the logger pod.", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.url": fmt.Sprintf("http://%s/", loggerSVCHost), }, @@ -255,7 +249,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "22. Logger pod receives the event from the Broker Filter for the 'logger' trigger.", Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.path": "/", "http.status_code": "202", "http.host": loggerSVCHost, @@ -274,7 +268,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "13. Broker InChannel sends the event to the Broker Ingress.", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.url": fmt.Sprintf("http://%s/", ingressHost), }, @@ -284,7 +278,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.path": "/", "http.status_code": "202", "http.host": ingressHost, @@ -294,7 +288,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "15. Broker Ingress sends the event to the Broker's TrChannel.", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.url": fmt.Sprintf("http://%s/", triggerChanHost), }, @@ -303,7 +297,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "16. Broker TrChannel receives the event from the Broker Ingress.", Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.host": triggerChanHost, "http.path": "/", @@ -327,7 +321,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "7. Broker TrChannel sends the event to the Broker Filter for the 'transformer' trigger.", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.url": fmt.Sprintf("http://%s%s", filterHost, transformerTriggerPath), }, Children: []tracinghelper.TestSpanTree{ @@ -335,7 +329,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "8. Broker Filter for the 'transformer' trigger receives the event from the Broker TrChannel.", Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.host": filterHost, "http.path": transformerTriggerPath, @@ -345,7 +339,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "9. Broker Filter for the 'transformer' trigger sends the event to the transformer pod.", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "200", "http.url": fmt.Sprintf("http://%s/", transformerSVCHost), }, @@ -354,7 +348,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "10. Transformer pod receives the event from the Broker Filter for the 'transformer' trigger.", Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.path": "/", "http.status_code": "200", "http.host": transformerSVCHost, @@ -374,7 +368,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "11. Broker TrChannel for the 'transformer' sends the transformer pod's reply to the Broker InChannel.", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.url": fmt.Sprintf("http://%s", ingressChanHost), }, @@ -383,7 +377,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "12. Broker InChannel receives the event from the Broker TrChannel for the 'transformer' trigger.", Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.host": ingressChanHost, "http.path": "/", @@ -401,7 +395,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "5. Broker TrChannel sends the event to the Broker Filter for the 'logger' trigger.", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.url": fmt.Sprintf("http://%s%s", filterHost, loggerTriggerPath), }, @@ -410,7 +404,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "6. Broker Filter for the 'logger' trigger receives the event from the Broker TrChannel. This does not pass the filter, so this 'branch' ends here.", Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.host": filterHost, "http.path": loggerTriggerPath, @@ -430,7 +424,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "2. Broker Ingress receives the event from the sending pod.", Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.host": ingressHost, "http.path": "/", @@ -440,7 +434,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "3. Broker Ingress sends the event to the Broker's TrChannel (trigger channel).", Kind: model.Client, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.url": fmt.Sprintf("http://%s/", triggerChanHost), }, @@ -449,7 +443,7 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Note: "4. Broker TrChannel receives the event from the Broker Ingress.", Kind: model.Server, Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", "http.host": triggerChanHost, "http.path": "/", @@ -477,9 +471,9 @@ func setupBrokerTracing(t *testing.T, channel string, client *common.Client, log Kind: model.Client, LocalEndpointServiceName: "sender", Tags: map[string]string{ - "http.method": "POST", + "http.method": http.MethodPost, "http.status_code": "202", - "http.url": fmt.Sprintf("http://%s-broker.%s.svc.cluster.local", brokerName, client.Namespace), + "http.url": fmt.Sprintf("http://%s", ingressHost), }, Children: expected.Children, }, diff --git a/test/conformance/helpers/constants.go b/test/conformance/helpers/constants.go new file mode 100644 index 00000000000..a02e6f099cc --- /dev/null +++ b/test/conformance/helpers/constants.go @@ -0,0 +1,48 @@ +/* +Copyright 2019 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 helpers + +import ( + "fmt" + + "knative.dev/eventing/pkg/apis/eventing/v1alpha1" +) + +func brokerIngressHost(domain string, broker v1alpha1.Broker) string { + return fmt.Sprintf("%s-broker.%s.svc.%s", broker.Name, broker.Namespace, domain) +} + +func channelHost(domain, namespace, chanName string) string { + return fmt.Sprintf("%s-kn-channel.%s.svc.%s", chanName, namespace, domain) +} + +func brokerIngressChannelHost(domain string, broker v1alpha1.Broker) string { + return channelHost(domain, broker.Namespace, fmt.Sprintf("%s-kne-ingress", broker.Name)) +} + +func brokerTriggerChannelHost(domain string, broker v1alpha1.Broker) string { + return channelHost(domain, broker.Namespace, fmt.Sprintf("%s-kne-trigger", broker.Name)) +} + +func brokerFilterHost(domain string, broker v1alpha1.Broker) string { + return fmt.Sprintf("%s-broker-filter.%s.svc.%s", broker.Name, broker.Namespace, domain) +} + +func triggerPath(trigger v1alpha1.Trigger) string { + return fmt.Sprintf("/triggers/%s/%s/%s", trigger.Namespace, trigger.Name, trigger.UID) +} + +func k8sServiceHost(domain, namespace, svcName string) string { + return fmt.Sprintf("%s.%s.svc.%s", svcName, namespace, domain) +} diff --git a/test/conformance/helpers/tracing/traces.go b/test/conformance/helpers/tracing/traces.go index 5a56a7b7c7e..5b6a293cb29 100644 --- a/test/conformance/helpers/tracing/traces.go +++ b/test/conformance/helpers/tracing/traces.go @@ -75,14 +75,18 @@ func (t SpanTree) toTestSpanTreeHelper() TestSpanTree { } // TestSpanTree is the expected version of SpanTree used for assertions in testing. +// +// The JSON names of the fields are weird because we want a specific order when pretty printing +// JSON. The JSON will be printed in alphabetical order, so we are imposing a certain order by +// prefixing the keys with a specific letter. The letter has no mean other than ordering. type TestSpanTree struct { - Note string `json:"aaNote,omitempty"` - Root bool `json:"root,omitempty"` - Kind model.Kind `json:"aKind,omitempty"` - LocalEndpointServiceName string `json:"aName,omitempty"` - Tags map[string]string `json:"tags,omitempty"` + Note string `json:"a_Note,omitempty"` + Root bool `json:"b_Root,omitempty"` + Kind model.Kind `json:"c_Kind,omitempty"` + LocalEndpointServiceName string `json:"d_Name,omitempty"` + Tags map[string]string `json:"e_Tags,omitempty"` - Children []TestSpanTree `json:"zChildren,omitempty"` + Children []TestSpanTree `json:"z_Children,omitempty"` } func (t TestSpanTree) String() string { @@ -90,6 +94,16 @@ func (t TestSpanTree) String() string { return string(b) } +// SortChildren attempts to sort the children of this TestSpanTree. The children are siblings, order +// does not actually matter. TestSpanTree.Matches() correctly handles this, by matching in any +// order. SortChildren() is most useful before JSON pretty printing the structure and comparing +// manually. +// +// The order it uses: +// 1. Shorter children first. +// 2. Span kind. +// 3. "http.url", "http.host", "http.path" tag presence and values. +// If all of those are equal, then arbitrarily chose the earlier index. func (t *TestSpanTree) SortChildren() { for _, child := range t.Children { child.SortChildren() @@ -192,8 +206,7 @@ func (t TestSpanTree) Matches(actual SpanTree) error { return fmt.Errorf("unexpected number of spans. got %d want %d", g, w) } t.SortChildren() - err := traceTreeMatches(".", t, actual) - if err != nil { + if err := traceTreeMatches(".", t, actual); err != nil { return fmt.Errorf("spanTree did not match: %v. \n*****Actual***** %v\n*****Expected***** %v", err, actual.ToTestSpanTree().String(), t.String()) } return nil From c6b8a3457cad06bba7b67e16c53fd2a235c9e3f9 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Tue, 8 Oct 2019 17:13:20 -0700 Subject: [PATCH 19/20] Rename to uri.go. --- test/conformance/broker_tracing_test.go | 3 +++ test/conformance/helpers/broker_tracing_test_helper.go | 3 +++ test/conformance/helpers/{constants.go => uri.go} | 3 +++ 3 files changed, 9 insertions(+) rename test/conformance/helpers/{constants.go => uri.go} (99%) diff --git a/test/conformance/broker_tracing_test.go b/test/conformance/broker_tracing_test.go index e193d266c60..cdf18cf48ce 100644 --- a/test/conformance/broker_tracing_test.go +++ b/test/conformance/broker_tracing_test.go @@ -2,10 +2,13 @@ /* Copyright 2019 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. diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index 2cc1cefbe2d..e40ad1458af 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -1,9 +1,12 @@ /* Copyright 2019 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. diff --git a/test/conformance/helpers/constants.go b/test/conformance/helpers/uri.go similarity index 99% rename from test/conformance/helpers/constants.go rename to test/conformance/helpers/uri.go index a02e6f099cc..0ee80d7da3c 100644 --- a/test/conformance/helpers/constants.go +++ b/test/conformance/helpers/uri.go @@ -1,9 +1,12 @@ /* Copyright 2019 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. From fdffd78ba0880f90440d436e5315f0a2f5f28421 Mon Sep 17 00:00:00 2001 From: Adam Harwayne Date: Tue, 8 Oct 2019 17:16:45 -0700 Subject: [PATCH 20/20] chose -> choose --- test/conformance/helpers/tracing/traces.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/conformance/helpers/tracing/traces.go b/test/conformance/helpers/tracing/traces.go index 5b6a293cb29..613b071d61b 100644 --- a/test/conformance/helpers/tracing/traces.go +++ b/test/conformance/helpers/tracing/traces.go @@ -103,7 +103,7 @@ func (t TestSpanTree) String() string { // 1. Shorter children first. // 2. Span kind. // 3. "http.url", "http.host", "http.path" tag presence and values. -// If all of those are equal, then arbitrarily chose the earlier index. +// If all of those are equal, then arbitrarily choose the earlier index. func (t *TestSpanTree) SortChildren() { for _, child := range t.Children { child.SortChildren()