@@ -42,25 +42,31 @@ type xychart struct {
42
42
}
43
43
44
44
type githubSummary struct {
45
- client api.Client
46
- Pods []string
45
+ client api.Client
46
+ firingAlerts bool
47
+ Pods []string
47
48
}
48
49
49
50
func NewSummary (c api.Client , pods ... string ) githubSummary {
50
51
return githubSummary {
51
- client : c ,
52
- Pods : pods ,
52
+ client : c ,
53
+ Pods : pods ,
54
+ firingAlerts : false ,
53
55
}
54
56
}
55
57
58
+ func (s * githubSummary ) FiringAlerts () bool {
59
+ return s .firingAlerts
60
+ }
61
+
56
62
// PerformanceQuery queries the prometheus server and generates a mermaid xychart with the data.
57
63
// title - Display name of the xychart
58
64
// pod - Pod name with which to filter results from prometheus
59
65
// query - Prometheus query
60
66
// yLabel - Label of the Y axis i.e. "KB/s", "MB", etc.
61
67
// scaler - Constant by which to scale the results. For instance, cpu usage is more human-readable
62
68
// as "mCPU" vs "CPU", so we scale the results by a factor of 1,000.
63
- func (s githubSummary ) PerformanceQuery (title , pod , query string , yLabel string , scaler float64 ) (string , error ) {
69
+ func (s githubSummary ) PerformanceQuery (title , pod , query , yLabel string , scaler float64 ) (string , error ) {
64
70
v1api := v1 .NewAPI (s .client )
65
71
ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
66
72
defer cancel ()
@@ -90,8 +96,9 @@ func (s githubSummary) PerformanceQuery(title, pod, query string, yLabel string,
90
96
formattedData := make ([]string , 0 )
91
97
// matrix does not allow [] access, so we just do one iteration for the single result
92
98
for _ , metric := range matrix {
93
- if len (metric .Values ) < 1 {
94
- return "" , fmt .Errorf ("expected at least one data point; got: %d" , len (metric .Values ))
99
+ if len (metric .Values ) < 2 {
100
+ // A graph with one data point means something with the collection was wrong
101
+ return "" , fmt .Errorf ("expected at least two data points; got: %d" , len (metric .Values ))
95
102
}
96
103
for _ , sample := range metric .Values {
97
104
floatSample := float64 (sample .Value ) * scaler
@@ -136,6 +143,7 @@ func (s githubSummary) Alerts() (string, error) {
136
143
switch a .State {
137
144
case v1 .AlertStateFiring :
138
145
firingAlerts = append (firingAlerts , aConv )
146
+ s .firingAlerts = true
139
147
case v1 .AlertStatePending :
140
148
pendingAlerts = append (pendingAlerts , aConv )
141
149
// Ignore AlertStateInactive; the alerts endpoint doesn't return them
@@ -172,28 +180,35 @@ func executeTemplate(templateFile string, obj any) (string, error) {
172
180
// The markdown is template-driven; the summary methods are called from within the
173
181
// template. This allows us to add or change queries (hopefully) without needing to
174
182
// touch code. The summary will be output to a file supplied by the env target.
175
- func PrintSummary (envTarget string ) error {
183
+ func PrintSummary (path string ) error {
184
+ if path == "" {
185
+ fmt .Printf ("No summary output path specified; skipping" )
186
+ return nil
187
+ }
188
+
176
189
client , err := api .NewClient (api.Config {
177
190
Address : defaultPromUrl ,
178
191
})
179
192
if err != nil {
180
- fmt .Printf ("Error creating prometheus client: %v \n " , err )
181
- os . Exit ( 1 )
193
+ fmt .Printf ("warning: failed to initialize promQL client: %s " , err )
194
+ return nil
182
195
}
183
196
184
197
summary := NewSummary (client , "operator-controller" , "catalogd" )
185
198
summaryMarkdown , err := executeTemplate (summaryTemplate , summary )
186
199
if err != nil {
187
- return err
200
+ fmt .Printf ("warning: failed to generate e2e summary: %s" , err )
201
+ return nil
188
202
}
189
- if path := os .Getenv (envTarget ); path != "" {
190
- err = os .WriteFile (path , []byte (summaryMarkdown ), 0o600 )
191
- if err != nil {
192
- return err
193
- }
194
- fmt .Printf ("Test summary output to %s successful\n " , envTarget )
195
- } else {
196
- fmt .Printf ("No summary output specified; skipping" )
203
+ err = os .WriteFile (path , []byte (summaryMarkdown ), 0o600 )
204
+ if err != nil {
205
+ fmt .Printf ("warning: failed to write summary output to %s: %s" , path , err )
206
+ return nil
197
207
}
208
+ fmt .Printf ("Test summary output to %s successful\n " , path )
209
+ // TODO: uncomment when the metrics collection is proven to be stable
210
+ // if summary.FiringAlerts() {
211
+ // return fmt.Errorf("Alert(s) encountered during test run; see summary for details")
212
+ //}
198
213
return nil
199
214
}
0 commit comments