-
Notifications
You must be signed in to change notification settings - Fork 124
/
perf_send.go
97 lines (80 loc) · 3.07 KB
/
perf_send.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
package command
import (
"context"
"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/evergreen/agent/internal"
"github.com/evergreen-ci/evergreen/agent/internal/client"
"github.com/evergreen-ci/evergreen/util"
"github.com/evergreen-ci/poplar"
"github.com/evergreen-ci/poplar/rpc"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
)
type perfSend struct {
// AWSKey and AWSSecret are the user's credentials for authenticating
// interactions with S3. These are required if any of the tests have
// artifacts.
AWSKey string `mapstructure:"aws_key" plugin:"expand"`
AWSSecret string `mapstructure:"aws_secret" plugin:"expand"`
// Region is the S3 region where the global bucket is located. It
// defaults to "us-east-1".
Region string `mapstructure:"region" plugin:"expand"`
// Bucket is the global s3 bucket to use when storing any artifacts
// without a bucket specified.
Bucket string `mapstructure:"bucket" plugin:"expand"`
// Prefix specifies the global prefix to use within the S3 bucket for
// any artifacts without a prefix specified.
Prefix string `mapstructure:"prefix" plugin:"expand"`
// File is the file containing either the JSON or YAML representation
// of the performance report tests.
File string `mapstructure:"file" plugin:"expand"`
base
}
func perfSendFactory() Command { return &perfSend{} }
func (*perfSend) Name() string { return "perf.send" }
func (c *perfSend) ParseParams(params map[string]interface{}) error {
if err := mapstructure.Decode(params, c); err != nil {
return errors.Wrap(err, "decoding params")
}
if c.File == "" {
return errors.New("file must not be blank")
}
return nil
}
func (c *perfSend) Execute(ctx context.Context, comm client.Communicator, logger client.LoggerProducer, conf *internal.TaskConfig) error {
if err := util.ExpandValues(c, &conf.Expansions); err != nil {
return errors.Wrap(err, "applying expansions")
}
// Read the file and add the Evergreen info.
filename := GetWorkingDirectory(conf, c.File)
report, err := poplar.LoadTests(filename)
if err != nil {
return errors.Wrapf(err, "reading tests from file '%s'", filename)
}
c.addEvgData(report, conf)
// Send data to the Cedar performance results service.
conn, err := comm.GetCedarGRPCConn(ctx)
if err != nil {
return errors.Wrap(err, "connecting to Cedar")
}
opts := rpc.UploadReportOptions{
Report: report,
ClientConn: conn,
}
return errors.Wrap(rpc.UploadReport(ctx, opts), "uploading report to Cedar")
}
func (c *perfSend) addEvgData(report *poplar.Report, conf *internal.TaskConfig) {
report.Project = conf.Task.Project
report.Version = conf.Task.Version
report.Order = conf.Task.RevisionOrderNumber
report.Variant = conf.Task.BuildVariant
report.TaskName = conf.Task.DisplayName
report.TaskID = conf.Task.Id
report.Execution = conf.Task.Execution
report.Mainline = conf.Task.Requester == evergreen.RepotrackerVersionRequester
report.BucketConf.APIKey = c.AWSKey
report.BucketConf.APISecret = c.AWSSecret
report.BucketConf.Name = c.Bucket
report.BucketConf.Prefix = c.Prefix
report.BucketConf.Region = c.Region
}