@@ -42,25 +42,31 @@ type xychart struct {
4242}
4343
4444type githubSummary struct {
45- client api.Client
46- Pods []string
45+ client api.Client
46+ firingAlerts bool
47+ Pods []string
4748}
4849
4950func NewSummary (c api.Client , pods ... string ) githubSummary {
5051 return githubSummary {
51- client : c ,
52- Pods : pods ,
52+ client : c ,
53+ Pods : pods ,
54+ firingAlerts : false ,
5355 }
5456}
5557
58+ func (s * githubSummary ) FiringAlerts () bool {
59+ return s .firingAlerts
60+ }
61+
5662// PerformanceQuery queries the prometheus server and generates a mermaid xychart with the data.
5763// title - Display name of the xychart
5864// pod - Pod name with which to filter results from prometheus
5965// query - Prometheus query
6066// yLabel - Label of the Y axis i.e. "KB/s", "MB", etc.
6167// scaler - Constant by which to scale the results. For instance, cpu usage is more human-readable
6268// 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 ) {
6470 v1api := v1 .NewAPI (s .client )
6571 ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
6672 defer cancel ()
@@ -90,8 +96,9 @@ func (s githubSummary) PerformanceQuery(title, pod, query string, yLabel string,
9096 formattedData := make ([]string , 0 )
9197 // matrix does not allow [] access, so we just do one iteration for the single result
9298 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 ))
95102 }
96103 for _ , sample := range metric .Values {
97104 floatSample := float64 (sample .Value ) * scaler
@@ -136,6 +143,8 @@ func (s githubSummary) Alerts() (string, error) {
136143 switch a .State {
137144 case v1 .AlertStateFiring :
138145 firingAlerts = append (firingAlerts , aConv )
146+ // TODO see note in PrintSummary()
147+ //s.firingAlerts = true
139148 case v1 .AlertStatePending :
140149 pendingAlerts = append (pendingAlerts , aConv )
141150 // Ignore AlertStateInactive; the alerts endpoint doesn't return them
@@ -172,28 +181,35 @@ func executeTemplate(templateFile string, obj any) (string, error) {
172181// The markdown is template-driven; the summary methods are called from within the
173182// template. This allows us to add or change queries (hopefully) without needing to
174183// touch code. The summary will be output to a file supplied by the env target.
175- func PrintSummary (envTarget string ) error {
184+ func PrintSummary (path string ) error {
185+ if path == "" {
186+ fmt .Printf ("No summary output path specified; skipping" )
187+ return nil
188+ }
189+
176190 client , err := api .NewClient (api.Config {
177191 Address : defaultPromUrl ,
178192 })
179193 if err != nil {
180- fmt .Printf ("Error creating prometheus client: %v \n " , err )
181- os . Exit ( 1 )
194+ fmt .Printf ("warning: failed to initialize promQL client: %s " , err )
195+ return nil
182196 }
183197
184198 summary := NewSummary (client , "operator-controller" , "catalogd" )
185199 summaryMarkdown , err := executeTemplate (summaryTemplate , summary )
186200 if err != nil {
187- return err
201+ fmt .Printf ("warning: failed to generate e2e summary: %s" , err )
202+ return nil
188203 }
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" )
204+ err = os .WriteFile (path , []byte (summaryMarkdown ), 0o600 )
205+ if err != nil {
206+ fmt .Printf ("warning: failed to write summary output to %s: %s" , path , err )
207+ return nil
197208 }
209+ fmt .Printf ("Test summary output to %s successful\n " , path )
210+ // TODO: uncomment when the metrics collection is proven to be stable
211+ // if summary.FiringAlerts() {
212+ // return fmt.Errorf("Alert(s) encountered during test run; see summary for details")
213+ //}
198214 return nil
199215}
0 commit comments