/
cedar.ext.go
92 lines (79 loc) · 1.98 KB
/
cedar.ext.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
package internal
import (
"time"
"github.com/evergreen-ci/juniper/gopb"
"github.com/evergreen-ci/poplar"
"google.golang.org/protobuf/types/known/timestamppb"
)
func ExportArtifactInfo(in *poplar.TestArtifact) *gopb.ArtifactInfo {
out := &gopb.ArtifactInfo{
Bucket: in.Bucket,
Prefix: in.Prefix,
Path: in.Path,
Tags: in.Tags,
CreatedAt: ExportTimestamp(in.CreatedAt),
}
switch {
case in.PayloadTEXT:
out.Format = gopb.DataFormat_TEXT
case in.PayloadFTDC:
out.Format = gopb.DataFormat_FTDC
case in.PayloadBSON:
out.Format = gopb.DataFormat_BSON
case in.PayloadJSON:
out.Format = gopb.DataFormat_JSON
case in.PayloadCSV:
out.Format = gopb.DataFormat_CSV
}
switch {
case in.DataUncompressed:
out.Compression = gopb.CompressionType_NONE
case in.DataGzipped:
out.Compression = gopb.CompressionType_GZ
case in.DataTarball:
out.Compression = gopb.CompressionType_TARGZ
}
switch {
case in.EventsRaw:
out.Schema = gopb.SchemaType_RAW_EVENTS
case in.EventsHistogram:
out.Schema = gopb.SchemaType_HISTOGRAM
case in.EventsIntervalSummary:
out.Schema = gopb.SchemaType_INTERVAL_SUMMARIZATION
case in.EventsCollapsed:
out.Schema = gopb.SchemaType_COLLAPSED_EVENTS
}
return out
}
func ExportRollup(in *poplar.TestMetrics) *gopb.RollupValue {
out := &gopb.RollupValue{
Name: in.Name,
Version: int64(in.Version),
UserSubmitted: true,
}
if in.Type != "" {
t, ok := gopb.RollupType_value[in.Type]
if ok {
out.Type = gopb.RollupType(t)
}
}
switch val := in.Value.(type) {
case int64:
out.Value = &gopb.RollupValue_Int{Int: val}
case float64:
out.Value = &gopb.RollupValue_Fl{Fl: val}
case int:
out.Value = &gopb.RollupValue_Int{Int: int64(val)}
case int32:
out.Value = &gopb.RollupValue_Int{Int: int64(val)}
case float32:
out.Value = &gopb.RollupValue_Fl{Fl: float64(val)}
}
return out
}
func ExportTimestamp(t time.Time) *timestamppb.Timestamp {
if !t.IsZero() {
return timestamppb.New(t)
}
return nil
}