@@ -27,6 +27,16 @@ import (
27
27
28
28
type getCountFunc func () (int , error )
29
29
30
+ // CheckMonitoring checks if logs and metrics exist for the given network. If no network
31
+ // UUID is provided, an attempt will be made to derive selectors from env vars (GH_*)
32
+ // identifying a github actions run.
33
+ func CheckMonitoring (ctx context.Context , log logging.Logger , networkUUID string ) error {
34
+ return errors .Join (
35
+ CheckLogsExist (ctx , log , networkUUID ),
36
+ CheckMetricsExist (ctx , log , networkUUID ),
37
+ )
38
+ }
39
+
30
40
// waitForCount waits until the provided function returns greater than zero.
31
41
func waitForCount (ctx context.Context , log logging.Logger , name string , getCount getCountFunc ) error {
32
42
err := pollUntilContextCancel (
@@ -55,8 +65,9 @@ func waitForCount(ctx context.Context, log logging.Logger, name string, getCount
55
65
return nil
56
66
}
57
67
58
- // CheckLogsExist checks if logs exist for the given network. Github labels are also
59
- // included if provided as env vars (GH_*).
68
+ // CheckLogsExist checks if logs exist for the given network. If no network UUID is
69
+ // provided, an attempt will be made to derive selectors from env vars (GH_*) identifying
70
+ // a github actions run.
60
71
func CheckLogsExist (ctx context.Context , log logging.Logger , networkUUID string ) error {
61
72
username , password , err := getCollectorCredentials (promtailCmd )
62
73
if err != nil {
@@ -163,7 +174,7 @@ func queryLoki(
163
174
}
164
175
165
176
// CheckMetricsExist checks if metrics exist for the given network. Github labels are also
166
- // included if provided as env vars (GH_*).
177
+ // used as filters if provided as env vars (GH_*).
167
178
func CheckMetricsExist (ctx context.Context , log logging.Logger , networkUUID string ) error {
168
179
username , password , err := getCollectorCredentials (prometheusCmd )
169
180
if err != nil {
@@ -253,10 +264,13 @@ func (b *basicAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, er
253
264
254
265
// getSelectors returns the comma-separated list of selectors.
255
266
func getSelectors (networkUUID string ) (string , error ) {
256
- selectors := [] string {}
267
+ // If network UUID is provided, use it as the only selector
257
268
if len (networkUUID ) > 0 {
258
- selectors = append ( selectors , fmt .Sprintf (`network_uuid="%s"` , networkUUID ))
269
+ return fmt .Sprintf (`network_uuid="%s"` , networkUUID ), nil
259
270
}
271
+
272
+ // Fall back to using Github labels as selectors
273
+ selectors := []string {}
260
274
githubLabels := githubLabelsFromEnv ()
261
275
for label := range githubLabels {
262
276
value , err := githubLabels .GetStringVal (label )
@@ -268,5 +282,9 @@ func getSelectors(networkUUID string) (string, error) {
268
282
}
269
283
selectors = append (selectors , fmt .Sprintf (`%s="%s"` , label , value ))
270
284
}
285
+ if len (selectors ) == 0 {
286
+ return "" , errors .New ("no GH_* env vars set to use for selectors" )
287
+ }
288
+
271
289
return strings .Join (selectors , "," ), nil
272
290
}
0 commit comments