Skip to content

Find, verify, and analyze leaked credentials

Add SourceName to JobProgressRef (#1664)

Miccah61977412dfcf
diff --git a/pkg/sources/job_progress.go b/pkg/sources/job_progress.go
index 6e2ede20e..73ce6cd27 100644
--- a/pkg/sources/job_progress.go
+++ b/pkg/sources/job_progress.go
@@ -41,8 +41,9 @@ type JobProgressHook interface {
// JobProgressRef is a wrapper of a JobProgress for read-only access to its state.
type JobProgressRef struct {
- SourceID int64
JobID int64
+ SourceID int64
+ SourceName string
jobProgress *JobProgress
}
@@ -88,8 +89,9 @@ func (f ChunkError) Unwrap() error { return f.err }
// JobProgress aggregates information about a run of a Source.
type JobProgress struct {
// Unique identifiers for this job.
- SourceID int64
- JobID int64
+ JobID int64
+ SourceID int64
+ SourceName string
// Tracks whether the job is finished or not.
ctx context.Context
cancel context.CancelFunc
@@ -134,13 +136,14 @@ func WithHooks(hooks ...JobProgressHook) func(*JobProgress) {
}
// NewJobProgress creates a new job report for the given source and job ID.
-func NewJobProgress(sourceID, jobID int64, opts ...func(*JobProgress)) *JobProgress {
+func NewJobProgress(jobID, sourceID int64, sourceName string, opts ...func(*JobProgress)) *JobProgress {
ctx, cancel := context.WithCancel(context.Background())
jp := &JobProgress{
- SourceID: sourceID,
- JobID: jobID,
- ctx: ctx,
- cancel: cancel,
+ JobID: jobID,
+ SourceID: sourceID,
+ SourceName: sourceName,
+ ctx: ctx,
+ cancel: cancel,
}
for _, opt := range opts {
opt(jp)
@@ -260,6 +263,7 @@ func (jp *JobProgress) Ref() JobProgressRef {
return JobProgressRef{
SourceID: jp.SourceID,
JobID: jp.JobID,
+ SourceName: jp.SourceName,
jobProgress: jp,
}
}
diff --git a/pkg/sources/job_progress_test.go b/pkg/sources/job_progress_test.go
index cbabaa96c..5dbc0e743 100644
--- a/pkg/sources/job_progress_test.go
+++ b/pkg/sources/job_progress_test.go
@@ -36,10 +36,10 @@ func TestJobProgressFatalErrors(t *testing.T) {
}
func TestJobProgressRef(t *testing.T) {
- jp := NewJobProgress(123, 456)
+ jp := NewJobProgress(123, 456, "source name")
ref := jp.Ref()
- assert.Equal(t, int64(123), ref.SourceID)
- assert.Equal(t, int64(456), ref.JobID)
+ assert.Equal(t, int64(123), ref.JobID)
+ assert.Equal(t, int64(456), ref.SourceID)
// Test Done() blocks until Finish() is called.
select {
@@ -61,7 +61,7 @@ func TestJobProgressHook(t *testing.T) {
defer ctrl.Finish()
hook := NewMockJobProgressHook(ctrl)
- jp := NewJobProgress(123, 456, WithHooks(hook))
+ jp := NewJobProgress(123, 456, "source name", WithHooks(hook))
// Start(JobProgressRef, time.Time)
// End(JobProgressRef, time.Time)
diff --git a/pkg/sources/source_manager.go b/pkg/sources/source_manager.go
index edc47b761..b274c8cf2 100644
--- a/pkg/sources/source_manager.go
+++ b/pkg/sources/source_manager.go
@@ -151,14 +151,20 @@ func (s *SourceManager) asyncRun(ctx context.Context, handle handle) (JobProgres
if err := s.preflightChecks(ctx, handle); err != nil {
return JobProgressRef{}, err
}
+ // Get the name. Should never fail due to preflight checks.
+ sourceInfo, ok := s.getSourceInfo(handle)
+ if !ok {
+ return JobProgressRef{SourceID: int64(handle)}, fmt.Errorf("unrecognized handle")
+ }
+ sourceName := sourceInfo.name
// Get a Job ID.
ctx = context.WithValue(ctx, "source_id", int64(handle))
jobID, err := s.api.GetJobID(ctx, int64(handle))
if err != nil {
- return JobProgressRef{SourceID: int64(handle)}, err
+ return JobProgressRef{SourceID: int64(handle), SourceName: sourceName}, err
}
// Create a JobProgress object for tracking progress.
- progress := NewJobProgress(int64(handle), jobID, WithHooks(s.hooks...))
+ progress := NewJobProgress(jobID, int64(handle), sourceName, WithHooks(s.hooks...))
s.pool.Go(func() error {
ctx := context.WithValues(ctx,
"job_id", jobID,
diff --git a/pkg/sources/source_manager_test.go b/pkg/sources/source_manager_test.go
index 4d66dbc7c..0e5787619 100644
--- a/pkg/sources/source_manager_test.go
+++ b/pkg/sources/source_manager_test.go
@@ -280,7 +280,10 @@ func TestSourceManagerJobAndSourceIDs(t *testing.T) {
})
assert.NoError(t, err)
- _, _ = mgr.Run(context.Background(), handle)
+ ref, _ := mgr.Run(context.Background(), handle)
assert.Equal(t, int64(1337), initializedSourceID)
+ assert.Equal(t, int64(1337), ref.SourceID)
assert.Equal(t, int64(9001), initializedJobID)
+ assert.Equal(t, int64(9001), ref.JobID)
+ assert.Equal(t, "dummy", ref.SourceName)
}