Skip to content

Commit

Permalink
chore: Run attestors in parallel per type.
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Glastra <[email protected]>
  • Loading branch information
matglas committed May 20, 2024
1 parent 5e04111 commit d6e84d4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions attestation/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"crypto"
"fmt"
"os"
"sync"
"time"

"github.com/in-toto/go-witness/cryptoutil"
Expand Down Expand Up @@ -149,17 +150,28 @@ func (ctx *AttestationContext) RunAttestors() error {
}

for _, k := range order {
log.Debugf("Starting %s attestors...", k.String())
log.Infof("Starting %s attestors stage...", k.String())

var wg sync.WaitGroup
ch := make(chan int, len(attestors))

for _, att := range attestors[k] {
log.Infof("Starting %v attestor...", att.Name())
ctx.runAttestor(att)
wg.Add(1)
go func(att Attestor) {
defer func() { wg.Done(); <-ch }()
ctx.runAttestor(att)
}(att)
}
wg.Wait()
log.Infof("Completed %s attestors stage...", k.String())
}

return nil
}

func (ctx *AttestationContext) runAttestor(attestor Attestor) {
log.Infof("Starting %v attestor...", attestor.Name())

startTime := time.Now()
if err := attestor.Attest(ctx); err != nil {
ctx.completedAttestors = append(ctx.completedAttestors, CompletedAttestor{
Expand All @@ -183,6 +195,8 @@ func (ctx *AttestationContext) runAttestor(attestor Attestor) {
if producer, ok := attestor.(Producer); ok {
ctx.addProducts(producer)
}

log.Infof("Finished %v attestor... (%vs)", attestor.Name(), time.Since(startTime).Seconds())
}

func (ctx *AttestationContext) CompletedAttestors() []CompletedAttestor {
Expand Down

0 comments on commit d6e84d4

Please sign in to comment.