From 0bf545aacef303f469951ccdf537eb11e21cd594 Mon Sep 17 00:00:00 2001 From: Knative Prow Robot Date: Mon, 26 Sep 2022 09:57:58 +0100 Subject: [PATCH] [release-1.7] Properly export trace for duplicated "finished" event (#6540) * Properly export trace for duplicated "finished" event Fixes an issue with duplicated finished event in which case the following error was thrown: knative.dev/eventing/test/upgrade/prober.(*prober).getStepNoFromMsg ... panic: runtime error: index out of range [1] with length 0 * Define FinishedEventPrefix and reuse it Co-authored-by: Martin Gencur --- test/upgrade/prober/verify.go | 19 ++++++++++++++----- test/upgrade/prober/wathola/event/services.go | 8 ++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/test/upgrade/prober/verify.go b/test/upgrade/prober/verify.go index 7e6db65dea5..9cdb3d36f0e 100644 --- a/test/upgrade/prober/verify.go +++ b/test/upgrade/prober/verify.go @@ -23,6 +23,7 @@ import ( "os" "path/filepath" "regexp" + "strings" "time" "go.uber.org/zap" @@ -101,7 +102,11 @@ func (p *prober) Verify() (eventErrs []error, eventsSent int) { } else if p.config.OnDuplicate == Error { eventErrs = append(eventErrs, errors.New(t)) } - p.exportStepEventTrace(i, t) + if strings.HasPrefix(t, event.FinishedEventPrefix) { + p.exportFinishedEventTrace() + } else { + p.exportStepEventTrace(i, t) + } } return eventErrs, report.EventsSent } @@ -117,19 +122,23 @@ func (p *prober) exportStepEventTrace(i int, msg string) { if i > exportTraceLimit { return } - stepNo := p.getStepNoFromMsg(msg) + stepNo, err := p.getStepNoFromMsg(msg) + if err != nil { + p.log.Warnf("Unable to get step number: %v", err) + return + } if err := p.exportTrace(p.getTraceForStepEvent(stepNo), fmt.Sprintf("step-%s.json", stepNo)); err != nil { p.log.Warnf("Failed to export trace for Step event #%s: %v", stepNo, err) } } -func (p *prober) getStepNoFromMsg(message string) string { +func (p *prober) getStepNoFromMsg(message string) (string, error) { r, _ := regexp.Compile(stepEventMsgPattern) matches := r.FindStringSubmatch(message) if len(matches) != 2 { - p.log.Warnf("message does not match pattern %s: %s", stepEventMsgPattern, message) + return "", fmt.Errorf("message does not match pattern %s: %s", stepEventMsgPattern, message) } - return matches[1] + return matches[1], nil } func (p *prober) getTraceForStepEvent(eventNo string) []byte { diff --git a/test/upgrade/prober/wathola/event/services.go b/test/upgrade/prober/wathola/event/services.go index 849109c4358..c5717810af6 100644 --- a/test/upgrade/prober/wathola/event/services.go +++ b/test/upgrade/prober/wathola/event/services.go @@ -23,6 +23,8 @@ import ( "knative.dev/eventing/test/upgrade/prober/wathola/config" ) +const FinishedEventPrefix = "finish event" + var mutex = sync.RWMutex{} var lastProgressReport = time.Now() @@ -93,8 +95,10 @@ func (s *stepStore) Count() int { func (f *finishedStore) RegisterFinished(finished *Finished) { if f.received > 0 { f.errors.throwDuplicated( - "finish event should be received only once, received %d", - f.received+1) + "%s should be received only once, received %d", + FinishedEventPrefix, f.received+1) + // We don't want to record all failures again. + return } f.received++ f.eventsSent = finished.EventsSent