From a2b2932e9f660a076e12a3a7e4d0e0b6c1ad9c1e Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Thu, 20 Aug 2020 12:29:31 -0700 Subject: [PATCH 1/2] do not use resp if it fails, use 0 instead --- pkg/mtbroker/filter/filter_handler.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/mtbroker/filter/filter_handler.go b/pkg/mtbroker/filter/filter_handler.go index 80b49f7b5da..292827e6335 100644 --- a/pkg/mtbroker/filter/filter_handler.go +++ b/pkg/mtbroker/filter/filter_handler.go @@ -255,7 +255,14 @@ func (h *Handler) sendEvent(ctx context.Context, headers http.Header, target str err = fmt.Errorf("failed to dispatch message: %w", err) } - _ = h.reporter.ReportEventDispatchTime(reporterArgs, resp.StatusCode, dispatchTime) + var sc int + if resp == nil { + sc = 0 + } else { + sc = resp.StatusCode + } + + _ = h.reporter.ReportEventDispatchTime(reporterArgs, sc, dispatchTime) return resp, err } From 1fc1c0bc7c6b014904a6348cc5e4b153afff4b5e Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Thu, 20 Aug 2020 12:33:14 -0700 Subject: [PATCH 2/2] simplify --- pkg/mtbroker/filter/filter_handler.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/mtbroker/filter/filter_handler.go b/pkg/mtbroker/filter/filter_handler.go index 292827e6335..a9c3d28ca68 100644 --- a/pkg/mtbroker/filter/filter_handler.go +++ b/pkg/mtbroker/filter/filter_handler.go @@ -255,10 +255,8 @@ func (h *Handler) sendEvent(ctx context.Context, headers http.Header, target str err = fmt.Errorf("failed to dispatch message: %w", err) } - var sc int - if resp == nil { - sc = 0 - } else { + sc := 0 + if resp != nil { sc = resp.StatusCode }