Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/conformance/broker_tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ import (
)

func TestBrokerTracing(t *testing.T) {
t.Skip("needs to be reworked for OTel (eventing#8637)")
t.Skip("OTel type migration done (eventing#8853), but needs cluster-side OTel collector infrastructure to run")
helpers.BrokerTracingTestHelperWithChannelTestRunner(context.Background(), t, brokerClass, channelTestRunner, testlib.SetupClientOptionNoop)
}
2 changes: 1 addition & 1 deletion test/conformance/channel_tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ import (
)

func TestChannelTracingWithReply(t *testing.T) {
t.Skip("needs to be reworked for OTel (eventing#8637)")
t.Skip("OTel type migration done (eventing#8853), but needs cluster-side OTel collector infrastructure to run")
helpers.ChannelTracingTestHelperWithChannelTestRunner(context.Background(), t, channelTestRunner, testlib.SetupClientOptionNoop)
}
8 changes: 4 additions & 4 deletions test/conformance/helpers/broker_tracing_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

cloudevents "github.com/cloudevents/sdk-go/v2"
cetest "github.com/cloudevents/sdk-go/v2/test"
"github.com/openzipkin/zipkin-go/model"
oteltrace "go.opentelemetry.io/otel/trace"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "knative.dev/eventing/pkg/apis/eventing/v1"
Expand Down Expand Up @@ -151,7 +151,7 @@ func setupBrokerTracing(_ context.Context, brokerClass string) SetupTracingTestI
{
Note: "4. Transformer pod receives the event from the Broker Filter for the 'transformer' trigger.",
Span: tracinghelper.MatchHTTPSpanWithReply(
model.Server,
oteltrace.SpanKindServer,
tracinghelper.WithHTTPHostAndPath(transformerSVCHost, "/"),
tracinghelper.WithLocalEndpointServiceName(eventTransformerPod.Name),
),
Expand All @@ -170,7 +170,7 @@ func setupBrokerTracing(_ context.Context, brokerClass string) SetupTracingTestI
{
Note: "7. Logger pod receives the event from the Broker Filter for the 'logger' trigger.",
Span: tracinghelper.MatchHTTPSpanNoReply(
model.Server,
oteltrace.SpanKindServer,
tracinghelper.WithHTTPHostAndPath(loggerSVCHost, "/"),
tracinghelper.WithLocalEndpointServiceName(loggerPodName),
),
Expand Down Expand Up @@ -198,7 +198,7 @@ func setupBrokerTracing(_ context.Context, brokerClass string) SetupTracingTestI
expected = tracinghelper.TestSpanTree{
Note: "1. Send pod sends event to the Broker Ingress (only if the sending pod generates a span).",
Span: tracinghelper.MatchHTTPSpanNoReply(
model.Client,
oteltrace.SpanKindClient,
tracinghelper.WithLocalEndpointServiceName(senderName),
),
Children: []tracinghelper.TestSpanTree{expected},
Expand Down
20 changes: 10 additions & 10 deletions test/conformance/helpers/channel_tracing_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
cloudevents "github.com/cloudevents/sdk-go/v2"
cetest "github.com/cloudevents/sdk-go/v2/test"
"github.com/google/uuid"
"github.com/openzipkin/zipkin-go/model"
oteltrace "go.opentelemetry.io/otel/trace"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

ch "knative.dev/eventing/pkg/channel"
Expand Down Expand Up @@ -142,7 +142,7 @@ func setupChannelTracingWithReply(
// 1 is added below if it is needed.
// 2. Channel receives event from sending pod.
Span: tracinghelper.MatchHTTPSpanNoReply(
model.Server,
oteltrace.SpanKindServer,
tracinghelper.WithHTTPHostAndPath(
fmt.Sprintf("%s%s.%s.svc", channelName, ch.K8ServiceNameSuffix, client.Namespace),
"/",
Expand All @@ -156,7 +156,7 @@ func setupChannelTracingWithReply(
{
// 4. Channel sends event to Mutator pod.
Span: tracinghelper.MatchHTTPSpanWithReply(
model.Client,
oteltrace.SpanKindClient,
tracinghelper.WithHTTPURL(
fmt.Sprintf("%s.%s.svc", mutatingPod.Name, client.Namespace),
"",
Expand All @@ -166,7 +166,7 @@ func setupChannelTracingWithReply(
{
// 5. Mutator Pod receives event from Channel.
Span: tracinghelper.MatchHTTPSpanWithReply(
model.Server,
oteltrace.SpanKindServer,
tracinghelper.WithHTTPHostAndPath(
fmt.Sprintf("%s.%s.svc", mutatingPod.Name, client.Namespace),
"/",
Expand All @@ -183,7 +183,7 @@ func setupChannelTracingWithReply(
{
// 7. Channel sends reply from Mutator Pod to the reply Channel.
Span: tracinghelper.MatchHTTPSpanNoReply(
model.Client,
oteltrace.SpanKindClient,
tracinghelper.WithHTTPURL(
fmt.Sprintf("%s%s.%s.svc", replyChannelName, ch.K8ServiceNameSuffix, client.Namespace),
"",
Expand All @@ -193,7 +193,7 @@ func setupChannelTracingWithReply(
{
// 8. Reply Channel receives event from the original Channel's reply.
Span: tracinghelper.MatchHTTPSpanNoReply(
model.Server,
oteltrace.SpanKindServer,
tracinghelper.WithHTTPHostAndPath(
fmt.Sprintf("%s%s.%s.svc", replyChannelName, ch.K8ServiceNameSuffix, client.Namespace),
"/",
Expand All @@ -207,7 +207,7 @@ func setupChannelTracingWithReply(
{
// 10. Reply Channel sends event to the logging Pod.
Span: tracinghelper.MatchHTTPSpanNoReply(
model.Client,
oteltrace.SpanKindClient,
tracinghelper.WithHTTPURL(
fmt.Sprintf("%s.%s.svc", recordEventsPod.Name, client.Namespace),
"",
Expand All @@ -217,7 +217,7 @@ func setupChannelTracingWithReply(
{
// 11. Logging pod receives event from Channel.
Span: tracinghelper.MatchHTTPSpanNoReply(
model.Server,
oteltrace.SpanKindServer,
tracinghelper.WithHTTPHostAndPath(
fmt.Sprintf("%s.%s.svc", recordEventsPod.Name, client.Namespace),
"/",
Expand All @@ -244,7 +244,7 @@ func setupChannelTracingWithReply(
expected = tracinghelper.TestSpanTree{
// 1. Sending pod sends event to Channel (only if the sending pod generates a span).
Span: tracinghelper.MatchHTTPSpanNoReply(
model.Client,
oteltrace.SpanKindClient,
tracinghelper.WithHTTPURL(
fmt.Sprintf("%s%s.%s.svc", channelName, ch.K8ServiceNameSuffix, client.Namespace),
"",
Expand All @@ -263,7 +263,7 @@ func setupChannelTracingWithReply(
}

func channelSpan(eventID, host, path string) *tracinghelper.SpanMatcher {
k := model.Client
k := oteltrace.SpanKindClient
return &tracinghelper.SpanMatcher{
Kind: &k,
Tags: map[string]*regexp.Regexp{
Expand Down
68 changes: 41 additions & 27 deletions test/conformance/helpers/tracing/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"strconv"
"testing"

"github.com/openzipkin/zipkin-go/model"
oteltrace "go.opentelemetry.io/otel/trace"
)

// hostSuffix is an optional suffix that might appear at the end of hostnames.
Expand All @@ -43,16 +43,28 @@ import (
// and then match anything prior to the path starting, e.g. '/'
const HostSuffix = "[.][^/]+"

// SpanData is a lightweight representation of an OTel span containing just the
// fields needed for test assertions. This avoids depending on the full
// ReadOnlySpan interface which is cumbersome to construct in tests.
type SpanData struct {
SpanContext oteltrace.SpanContext
Parent oteltrace.SpanContext
Name string
Kind oteltrace.SpanKind
ServiceName string
Attributes map[string]string
}

// PrettyPrintTrace pretty prints a Trace.
func PrettyPrintTrace(trace []model.SpanModel) string {
func PrettyPrintTrace(trace []SpanData) string {
b, _ := json.Marshal(trace)
return string(b)
}

// SpanTree is the tree of Spans representation of a Trace.
type SpanTree struct {
Root bool
Span model.SpanModel
Span SpanData
Children []SpanTree
}

Expand All @@ -62,16 +74,16 @@ func (t SpanTree) String() string {
}

type SpanMatcher struct {
Kind *model.Kind `json:"a_Kind,omitempty"`
LocalEndpointServiceName string `json:"b_Name,omitempty"`
Tags map[string]*regexp.Regexp `json:"c_Tags,omitempty"`
Kind *oteltrace.SpanKind `json:"a_Kind,omitempty"`
ServiceName string `json:"b_Name,omitempty"`
Tags map[string]*regexp.Regexp `json:"c_Tags,omitempty"`
}

type SpanMatcherOption func(*SpanMatcher)

func WithLocalEndpointServiceName(s string) SpanMatcherOption {
return func(m *SpanMatcher) {
m.LocalEndpointServiceName = s
m.ServiceName = s
}
}

Expand All @@ -88,7 +100,7 @@ func WithHTTPURL(host, path string) SpanMatcherOption {
}
}

func (m *SpanMatcher) MatchesSpan(span *model.SpanModel) error {
func (m *SpanMatcher) MatchesSpan(span *SpanData) error {
if m == nil {
return nil
}
Expand All @@ -97,23 +109,23 @@ func (m *SpanMatcher) MatchesSpan(span *model.SpanModel) error {
return fmt.Errorf("mismatched kind: got %q, want %q", span.Kind, *m.Kind)
}
}
if m.LocalEndpointServiceName != "" {
if span.LocalEndpoint == nil {
return errors.New("missing local endpoint")
if m.ServiceName != "" {
if span.ServiceName == "" {
return errors.New("missing service name")
}
if m.LocalEndpointServiceName != span.LocalEndpoint.ServiceName {
return fmt.Errorf("mismatched LocalEndpoint ServiceName: got %q, want %q", span.LocalEndpoint.ServiceName, m.LocalEndpointServiceName)
if m.ServiceName != span.ServiceName {
return fmt.Errorf("mismatched ServiceName: got %q, want %q", span.ServiceName, m.ServiceName)
}
}
for k, v := range m.Tags {
if t := span.Tags[k]; !v.MatchString(t) {
if t := span.Attributes[k]; !v.MatchString(t) {
return fmt.Errorf("unexpected tag %s: got %q, want %q", k, t, v)
}
}
return nil
}

func MatchSpan(kind model.Kind, opts ...SpanMatcherOption) *SpanMatcher {
func MatchSpan(kind oteltrace.SpanKind, opts ...SpanMatcherOption) *SpanMatcher {
m := &SpanMatcher{
Kind: &kind,
}
Expand All @@ -123,7 +135,7 @@ func MatchSpan(kind model.Kind, opts ...SpanMatcherOption) *SpanMatcher {
return m
}

func MatchHTTPSpanWithCode(kind model.Kind, statusCode int, opts ...SpanMatcherOption) *SpanMatcher {
func MatchHTTPSpanWithCode(kind oteltrace.SpanKind, statusCode int, opts ...SpanMatcherOption) *SpanMatcher {
return MatchSpan(kind, WithCode(statusCode))
}

Expand All @@ -136,11 +148,11 @@ func WithCode(statusCode int) SpanMatcherOption {
}
}

func MatchHTTPSpanNoReply(kind model.Kind, opts ...SpanMatcherOption) *SpanMatcher {
func MatchHTTPSpanNoReply(kind oteltrace.SpanKind, opts ...SpanMatcherOption) *SpanMatcher {
return MatchHTTPSpanWithCode(kind, 202, opts...)
}

func MatchHTTPSpanWithReply(kind model.Kind, opts ...SpanMatcherOption) *SpanMatcher {
func MatchHTTPSpanWithReply(kind oteltrace.SpanKind, opts ...SpanMatcherOption) *SpanMatcher {
return MatchHTTPSpanWithCode(kind, 200, opts...)
}

Expand All @@ -160,13 +172,14 @@ func (tt TestSpanTree) String() string {
return string(b)
}

// GetTraceTree converts a set slice of spans into a SpanTree.
func GetTraceTree(trace []model.SpanModel) (*SpanTree, error) {
var roots []model.SpanModel
parents := map[model.ID][]model.SpanModel{}
// GetTraceTree converts a slice of SpanData into a SpanTree.
func GetTraceTree(trace []SpanData) (*SpanTree, error) {
var roots []SpanData
parents := map[oteltrace.SpanID][]SpanData{}
for _, span := range trace {
if span.ParentID != nil {
parents[*span.ParentID] = append(parents[*span.ParentID], span)
if span.Parent.IsValid() && span.Parent.HasSpanID() {
parentID := span.Parent.SpanID()
parents[parentID] = append(parents[parentID], span)
} else {
roots = append(roots, span)
}
Expand All @@ -191,18 +204,19 @@ func GetTraceTree(trace []model.SpanModel) (*SpanTree, error) {
return &tree, nil
}

func getChildren(parents map[model.ID][]model.SpanModel, current []model.SpanModel) ([]SpanTree, error) {
func getChildren(parents map[oteltrace.SpanID][]SpanData, current []SpanData) ([]SpanTree, error) {
children := make([]SpanTree, 0, len(current))
for _, span := range current {
grandchildren, err := getChildren(parents, parents[span.ID])
spanID := span.SpanContext.SpanID()
grandchildren, err := getChildren(parents, parents[spanID])
if err != nil {
return children, err
}
children = append(children, SpanTree{
Span: span,
Children: grandchildren,
})
delete(parents, span.ID)
delete(parents, spanID)
}

return children, nil
Expand Down
Loading