Skip to content

Commit

Permalink
Include the job ID in a chunk (#1652)
Browse files Browse the repository at this point in the history
* Include the job ID in a source's chunk.

* address comments.

* address comments.
  • Loading branch information
ahrav authored Aug 22, 2023
1 parent fd00d2b commit 9ae7230
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/sources/source_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"sync/atomic"
"time"

"golang.org/x/sync/errgroup"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
"golang.org/x/sync/errgroup"
)

// handle uniquely identifies a Source given to the manager to manage. If the
Expand Down Expand Up @@ -255,6 +256,7 @@ func (s *SourceManager) runWithoutUnits(ctx context.Context, handle handle, sour
go func() {
defer wg.Done()
for chunk := range ch {
chunk.JobID = source.JobID()
report.ReportChunk(nil, chunk)
s.outputChunks <- chunk
}
Expand Down Expand Up @@ -334,6 +336,9 @@ func (s *SourceManager) runWithUnits(ctx context.Context, handle handle, source
defer wg.Done()
defer func() { report.EndUnitChunking(unit, time.Now()) }()
for chunk := range chunkReporter.chunkCh {
if src, ok := source.(Source); ok {
chunk.JobID = src.JobID()
}
s.outputChunks <- chunk
}
}()
Expand Down
2 changes: 2 additions & 0 deletions pkg/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Chunk struct {
SourceName string
// SourceID is the ID of the source that the Chunk originated from.
SourceID int64
// JobID is the ID of the job that the Chunk originated from.
JobID int64
// SourceType is the type of Source that produced the chunk.
SourceType sourcespb.SourceType
// SourceMetadata holds the context of where the Chunk was found.
Expand Down

0 comments on commit 9ae7230

Please sign in to comment.