Skip to content
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

Expose dispatch result to be used by other implementations #5481

Merged
merged 4 commits into from
Jun 8, 2021
Merged
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
27 changes: 21 additions & 6 deletions pkg/channel/fanout/fanout_message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (f *FanoutMessageHandler) ServeHTTP(response nethttp.ResponseWriter, reques
}

// ParseDispatchResultAndReportMetric processes the dispatch result and records the related channel metrics with the appropriate context
func ParseDispatchResultAndReportMetrics(result dispatchResult, reporter channel.StatsReporter, reportArgs channel.ReportArgs) error {
func ParseDispatchResultAndReportMetrics(result DispatchResult, reporter channel.StatsReporter, reportArgs channel.ReportArgs) error {
if result.info != nil && result.info.Time > channel.NoDuration {
if result.info.ResponseCode > channel.NoResponse {
_ = reporter.ReportEventDispatchTime(&reportArgs, result.info.ResponseCode, result.info.Time)
Expand All @@ -245,20 +245,20 @@ func ParseDispatchResultAndReportMetrics(result dispatchResult, reporter channel

// dispatch takes the event, fans it out to each subscription in subs. If all the fanned out
// events return successfully, then return nil. Else, return an error.
func (f *FanoutMessageHandler) dispatch(ctx context.Context, subs []Subscription, bufferedMessage binding.Message, additionalHeaders nethttp.Header) dispatchResult {
func (f *FanoutMessageHandler) dispatch(ctx context.Context, subs []Subscription, bufferedMessage binding.Message, additionalHeaders nethttp.Header) DispatchResult {
// Bind the lifecycle of the buffered message to the number of subs
bufferedMessage = buffering.WithAcksBeforeFinish(bufferedMessage, len(subs))

errorCh := make(chan dispatchResult, len(subs))
errorCh := make(chan DispatchResult, len(subs))
for _, sub := range subs {
go func(s Subscription) {
dispatchedResultPerSub, err := f.makeFanoutRequest(ctx, bufferedMessage, additionalHeaders, s)
errorCh <- dispatchResult{err: err, info: dispatchedResultPerSub}
errorCh <- DispatchResult{err: err, info: dispatchedResultPerSub}
}(sub)
}

var totalDispatchTimeForFanout time.Duration = channel.NoDuration
dispatchResultForFanout := dispatchResult{
dispatchResultForFanout := DispatchResult{
info: &channel.DispatchExecutionInfo{
Time: channel.NoDuration,
ResponseCode: channel.NoResponse,
Expand Down Expand Up @@ -307,7 +307,22 @@ func (f *FanoutMessageHandler) makeFanoutRequest(ctx context.Context, message bi
)
}

type dispatchResult struct {
type DispatchResult struct {
err error
info *channel.DispatchExecutionInfo
}

func (d DispatchResult) Error() error {
return d.err
}

func (d DispatchResult) Info() *channel.DispatchExecutionInfo {
return d.info
}

func NewDispatchResult(err error, info *channel.DispatchExecutionInfo) DispatchResult {
return DispatchResult{
err: err,
info: info,
}
}