-
Notifications
You must be signed in to change notification settings - Fork 86
/
step_download_trace.go
106 lines (77 loc) · 2.45 KB
/
step_download_trace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package worker
import (
"os"
"time"
gocontext "context"
"github.com/mitchellh/multistep"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/travis-ci/worker/backend"
"github.com/travis-ci/worker/context"
"github.com/travis-ci/worker/metrics"
"go.opencensus.io/trace"
)
type stepDownloadTrace struct {
persister BuildTracePersister
}
func (s *stepDownloadTrace) Run(state multistep.StateBag) multistep.StepAction {
if s.persister == nil {
return multistep.ActionContinue
}
ctx := state.Get("ctx").(gocontext.Context)
defer context.TimeSince(ctx, "step_download_trace_run", time.Now())
ctx, span := trace.StartSpan(ctx, "DownloadTrace.Run")
defer span.End()
buildJob := state.Get("buildJob").(Job)
processedAt := state.Get("processedAt").(time.Time)
instance := state.Get("instance").(backend.Instance)
logger := context.LoggerFromContext(ctx).WithField("self", "step_download_trace")
// ctx, cancel := gocontext.WithTimeout(ctx, s.uploadTimeout)
// defer cancel()
// downloading the trace is best-effort, so we continue in any case
if !buildJob.Payload().Trace {
return multistep.ActionContinue
}
buf, err := instance.DownloadTrace(ctx)
if err != nil {
span.SetStatus(trace.Status{
Code: trace.StatusCodeUnavailable,
Message: err.Error(),
})
if err == backend.ErrDownloadTraceNotImplemented || os.IsNotExist(errors.Cause(err)) {
logger.WithFields(logrus.Fields{
"err": err,
}).Info("skipping trace download")
return multistep.ActionContinue
}
metrics.Mark("worker.job.trace.download.error")
logger.WithFields(logrus.Fields{
"err": err,
}).Error("couldn't download trace")
context.CaptureError(ctx, err)
return multistep.ActionContinue
}
logger.WithFields(logrus.Fields{
"since_processed_ms": time.Since(processedAt).Seconds() * 1e3,
}).Info("downloaded trace")
err = s.persister.Persist(ctx, buildJob, buf)
if err != nil {
metrics.Mark("worker.job.trace.persist.error")
span.SetStatus(trace.Status{
Code: trace.StatusCodeUnavailable,
Message: err.Error(),
})
logger.WithFields(logrus.Fields{
"err": err,
}).Error("couldn't persist trace")
context.CaptureError(ctx, err)
return multistep.ActionContinue
}
logger.WithFields(logrus.Fields{
"since_processed_ms": time.Since(processedAt).Seconds() * 1e3,
}).Info("persisted trace")
return multistep.ActionContinue
}
func (s *stepDownloadTrace) Cleanup(state multistep.StateBag) {
// Nothing to clean up
}