Skip to content

Commit

Permalink
Tracing tests updates (#2532)
Browse files Browse the repository at this point in the history
* Do not call deprecated eventshub.AddTracing

* Remove workaround for incorrect tracing shutdown

The issue knative/pkg#2475 has been resolved.
It's not necessary to send multiple events anymore. Each event should be
exported to Zipking because of the new fix for tracer shutdown.

* Update reconciler-test dependency
  • Loading branch information
mgencur authored Sep 6, 2022
1 parent e5a6438 commit a8858e4
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
knative.dev/eventing-kafka v0.34.0
knative.dev/hack v0.0.0-20220823140917-8d1e4ccf9dc3
knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15
knative.dev/reconciler-test v0.0.0-20220818122349-177f8264c28c
knative.dev/reconciler-test v0.0.0-20220901014218-ff8756131bd5
sigs.k8s.io/yaml v1.3.0
)

Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1572,8 +1572,9 @@ knative.dev/hack v0.0.0-20220823140917-8d1e4ccf9dc3/go.mod h1:t/azP8I/Cygaw+87O7
knative.dev/hack/schema v0.0.0-20220823140917-8d1e4ccf9dc3/go.mod h1:ffjwmdcrH5vN3mPhO8RrF2KfNnbHeCE2C60A+2cv3U0=
knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15 h1:GNmzHVaUo3zoi/wtIN71LPQaWy6DdoYzmb+GIq2s4fw=
knative.dev/pkg v0.0.0-20220818004048-4a03844c0b15/go.mod h1:YLjXbkQLlGHok+u0FLfMbBHFzY9WGu3GHhnrptoAy8I=
knative.dev/reconciler-test v0.0.0-20220818122349-177f8264c28c h1:wWtcZ1ZyP+mXx4xQmcKzKyXkk/t07/iSq/jqhqxoyCM=
knative.dev/reconciler-test v0.0.0-20220818122349-177f8264c28c/go.mod h1:A437yxlDVDVKQv779WlB9Nj9lWAMoOKHQXFXls24Sps=
knative.dev/reconciler-test v0.0.0-20220901014218-ff8756131bd5 h1:Z17OIrS0nusy3sgqWNSWGWqyFvYhhMaTXqDU32vTLuk=
knative.dev/reconciler-test v0.0.0-20220901014218-ff8756131bd5/go.mod h1:LTqPpT5I7bSUToTpKpNkW6avSRFnMt4hby1y53MEBLE=
pgregory.net/rapid v0.3.3 h1:jCjBsY4ln4Atz78QoBWxUEvAHaFyNDQg9+WU62aCn1U=
pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
1 change: 0 additions & 1 deletion test/e2e_new/features/featuressteps/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func BrokerSmokeTest(brokerName, triggerName string) feature.StepFn {
feature.MakeRandomK8sName("source"),
eventshub.StartSenderToResource(broker.GVR(), brokerName),
eventshub.AddSequence,
eventshub.AddTracing,
eventshub.InputEvent(event),
),
assert.OnStore(sink).MatchEvent(eventMatchers...).Exact(1),
Expand Down
11 changes: 1 addition & 10 deletions test/e2e_new/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,12 @@ func TracingHeadersUsingOrderedDeliveryWithTraceExported() *feature.Feature {
sourceName,
eventshub.StartSenderToResource(broker.GVR(), brokerName),
eventshub.InputEvent(ev),
eventshub.AddTracing,
// Send at least two events to workaround https://github.com/knative/pkg/issues/2475.
// There's some time needed for exporting the trace to Zipkin. Sending two events with
// some delay gives the exporter time to export the trace for the first event. The sender
// is shutdown immediately after sending the last event so the trace for the last
// event will probably not be exported.
eventshub.SendMultipleEvents(2, 3*time.Second),
))

f.Assert("received event has traceparent header",
OnStore(sinkName).
Match(MatchKind(EventReceived), hasTraceparentHeader).
AtLeast(1),
Exact(1),
)

f.Assert("event trace exported", brokerHasMatchingTraceTree(sourceName, sinkName, brokerName, ev.ID()))
Expand Down Expand Up @@ -225,7 +218,6 @@ func TracingHeadersUsingUnorderedDelivery() *feature.Feature {
sourceName,
eventshub.StartSenderToResource(broker.GVR(), brokerName),
eventshub.InputEvent(ev),
eventshub.AddTracing,
))

f.Assert("received event has traceparent header",
Expand Down Expand Up @@ -276,7 +268,6 @@ func TracingHeadersUsingUnorderedDeliveryWithMultipleTriggers() *feature.Feature
sourceName,
eventshub.StartSenderToResource(broker.GVR(), brokerName),
eventshub.InputEvent(ev),
eventshub.AddTracing,
eventshub.SendMultipleEvents(5, time.Millisecond),
))

Expand Down
10 changes: 1 addition & 9 deletions test/e2e_new_channel/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"context"
"fmt"
"testing"
"time"

cetest "github.com/cloudevents/sdk-go/v2/test"
"github.com/openzipkin/zipkin-go/model"
Expand Down Expand Up @@ -87,13 +86,6 @@ func eventWithTraceExported() *feature.Feature {
sourceName,
eventshub.StartSenderToResource(channel_impl.GVR(), channelName),
eventshub.InputEvent(ev),
eventshub.AddTracing,
// Send at least two events to workaround https://github.com/knative/pkg/issues/2475.
// There's some time needed for exporting the trace to Zipkin. Sending two events with
// some delay gives the exporter time to export the trace for the first event. The sender
// is shutdown immediately after sending the last event so the trace for the last
// event will probably not be exported.
eventshub.SendMultipleEvents(2, 3*time.Second),
))

f.Assert("event trace exported", channelHasMatchingTraceTree(sourceName, sinkName, channelName, ev.ID()))
Expand Down Expand Up @@ -170,7 +162,7 @@ func channelHasMatchingTraceTree(sourceName, sinkName, channelName, eventID stri
},
},
}
eventshub.StoreFromContext(ctx, sinkName).AssertAtLeast(t, 1,
eventshub.StoreFromContext(ctx, sinkName).AssertExact(t, 1,
MatchKind(EventReceived),
tracing.TraceTreeMatches(sourceName, eventID, expectedTree),
)
Expand Down
6 changes: 4 additions & 2 deletions vendor/knative.dev/reconciler-test/pkg/eventshub/eventshub.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ func Start(eventLogFactories map[string]EventLogFactory, eventGeneratorFactories
ctx, _ := injection.EnableInjectionOrDie(nil, nil)
ctx = ConfigureLogging(ctx, "eventshub")

if err := ConfigureTracing(logging.FromContext(ctx), ""); err != nil {
tracer, err := ConfigureTracing(logging.FromContext(ctx), "")
if err != nil {
logging.FromContext(ctx).Fatal("Unable to setup trace publishing", err)
}
defer tracer.Shutdown(context.Background())

var env envConfig
if err := envconfig.Process("", &env); err != nil {
Expand All @@ -54,7 +56,7 @@ func Start(eventLogFactories map[string]EventLogFactory, eventGeneratorFactories
logging.FromContext(ctx).Infof("Events Hub environment configuration: %+v", env)

eventLogs := createEventLogs(ctx, eventLogFactories, env.EventLogs)
err := startEventGenerators(ctx, eventGeneratorFactories, env.EventGenerators, eventLogs)
err = startEventGenerators(ctx, eventGeneratorFactories, env.EventGenerators, eventLogs)

if err != nil {
logging.FromContext(ctx).Fatal("Error during start: ", err)
Expand Down
21 changes: 17 additions & 4 deletions vendor/knative.dev/reconciler-test/pkg/eventshub/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,32 @@ func ParseDurationStr(durationStr string, defaultDuration int) time.Duration {
}

// ConfigureTracing can be used in test-images to configure tracing
func ConfigureTracing(logger *zap.SugaredLogger, serviceName string) error {
func ConfigureTracing(logger *zap.SugaredLogger, serviceName string) (tracing.Tracer, error) {
tracingEnv := os.Getenv(ConfigTracingEnv)

var (
tracer tracing.Tracer
err error
)

if tracingEnv == "" {
return tracing.SetupStaticPublishing(logger, serviceName, config.NoopConfig())
tracer, err = tracing.SetupPublishingWithStaticConfig(logger, serviceName, config.NoopConfig())
if err != nil {
return tracer, err
}
}

conf, err := config.JSONToTracingConfig(tracingEnv)
if err != nil {
return err
return tracer, err
}

tracer, err = tracing.SetupPublishingWithStaticConfig(logger, serviceName, conf)
if err != nil {
return tracer, err
}

return tracing.SetupStaticPublishing(logger, serviceName, conf)
return tracer, nil
}

// ConfigureTracing can be used in test-images to configure tracing
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ knative.dev/pkg/webhook/json
knative.dev/pkg/webhook/resourcesemantics
knative.dev/pkg/webhook/resourcesemantics/defaulting
knative.dev/pkg/webhook/resourcesemantics/validation
# knative.dev/reconciler-test v0.0.0-20220818122349-177f8264c28c
# knative.dev/reconciler-test v0.0.0-20220901014218-ff8756131bd5
## explicit; go 1.18
knative.dev/reconciler-test/cmd/eventshub
knative.dev/reconciler-test/pkg/environment
Expand Down

0 comments on commit a8858e4

Please sign in to comment.