-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IMC and Multi-Tenant Channel Based Broker retries #2932
Merged
knative-prow-robot
merged 10 commits into
knative:master
from
pierDipi:broker-redelivery
Jul 21, 2020
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
82ff7bc
IMC and Multi-Tenant Channel Based Broker retries
pierDipi 2110286
Do not create a unnecessarily a default pooled client
pierDipi 0a0eaf2
No retries by default
pierDipi 59af194
Use DispatchMessage directly
pierDipi fcc3b60
Remove redundant check
pierDipi 3c7679e
Put NoRetries in a var
pierDipi e029985
Create a new struct with SubscriberSpec and RetriesConfig
pierDipi 5a73e1c
Add DispatchMessageWithRetries to MessageDispatcher interface
pierDipi 3a43578
Rename to RetryConfig
pierDipi 030c6c6
Add UT for delivery spec
pierDipi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,9 @@ package fanout | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
nethttp "net/http" | ||
"net/url" | ||
"time" | ||
|
@@ -33,17 +35,32 @@ import ( | |
"go.opencensus.io/trace" | ||
"go.uber.org/zap" | ||
|
||
eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1" | ||
eventingduck "knative.dev/eventing/pkg/apis/duck/v1beta1" | ||
"knative.dev/eventing/pkg/channel" | ||
"knative.dev/eventing/pkg/kncloudevents" | ||
) | ||
|
||
const ( | ||
defaultTimeout = 15 * time.Minute | ||
) | ||
|
||
type Subscription struct { | ||
eventingduck.SubscriberSpec | ||
RetriesConfig kncloudevents.RetryConfig | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: RetriesConfig => RetryConfig? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
func (s *Subscription) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(s.SubscriberSpec) | ||
} | ||
|
||
func (s *Subscription) UnmarshalJSON(bytes []byte) error { | ||
return json.Unmarshal(bytes, &s.SubscriberSpec) | ||
} | ||
|
||
// Config for a fanout.MessageHandler. | ||
type Config struct { | ||
Subscriptions []eventingduck.SubscriberSpec `json:"subscriptions"` | ||
Subscriptions []Subscription `json:"subscriptions"` | ||
// AsyncHandler controls whether the Subscriptions are called synchronous or asynchronously. | ||
// It is expected to be false when used as a sidecar. | ||
AsyncHandler bool `json:"asyncHandler,omitempty"` | ||
|
@@ -78,9 +95,26 @@ func NewMessageHandler(logger *zap.Logger, messageDispatcher channel.MessageDisp | |
return nil, err | ||
} | ||
handler.receiver = receiver | ||
|
||
for i := range config.Subscriptions { | ||
retriesConfig, err := retriesOf(config.Subscriptions[i].SubscriberSpec) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create retries config from SubscriberSpec: %w", err) | ||
} | ||
config.Subscriptions[i].RetriesConfig = retriesConfig | ||
} | ||
|
||
return handler, nil | ||
} | ||
|
||
func retriesOf(spec eventingduck.SubscriberSpec) (kncloudevents.RetryConfig, error) { | ||
delivery := &eventingduckv1.DeliverySpec{} | ||
|
||
_ = spec.ConvertTo(context.Background(), delivery) | ||
|
||
return kncloudevents.RetryConfigFromDeliverySpec(*delivery) | ||
} | ||
|
||
func createMessageReceiverFunction(f *MessageHandler) func(context.Context, channel.ChannelReference, binding.Message, []binding.Transformer, nethttp.Header) error { | ||
if f.config.AsyncHandler { | ||
return func(ctx context.Context, _ channel.ChannelReference, message binding.Message, transformers []binding.Transformer, additionalHeaders nethttp.Header) error { | ||
|
@@ -140,7 +174,7 @@ func (f *MessageHandler) dispatch(ctx context.Context, bufferedMessage binding.M | |
|
||
errorCh := make(chan error, subs) | ||
for _, sub := range f.config.Subscriptions { | ||
go func(s eventingduck.SubscriberSpec) { | ||
go func(s Subscription) { | ||
errorCh <- f.makeFanoutRequest(ctx, bufferedMessage, additionalHeaders, s) | ||
}(sub) | ||
} | ||
|
@@ -163,18 +197,22 @@ func (f *MessageHandler) dispatch(ctx context.Context, bufferedMessage binding.M | |
|
||
// makeFanoutRequest sends the request to exactly one subscription. It handles both the `call` and | ||
// the `sink` portions of the subscription. | ||
func (f *MessageHandler) makeFanoutRequest(ctx context.Context, message binding.Message, additionalHeaders nethttp.Header, sub eventingduck.SubscriberSpec) error { | ||
func (f *MessageHandler) makeFanoutRequest(ctx context.Context, message binding.Message, additionalHeaders nethttp.Header, sub Subscription) error { | ||
|
||
var destination *url.URL | ||
if sub.SubscriberURI != nil { | ||
destination = sub.SubscriberURI.URL() | ||
} | ||
|
||
var reply *url.URL | ||
if sub.ReplyURI != nil { | ||
reply = sub.ReplyURI.URL() | ||
} | ||
var deadLetter *url.URL | ||
|
||
var deadLetterURL *url.URL | ||
if sub.Delivery != nil && sub.Delivery.DeadLetterSink != nil && sub.Delivery.DeadLetterSink.URI != nil { | ||
deadLetter = sub.Delivery.DeadLetterSink.URI.URL() | ||
deadLetterURL = sub.Delivery.DeadLetterSink.URI.URL() | ||
} | ||
return f.dispatcher.DispatchMessage(ctx, message, additionalHeaders, destination, reply, deadLetter) | ||
|
||
return f.dispatcher.DispatchMessageWithRetries(ctx, message, additionalHeaders, destination, reply, deadLetterURL, &sub.RetriesConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not your doing, but 15 minute timeout? :) I'll look what this is for. Just a note :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems too much :)
It's used here:
eventing/pkg/channel/fanout/fanout_message_handler.go
Lines 175 to 193 in d5ea26f