@@ -21,46 +21,59 @@ import (
2121 "gonum.org/v1/gonum/mat"
2222)
2323
24+ // This module cannot be included in the workspace since it requires a version of Gonum that is not compatible with the Go Driver.
25+ // Must use GOWORK=off to run this test.
26+
27+ type OverrideInfo struct {
28+ OverrideMainline bool `bson:"override_mainline"`
29+ BaseOrder interface {} `bson:"base_order"`
30+ Reason interface {} `bson:"reason"`
31+ User interface {} `bson:"user"`
32+ }
33+
34+ type Info struct {
35+ Project string `bson:"project"`
36+ Version string `bson:"version"`
37+ Variant string `bson:"variant"`
38+ Order int64 `bson:"order"`
39+ TaskName string `bson:"task_name"`
40+ TaskID string `bson:"task_id"`
41+ Execution int64 `bson:"execution"`
42+ Mainline bool `bson:"mainline"`
43+ OverrideInfo OverrideInfo
44+ TestName string `bson:"test_name"`
45+ Args map [string ]interface {} `bson:"args"`
46+ }
47+
48+ type Stat struct {
49+ Name string `bson:"name"`
50+ Val float64 `bson:"val"`
51+ Metadata interface {} `bson:"metadata"`
52+ }
53+
54+ type Rollups struct {
55+ Stats []Stat
56+ }
57+
2458type RawData struct {
25- Info struct {
26- Project string `bson:"project"`
27- Version string `bson:"version"`
28- Variant string `bson:"variant"`
29- Order int64 `bson:"order"`
30- TaskName string `bson:"task_name"`
31- TaskID string `bson:"task_id"`
32- Execution int64 `bson:"execution"`
33- Mainline bool `bson:"mainline"`
34- OverrideInfo struct {
35- OverrideMainline bool `bson:"override_mainline"`
36- BaseOrder interface {} `bson:"base_order"`
37- Reason interface {} `bson:"reason"`
38- User interface {} `bson:"user"`
39- }
40- TestName string `bson:"test_name"`
41- Args map [string ]interface {} `bson:"args"`
42- }
43- CreatedAt interface {} `bson:"created_at"`
44- CompletedAt interface {} `bson:"completed_at"`
45- Rollups struct {
46- Stats []struct {
47- Name string `bson:"name"`
48- Val float64 `bson:"val"`
49- Metadata interface {} `bson:"metadata"`
50- }
51- }
59+ Info Info
60+ CreatedAt interface {} `bson:"created_at"`
61+ CompletedAt interface {} `bson:"completed_at"`
62+ Rollups Rollups
5263 FailedRollupAttempts int64 `bson:"failed_rollup_attempts"`
5364}
5465
66+ type TimeSeriesInfo struct {
67+ Project string `bson:"project"`
68+ Variant string `bson:"variant"`
69+ Task string `bson:"task"`
70+ Test string `bson:"test"`
71+ Measurement string `bson:"measurement"`
72+ Args map [string ]interface {} `bson:"args"`
73+ }
74+
5575type StableRegion struct {
56- TimeSeriesInfo struct {
57- Project string `bson:"project"`
58- Variant string `bson:"variant"`
59- Task string `bson:"task"`
60- Test string `bson:"test"`
61- Measurement string `bson:"measurement"`
62- Args map [string ]interface {} `bson:"args"`
63- }
76+ TimeSeriesInfo TimeSeriesInfo
6477 Start interface {} `bson:"start"`
6578 End interface {} `bson:"end"`
6679 Values []float64 `bson:"values"`
@@ -78,61 +91,66 @@ type StableRegion struct {
7891}
7992
8093type EnergyStats struct {
81- Benchmark string
82- Measurement string
83- PatchVersion string
84- StableRegion StableRegion
85- PatchValues []float64
86- PChange float64
87- E float64
88- T float64
89- H float64
90- Z float64
94+ Benchmark string
95+ Measurement string
96+ PatchVersion string
97+ StableRegion StableRegion
98+ PatchValues []float64
99+ PercentChange float64
100+ EnergyStatistic float64
101+ TestStatistic float64
102+ HScore float64
103+ ZScore float64
91104}
92105
106+ const expandedMetricsDB = "expanded_metrics"
107+ const rawResultsColl = "raw_results"
108+ const stableRegionsColl = "stable_regions"
109+
93110func main () {
94- // Connect to analytics node
111+ // Check for variables
95112 uri := os .Getenv ("PERF_URI_PRIVATE_ENDPOINT" )
96113 if uri == "" {
97- log .Panic ("PERF_URI_PRIVATE_ENDPOINT env variable is not set" )
114+ log .Fatal ("PERF_URI_PRIVATE_ENDPOINT env variable is not set" )
98115 }
99116
100117 version := os .Args [len (os .Args )- 1 ]
101118 if version == "" {
102- log .Panic ("could not get VERSION_ID" )
119+ log .Fatal ("could not get VERSION_ID" )
103120 }
104121
105- client , err1 := mongo .Connect (options .Client ().ApplyURI (uri ))
106- if err1 != nil {
107- log .Panicf ("Error connecting client: %v" , err1 )
122+ // Connect to analytics node
123+ client , err := mongo .Connect (options .Client ().ApplyURI (uri ))
124+ if err != nil {
125+ log .Fatalf ("Error connecting client: %v" , err )
108126 }
109127
110128 ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
111129 defer cancel ()
112- err2 : = client .Ping (ctx , nil )
113- if err2 != nil {
114- log .Panicf ("Error pinging MongoDB Analytics: %v" , err2 )
130+ err = client .Ping (ctx , nil )
131+ if err != nil {
132+ log .Fatalf ("Error pinging MongoDB Analytics: %v" , err )
115133 }
116- fmt .Println ("Successfully connected to MongoDB Analytics node." )
134+ log .Println ("Successfully connected to MongoDB Analytics node." )
117135
118- db := client .Database ("expanded_metrics" )
136+ db := client .Database (expandedMetricsDB )
119137
120138 // Get raw data, most recent stable region, and calculate energy stats
121- patchRawData , err3 := findRawData (version , db .Collection ("raw_results" ))
122- if err3 != nil {
123- log .Panicf ("Error getting raw data: %v" , err3 )
139+ patchRawData , err := findRawData (version , db .Collection (rawResultsColl ))
140+ if err != nil {
141+ log .Fatalf ("Error getting raw data: %v" , err )
124142 }
125143
126- allEnergyStats , err4 := getEnergyStatsForAllBenchMarks (patchRawData , db .Collection ("stable_regions" ))
127- if err4 != nil {
128- log .Panicf ("Error getting energy statistics: %v" , err4 )
144+ allEnergyStats , err := getEnergyStatsForAllBenchMarks (patchRawData , db .Collection (stableRegionsColl ))
145+ if err != nil {
146+ log .Fatalf ("Error getting energy statistics: %v" , err )
129147 }
130- fmt .Println (generatePRComment (allEnergyStats , version ))
148+ log .Println (generatePRComment (allEnergyStats , version ))
131149
132150 // Disconnect client
133- err0 : = client .Disconnect (context .Background ())
134- if err0 != nil {
135- log .Panicf ("Failed to disconnect client: %v" , err0 )
151+ err = client .Disconnect (context .Background ())
152+ if err != nil {
153+ log .Fatalf ("Failed to disconnect client: %v" , err )
136154 }
137155}
138156
@@ -149,27 +167,27 @@ func findRawData(version string, coll *mongo.Collection) ([]RawData, error) {
149167
150168 cursor , err := coll .Find (findCtx , filter )
151169 if err != nil {
152- log .Panicf (
170+ log .Fatalf (
153171 "Error retrieving raw data for version %q: %v" ,
154172 version ,
155173 err ,
156174 )
157175 }
158- defer cursor .Close (findCtx )
176+ defer func () { err = cursor .Close (findCtx ) }( )
159177
160- fmt .Printf ("Successfully retrieved %d docs from version %s.\n " , cursor .RemainingBatchLength (), version )
178+ log .Printf ("Successfully retrieved %d docs from version %s.\n " , cursor .RemainingBatchLength (), version )
161179
162180 var rawData []RawData
163181 err = cursor .All (findCtx , & rawData )
164182 if err != nil {
165- log .Panicf (
183+ log .Fatalf (
166184 "Error decoding raw data from version %q: %v" ,
167185 version ,
168186 err ,
169187 )
170188 }
171189
172- return rawData , nil
190+ return rawData , err
173191}
174192
175193// Find the most recent stable region of the mainline version for a specific test/measurement
@@ -208,7 +226,7 @@ func getEnergyStatsForOneBenchmark(rd RawData, coll *mongo.Collection) ([]*Energ
208226
209227 stableRegion , err := findLastStableRegion (testname , measurement , coll )
210228 if err != nil {
211- log .Panicf (
229+ log .Fatalf (
212230 "Error finding last stable region for test %q, measurement %q: %v" ,
213231 testname ,
214232 measurement ,
@@ -221,16 +239,16 @@ func getEnergyStatsForOneBenchmark(rd RawData, coll *mongo.Collection) ([]*Energ
221239 z := GetZScore (patchVal [0 ], stableRegion .Mean , stableRegion .Std )
222240
223241 es := EnergyStats {
224- Benchmark : testname ,
225- Measurement : measurement ,
226- PatchVersion : rd .Info .Version ,
227- StableRegion : * stableRegion ,
228- PatchValues : patchVal ,
229- PChange : pChange ,
230- E : e ,
231- T : t ,
232- H : h ,
233- Z : z ,
242+ Benchmark : testname ,
243+ Measurement : measurement ,
244+ PatchVersion : rd .Info .Version ,
245+ StableRegion : * stableRegion ,
246+ PatchValues : patchVal ,
247+ PercentChange : pChange ,
248+ EnergyStatistic : e ,
249+ TestStatistic : t ,
250+ HScore : h ,
251+ ZScore : z ,
234252 }
235253 energyStats = append (energyStats , & es )
236254 }
@@ -258,9 +276,9 @@ func generatePRComment(energyStats []*EnergyStats, version string) string {
258276
259277 var testCount int64
260278 for _ , es := range energyStats {
261- if math .Abs (es .Z ) > 1.96 {
279+ if math .Abs (es .ZScore ) > 1.96 {
262280 testCount += 1
263- fmt .Fprintf (& comment , "| %s | %s | %.4f | %.4f | %.4f | Avg: %.4f, Stdev: %.4f | %.4f |\n " , es .Benchmark , es .Measurement , es .H , es .Z , es .PChange , es .StableRegion .Mean , es .StableRegion .Std , es .PatchValues [0 ])
281+ fmt .Fprintf (& comment , "| %s | %s | %.4f | %.4f | %.4f | Avg: %.4f, Stdev: %.4f | %.4f |\n " , es .Benchmark , es .Measurement , es .HScore , es .ZScore , es .PercentChange , es .StableRegion .Mean , es .StableRegion .Std , es .PatchValues [0 ])
264282 }
265283 }
266284
0 commit comments