Skip to content

Commit

Permalink
Trigger dls resolving e2e (#5841)
Browse files Browse the repository at this point in the history
* added basic template for trigger dlq tests + removed duplicated import

* added file for trigger sink related tests

* modified DLQ for DLS for proper use of terminology + added test where the trigger DLS is use instead of its corresponding broker one

* added test cases for triggers dls

* changed tab for spaces on comments

* fixed descriptions on tests

* added part where test makes sure no events are been sent to brokers DLS

* added test for broker nil uri in triggers broker DLS resolving fallback

* fixed comment

* fixed pr comments

* changed copyright year for new trigger test rekt e2e file

* fixing typo

* fixing pr comments

* fixed incorect test setup description

* added functions necesary for build brokers with dls as precondition + changed broker and trigger tests structure for them to use the needed preconditions

* fixed name of aux test function

* Update test/rekt/features/trigger/trigger_sink_resolution.go

Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>

* Update test/rekt/features/trigger/trigger_sink_resolution.go

Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>

Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
  • Loading branch information
gabo1208 and pierDipi authored Nov 9, 2021
1 parent aef6803 commit 31e4e2e
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pkg/reconciler/broker/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (r *Reconciler) resolveDeadLetterSink(ctx context.Context, b *eventingv1.Br
return fmt.Errorf("broker %s didn't set status.deadLetterSinkURI", b.Name)
}
} else {
// There is no DLS defined in nither Trigger nor the Broker
// There is no DLS defined in neither Trigger nor the Broker
t.Status.DeadLetterSinkURI = nil
t.Status.MarkDeadLetterSinkNotConfigured()
}
Expand Down
43 changes: 43 additions & 0 deletions pkg/reconciler/broker/trigger/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,49 @@ func TestReconcile(t *testing.T) {
WithTriggerDeadLetterSinkResolvedSucceeded(),
),
}},
}, {
Name: "Trigger does not have DLS defined, Broker DLS URI resolved to nil, Trigger returns error status",
Key: testKey,
Objects: []runtime.Object{
makeSubscriberKubernetesServiceAsUnstructured(),
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerConfig(config()),
WithInitBrokerConditions,
WithBrokerReady,
WithBrokerResourceVersion(""),
WithChannelAddressAnnotation(triggerChannelURL),
WithChannelAPIVersionAnnotation(triggerChannelAPIVersion),
WithChannelKindAnnotation(triggerChannelKind),
WithChannelNameAnnotation(triggerChannelName),
WithDeadLeaderSink(k8sSVCDest.Ref, ""),
WithBrokerStatusDLSURI(nil),
),
createChannel(testNS, true),
imcConfigMap(),
makeReadySubscription(testNS),
NewTrigger(triggerName, testNS, brokerName,
WithTriggerUID(triggerUID),
WithTriggerSubscriberURI(subscriberURI),
WithInitTriggerConditions),
},
WantErr: true,
WantEvents: []string{
Eventf(corev1.EventTypeWarning, "InternalError", `broker test-broker didn't set status.deadLetterSinkURI`),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewTrigger(triggerName, testNS, brokerName,
WithTriggerUID(triggerUID),
WithTriggerSubscriberURI(subscriberURI),
WithTriggerBrokerReady(),
// The first reconciliation will initialize the status conditions.
WithInitTriggerConditions,
WithTriggerSubscribedUnknown("", ""),
WithTriggerStatusSubscriberURI(subscriberURI),
WithTriggerSubscriberResolvedSucceeded(),
WithTriggerDeadLetterSinkResolvedFailed("Broker test-broker didn't set status.deadLetterSinkURI", ""),
),
}},
}, {
Name: "Subscription not ready, trigger marked not ready",
Key: testKey,
Expand Down
20 changes: 17 additions & 3 deletions test/rekt/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"knative.dev/eventing/pkg/apis/eventing"
"knative.dev/eventing/test/rekt/features/broker"
b "knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/reconciler-test/pkg/eventshub"
)

// TestBrokerAsMiddleware
Expand Down Expand Up @@ -69,15 +70,28 @@ func TestBrokerWithDLQ(t *testing.T) {
// source ---> broker<Via> --[trigger]--> bad uri
// |
// +--[DLQ]--> sink
env.Test(ctx, t, broker.SourceToSinkWithDLQ("test1"))
// Setup data plane

// Test that a Broker "test1" works as expected with the following topology:
// Install probes.
prober := eventshub.NewProber()
brokerName := "normal-broker"
sink1 := "sink"

// Wait till broker is ready since we need it to run the test
env.Prerequisite(ctx, t, broker.GoesReadyWithProbeReceiver(brokerName, sink1, prober, b.WithEnvConfig()...))
env.Test(ctx, t, broker.SourceToSinkWithDLQ(brokerName, sink1, prober))

// Test that a Broker "test2" works as expected with the following topology:
// source ---> broker +--[trigger<via1>]--> bad uri
// | |
// | +--[trigger<vai2>]--> sink2
// |
// +--[DLQ]--> sink1
env.Test(ctx, t, broker.SourceToTwoSinksWithDLQ("test2"))
// Wait till broker is ready since we need it to run this test
brokerName = "dls-broker"
sink2 := "sink2"
env.Prerequisite(ctx, t, broker.GoesReadyWithProbeReceiver(brokerName, sink1, prober, b.WithEnvConfig()...))
env.Test(ctx, t, broker.SourceToTwoSinksWithDLQ(brokerName, sink1, sink2, prober))
}

// TestBrokerWithFlakyDLQ
Expand Down
21 changes: 21 additions & 0 deletions test/rekt/features/broker/readyness.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ package broker
import (
"fmt"

"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/manifest"

"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/delivery"
"knative.dev/eventing/test/rekt/resources/trigger"
"knative.dev/reconciler-test/resources/svc"
)
Expand Down Expand Up @@ -64,3 +66,22 @@ func GoesReady(name string, cfg ...manifest.CfgFn) *feature.Feature {

return f
}

// GoesReady returns a feature that will create a Broker of the given
// name and class, with an event receiver as its DLS
// and confirm it becomes ready with an address.
func GoesReadyWithProbeReceiver(name, sinkName string, prober *eventshub.EventProber, cfg ...manifest.CfgFn) *feature.Feature {
f := new(feature.Feature)

f.Setup("install probe", prober.ReceiverInstall(sinkName))

brokerConfig := append(cfg, delivery.WithDeadLetterSink(prober.AsKReference(sinkName), ""))
f.Setup(fmt.Sprintf("install broker %q", name), broker.Install(name, brokerConfig...))

f.Requirement("Broker is ready", broker.IsReady(name))

f.Stable("broker").
Must("be addressable", broker.IsAddressable(name))

return f
}
34 changes: 9 additions & 25 deletions test/rekt/features/broker/source_to_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/google/uuid"
"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/delivery"
"knative.dev/eventing/test/rekt/resources/eventlibrary"
"knative.dev/eventing/test/rekt/resources/flaker"
"knative.dev/eventing/test/rekt/resources/trigger"
Expand All @@ -32,8 +31,6 @@ import (
"knative.dev/reconciler-test/pkg/manifest"
"knative.dev/reconciler-test/resources/svc"

b "knative.dev/eventing/test/rekt/resources/broker"

. "github.com/cloudevents/sdk-go/v2/test"
. "knative.dev/reconciler-test/pkg/eventshub/assert"
)
Expand Down Expand Up @@ -79,8 +76,7 @@ func SourceToSink(brokerName string) *feature.Feature {
// |
// +--[DLQ]--> sink
//
func SourceToSinkWithDLQ(brokerName string) *feature.Feature {
prober := eventshub.NewProber()
func SourceToSinkWithDLQ(brokerName, sinkName string, prober *eventshub.EventProber) *feature.Feature {
prober.SetTargetResource(broker.GVR(), brokerName)

via := feature.MakeRandomK8sName("via")
Expand All @@ -95,15 +91,6 @@ func SourceToSinkWithDLQ(brokerName string) *feature.Feature {
panic(fmt.Errorf("can not find event files: %s", err))
}

// Setup Probes
f.Setup("install recorder", prober.ReceiverInstall("sink"))

// Setup data plane
brokerConfig := append(b.WithEnvConfig(), delivery.WithDeadLetterSink(prober.AsKReference("sink"), ""))
f.Setup("update broker with DLQ", broker.Install(
brokerName,
brokerConfig...,
))
f.Setup("install trigger", trigger.Install(via, brokerName, trigger.WithSubscriber(nil, "bad://uri")))

// Resources ready.
Expand All @@ -118,7 +105,7 @@ func SourceToSinkWithDLQ(brokerName string) *feature.Feature {
// Assert events ended up where we expected.
f.Stable("broker with DLQ").
Must("accepted all events", prober.AssertSentAll("source")).
Must("deliver event to DLQ", prober.AssertReceivedAll("source", "sink"))
Must("deliver event to DLQ", prober.AssertReceivedAll("source", sinkName))

return f
}
Expand All @@ -131,8 +118,7 @@ func SourceToSinkWithDLQ(brokerName string) *feature.Feature {
// |
// +--[DLQ]--> sink1
//
func SourceToTwoSinksWithDLQ(brokerName string) *feature.Feature {
prober := eventshub.NewProber()
func SourceToTwoSinksWithDLQ(brokerName, sink1, sink2 string, prober *eventshub.EventProber) *feature.Feature {
prober.SetTargetResource(broker.GVR(), brokerName)

via1 := feature.MakeRandomK8sName("via")
Expand All @@ -149,13 +135,11 @@ func SourceToTwoSinksWithDLQ(brokerName string) *feature.Feature {
}

// Setup Probes
f.Setup("install recorder1", prober.ReceiverInstall("sink1"))
f.Setup("install recorder2", prober.ReceiverInstall("sink2"))
f.Setup("install recorder2", prober.ReceiverInstall(sink2))

// Setup data plane
f.Setup("update broker with DLQ", broker.Install(brokerName, delivery.WithDeadLetterSink(prober.AsKReference("sink1"), "")))
f.Setup("install trigger via1", trigger.Install(via1, brokerName, trigger.WithSubscriber(nil, "bad://uri")))
f.Setup("install trigger via2", trigger.Install(via2, brokerName, trigger.WithSubscriber(prober.AsKReference("sink2"), "")))
f.Setup("install trigger via2", trigger.Install(via2, brokerName, trigger.WithSubscriber(prober.AsKReference(sink2), "")))

// Resources ready.
f.Setup("trigger1 goes ready", trigger.IsReady(via1))
Expand All @@ -166,14 +150,14 @@ func SourceToTwoSinksWithDLQ(brokerName string) *feature.Feature {

// After we have finished sending.
f.Requirement("sender is finished", prober.SenderDone("source"))
f.Requirement("receiver 1 is finished", prober.ReceiverDone("source", "sink1"))
f.Requirement("receiver 2 is finished", prober.ReceiverDone("source", "sink2"))
f.Requirement("receiver 1 is finished", prober.ReceiverDone("source", sink1))
f.Requirement("receiver 2 is finished", prober.ReceiverDone("source", sink2))

// Assert events ended up where we expected.
f.Stable("broker with DLQ").
Must("accepted all events", prober.AssertSentAll("source")).
Must("deliver event to DLQ (via1)", prober.AssertReceivedAll("source", "sink1")).
Must("deliver event to sink (via2)", prober.AssertReceivedAll("source", "sink2"))
Must("deliver event to DLQ (via1)", prober.AssertReceivedAll("source", sink1)).
Must("deliver event to sink (via2)", prober.AssertReceivedAll("source", sink2))

return f
}
Expand Down
143 changes: 143 additions & 0 deletions test/rekt/features/trigger/trigger_sink_resolution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
Copyright 2021 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 trigger

import (
"context"
"fmt"

"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/delivery"
"knative.dev/eventing/test/rekt/resources/eventlibrary"
"knative.dev/eventing/test/rekt/resources/trigger"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/feature"
)

// SourceToTriggerSinkWithDLS tests to see if a Ready Trigger with a DLS defined send
// failing events to it's DLS.
//
// source ---> broker --[trigger]--> bad uri
// |
// +--[DLS]--> sink
//
func SourceToTriggerSinkWithDLS(triggerName, brokerName string, prober *eventshub.EventProber) *feature.Feature {
prober.SetTargetResource(broker.GVR(), brokerName)
f := feature.NewFeature()

lib := feature.MakeRandomK8sName("lib")
f.Setup("install events", eventlibrary.Install(lib))
f.Setup("event cache is ready", eventlibrary.IsReady(lib))
f.Setup("use events cache", prober.SenderEventsFromSVC(lib, "events/three.ce"))
if err := prober.ExpectYAMLEvents(eventlibrary.PathFor("events/three.ce")); err != nil {
panic(fmt.Errorf("can not find event files: %s", err))
}

// Setup Probes
f.Setup("install recorder", prober.ReceiverInstall("sink"))

// Setup trigger
f.Setup("install trigger", trigger.Install(
triggerName,
brokerName,
trigger.WithSubscriber(nil, "bad://uri"),
delivery.WithDeadLetterSink(prober.AsKReference("sink"), "")))

// Resources ready.
f.Setup("trigger goes ready", trigger.IsReady(triggerName))

// Install sender.
f.Setup("install source", prober.SenderInstall("source"))

// After we have finished sending.
f.Requirement("sender is finished", prober.SenderDone("source"))

// Assert events ended up where we expected.
f.Stable("trigger with DLS").
Must("accepted all events", prober.AssertSentAll("source")).
Must("deliver event to DLS", prober.AssertReceivedAll("source", "sink"))

return f
}

// SourceToTriggerSinkWithDLSDontUseBrokers tests to see if a Ready Trigger sends
// failing events to it's DLS even when it's corresponding Ready Broker also have a DLS defined.
//
// source ---> broker --[trigger]--> bad uri
// | |
// +--[DLS] +--[DLS]--> sink
//
func SourceToTriggerSinkWithDLSDontUseBrokers(triggerName, brokerName, brokerSinkName string, prober *eventshub.EventProber) *feature.Feature {
triggerSinkName := "trigger-sink"
prober.SetTargetResource(broker.GVR(), brokerName)

f := feature.NewFeature()

lib := feature.MakeRandomK8sName("lib")
f.Setup("install events", eventlibrary.Install(lib))
f.Setup("event cache is ready", eventlibrary.IsReady(lib))
f.Setup("use events cache", prober.SenderEventsFromSVC(lib, "events/three.ce"))
if err := prober.ExpectYAMLEvents(eventlibrary.PathFor("events/three.ce")); err != nil {
panic(fmt.Errorf("can not find event files: %s", err))
}

// Setup Probes
f.Setup("install trigger recorder", prober.ReceiverInstall(triggerSinkName))
f.Setup("install brokers recorder", prober.ReceiverInstall(brokerSinkName))

// Setup topology
brokerConfig := append(
broker.WithEnvConfig(),
delivery.WithDeadLetterSink(prober.AsKReference(brokerSinkName), ""))
f.Setup("install broker with DLS", broker.Install(
brokerName,
brokerConfig...,
))

f.Setup("install trigger", trigger.Install(
triggerName,
brokerName,
trigger.WithSubscriber(nil, "bad://uri"),
delivery.WithDeadLetterSink(prober.AsKReference(triggerSinkName), "")))

// Resources ready.
f.Setup("trigger goes ready", trigger.IsReady(triggerName))

// Install events after topology is ready.
f.Setup("install source", prober.SenderInstall("source"))

// After we have finished sending.
f.Requirement("sender is finished", prober.SenderDone("source"))

// Assert events ended up where we expected.
f.Stable("trigger with a valid DLS ref").
Must("accept all events", prober.AssertSentAll("source")).
Must("deliver events to trigger DLS", prober.AssertReceivedAll("source", triggerSinkName)).
Must("not deliver events to its broker DLS", noEventsToDLS(prober, brokerSinkName))

return f
}

func noEventsToDLS(prober *eventshub.EventProber, sinkName string) feature.StepFn {
return func(ctx context.Context, t feature.T) {
if len(prober.ReceivedBy(ctx, sinkName)) == 0 {
t.Log("no events were sent to %s DLS", sinkName)
} else {
t.Errorf("events were received by %s DLS", sinkName)
}
}
}
Loading

0 comments on commit 31e4e2e

Please sign in to comment.