From 2f879c41c4a9e44dded5e947b08f45b98976c50d Mon Sep 17 00:00:00 2001 From: Jason Song Date: Thu, 20 Oct 2022 15:29:23 +0800 Subject: [PATCH] chore: remove tracing codes --- go.mod | 1 - go.sum | 1 - runtime/reporter.go | 62 +++++++++++++-------------------------------- 3 files changed, 17 insertions(+), 47 deletions(-) diff --git a/go.mod b/go.mod index 381b762..4fb7716 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/avast/retry-go/v4 v4.1.0 github.com/bufbuild/connect-go v0.5.0 github.com/docker/docker v20.10.17+incompatible - github.com/google/go-cmp v0.5.8 github.com/joho/godotenv v1.4.0 github.com/kelseyhightower/envconfig v1.4.0 github.com/mattn/go-isatty v0.0.16 diff --git a/go.sum b/go.sum index 4dcd689..0d39d5c 100644 --- a/go.sum +++ b/go.sum @@ -404,7 +404,6 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-containerregistry v0.5.1/go.mod h1:Ct15B4yir3PLOP5jsy0GNeYVaIZs/MK/Jz5any1wFW0= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= diff --git a/runtime/reporter.go b/runtime/reporter.go index 68def59..b7f244e 100644 --- a/runtime/reporter.go +++ b/runtime/reporter.go @@ -12,8 +12,6 @@ import ( "github.com/avast/retry-go/v4" "github.com/bufbuild/connect-go" - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" log "github.com/sirupsen/logrus" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/timestamppb" @@ -61,9 +59,7 @@ func (r *Reporter) Fire(entry *log.Entry) error { timestamp := entry.Time if r.state.StartedAt == nil { - r.updateState(func() { - r.state.StartedAt = timestamppb.New(timestamp) - }) + r.state.StartedAt = timestamppb.New(timestamp) } var step *runnerv1.StepState @@ -76,15 +72,13 @@ func (r *Reporter) Fire(entry *log.Entry) error { if step == nil { if v, ok := entry.Data["jobResult"]; ok { if jobResult, ok := r.parseResult(v); ok { - r.updateState(func() { - r.state.Result = jobResult - r.state.StoppedAt = timestamppb.New(timestamp) - for _, s := range r.state.Steps { - if s.Result == runnerv1.Result_RESULT_UNSPECIFIED { - s.Result = runnerv1.Result_RESULT_CANCELLED - } + r.state.Result = jobResult + r.state.StoppedAt = timestamppb.New(timestamp) + for _, s := range r.state.Steps { + if s.Result == runnerv1.Result_RESULT_UNSPECIFIED { + s.Result = runnerv1.Result_RESULT_CANCELLED } - }) + } } } if !r.duringSteps() { @@ -94,19 +88,15 @@ func (r *Reporter) Fire(entry *log.Entry) error { } if step.StartedAt == nil { - r.updateState(func() { - step.StartedAt = timestamppb.New(timestamp) - }) + step.StartedAt = timestamppb.New(timestamp) } if v, ok := entry.Data["raw_output"]; ok { if rawOutput, ok := v.(bool); ok && rawOutput { - r.updateState(func() { - if step.LogLength == 0 { - step.LogIndex = int64(r.logOffset + len(r.logRows)) - } - step.LogLength++ - }) + if step.LogLength == 0 { + step.LogIndex = int64(r.logOffset + len(r.logRows)) + } + step.LogLength++ r.logRows = append(r.logRows, r.parseLogRow(entry)) return nil } @@ -114,13 +104,11 @@ func (r *Reporter) Fire(entry *log.Entry) error { if v, ok := entry.Data["stepResult"]; ok { if stepResult, ok := r.parseResult(v); ok { - r.updateState(func() { - if step.LogLength == 0 { - step.LogIndex = int64(r.logOffset + len(r.logRows)) - } - step.Result = stepResult - step.StoppedAt = timestamppb.New(timestamp) - }) + if step.LogLength == 0 { + step.LogIndex = int64(r.logOffset + len(r.logRows)) + } + step.Result = stepResult + step.StoppedAt = timestamppb.New(timestamp) } } @@ -274,19 +262,3 @@ func (r *Reporter) parseLogRow(entry *log.Entry) *runnerv1.LogRow { Content: strings.TrimSuffix(entry.Message, "\r\n"), } } - -func (r *Reporter) updateState(update func()) { - if log.GetLevel() < log.TraceLevel { - update() - return - } - - before := proto.Clone(r.state) - update() - diff := cmp.Diff(before, r.state, cmpopts.IgnoreUnexported( - runnerv1.TaskState{}, - runnerv1.StepState{}, - timestamppb.Timestamp{}, - )) - log.Tracef("update state %d: %s", r.state.Id, diff) -}