Skip to content

Commit

Permalink
[release-1.7] Properly export trace for duplicated "finished" event (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
knative-prow-robot and mgencur authored Sep 26, 2022
1 parent 9967e86 commit 0bf545a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
19 changes: 14 additions & 5 deletions test/upgrade/prober/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"regexp"
"strings"
"time"

"go.uber.org/zap"
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions test/upgrade/prober/wathola/event/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0bf545a

Please sign in to comment.