From f55352fdff24df5d329777701df174499ede7e3a Mon Sep 17 00:00:00 2001 From: Matthias Glastra Date: Tue, 30 Apr 2024 18:10:08 +0200 Subject: [PATCH] chore: Parallel attestors per type. Signed-off-by: Matthias Glastra --- attestation/context.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/attestation/context.go b/attestation/context.go index bef8e7bc..33d0f88d 100644 --- a/attestation/context.go +++ b/attestation/context.go @@ -19,6 +19,7 @@ import ( "crypto" "fmt" "os" + "sync" "time" "github.com/in-toto/go-witness/cryptoutil" @@ -138,16 +139,27 @@ func (ctx *AttestationContext) RunAttestors() error { order := runTypeOrder() for _, k := range order { log.Debugf("Starting %s attestors...", 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...", 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{ @@ -171,6 +183,8 @@ func (ctx *AttestationContext) runAttestor(attestor Attestor) { if producer, ok := attestor.(Producer); ok { ctx.addProducts(producer) } + + log.Debugf("Finished %v attestor...", attestor.Name()) } func (ctx *AttestationContext) CompletedAttestors() []CompletedAttestor {