From 4502b4a47f544dd565ae74990ea866f16c80cf77 Mon Sep 17 00:00:00 2001 From: "docmerlin (j. Emrys Landivar)" Date: Thu, 27 Sep 2018 08:19:26 -0500 Subject: [PATCH] add requestedAt to task log --- task/backend/inmem_logreaderwriter.go | 11 +++++++++-- task/backend/meta.go | 5 +++-- task/backend/scheduler.go | 4 ++++ task/backend/store.go | 3 +++ task/backend/storetest/logstoretest.go | 5 +++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/task/backend/inmem_logreaderwriter.go b/task/backend/inmem_logreaderwriter.go index d373aa6a97..3bf52eec8d 100644 --- a/task/backend/inmem_logreaderwriter.go +++ b/task/backend/inmem_logreaderwriter.go @@ -41,7 +41,15 @@ func (r *runReaderWriter) UpdateRunState(ctx context.Context, rlb RunLogBase, wh if !ok { tid := append([]byte(nil), rlb.Task.ID...) sf := time.Unix(rlb.RunScheduledFor, 0).UTC() - run := &platform.Run{ID: rlb.RunID, TaskID: tid, Status: status.String(), ScheduledFor: sf.Format(time.RFC3339)} + run := &platform.Run{ + ID: rlb.RunID, + TaskID: tid, + Status: status.String(), + ScheduledFor: sf.Format(time.RFC3339), + } + if rlb.RequestedAt != 0 { + run.RequestedAt = time.Unix(rlb.RequestedAt, 0).UTC().Format(time.RFC3339) + } timeSetter(run) r.byRunID[ridStr] = run tidStr := rlb.Task.ID.String() @@ -57,7 +65,6 @@ func (r *runReaderWriter) UpdateRunState(ctx context.Context, rlb RunLogBase, wh func (r *runReaderWriter) AddRunLog(ctx context.Context, rlb RunLogBase, when time.Time, log string) error { r.mu.Lock() defer r.mu.Unlock() - log = fmt.Sprintf("%s: %s", when.Format(time.RFC3339), log) ridStr := rlb.RunID.String() existingRun, ok := r.byRunID[ridStr] diff --git a/task/backend/meta.go b/task/backend/meta.go index 2c8e73dda9..5bf1d776dd 100644 --- a/task/backend/meta.go +++ b/task/backend/meta.go @@ -149,8 +149,9 @@ func (stm *StoreTaskMeta) createNextRunFromQueue(now, nextDue int64, sch cron.Sc return RunCreation{ Created: QueuedRun{ - RunID: id, - Now: runNow, + RunID: id, + Now: runNow, + RequestedAt: q.RequestedAt, }, NextDue: nextDue, HasQueue: len(stm.ManualRuns) > 0, diff --git a/task/backend/scheduler.go b/task/backend/scheduler.go index 347c2ac6f8..91d811d527 100644 --- a/task/backend/scheduler.go +++ b/task/backend/scheduler.go @@ -46,6 +46,9 @@ type Executor interface { type QueuedRun struct { TaskID, RunID platform.ID + // The Unix timestamp (seconds since January 1, 1970 UTC) that will be set when a run a manually requested + RequestedAt int64 + // The Unix timestamp (seconds since January 1, 1970 UTC) that will be set // as the "now" option when executing the task. Now int64 @@ -602,6 +605,7 @@ func (r *runner) updateRunState(qr QueuedRun, s RunStatus, runLogger *zap.Logger Task: r.task, RunID: qr.RunID, RunScheduledFor: qr.Now, + RequestedAt: qr.RequestedAt, } // Arbitrarily chosen short time limit for how fast the log write must complete. diff --git a/task/backend/store.go b/task/backend/store.go index af2eee0733..ca5fcb0e58 100644 --- a/task/backend/store.go +++ b/task/backend/store.go @@ -148,6 +148,9 @@ type RunLogBase struct { // The Unix timestamp indicating the run's scheduled time. RunScheduledFor int64 + + // When the log is requested, should be ignored when it is zero. + RequestedAt int64 } // LogWriter writes task logs and task state changes to a store. diff --git a/task/backend/storetest/logstoretest.go b/task/backend/storetest/logstoretest.go index 3beb28605c..2037989491 100644 --- a/task/backend/storetest/logstoretest.go +++ b/task/backend/storetest/logstoretest.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "github.com/influxdata/platform" "github.com/influxdata/platform/task/backend" ) @@ -86,7 +87,7 @@ func updateRunState(t *testing.T, crf CreateRunStoreFunc, drf DestroyRunStoreFun } if !reflect.DeepEqual(run, *returnedRun) { - t.Fatalf("expected: %+v, got: %+v", run, returnedRun) + t.Fatalf("expected: %+v, got: %+v, \n diff: %+v", run, *returnedRun, cmp.Diff(run, *returnedRun)) } } @@ -144,7 +145,7 @@ func runLogTest(t *testing.T, crf CreateRunStoreFunc, drf DestroyRunStoreFunc) { } if !reflect.DeepEqual(run, *returnedRun) { - t.Fatalf("expected: %+v, got: %+v", run, returnedRun) + t.Fatalf("expected: %+v, got: %+v,\n\ndiff: %+v", run, *returnedRun, cmp.Diff(run, *returnedRun)) } }