@@ -27,8 +27,9 @@ import (
27
27
28
28
type getCountFunc func () (int , error )
29
29
30
- // CheckMonitoring checks if logs and metrics exist for the given network. Github labels
31
- // are also used as filters if provided as env vars (GH_*).
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.
32
33
func CheckMonitoring (ctx context.Context , log logging.Logger , networkUUID string ) error {
33
34
return errors .Join (
34
35
CheckLogsExist (ctx , log , networkUUID ),
@@ -64,8 +65,9 @@ func waitForCount(ctx context.Context, log logging.Logger, name string, getCount
64
65
return nil
65
66
}
66
67
67
- // CheckLogsExist checks if logs exist for the given network. Github labels are also
68
- // used as filters 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.
69
71
func CheckLogsExist (ctx context.Context , log logging.Logger , networkUUID string ) error {
70
72
username , password , err := getCollectorCredentials (promtailCmd )
71
73
if err != nil {
@@ -262,10 +264,12 @@ func (b *basicAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, er
262
264
263
265
// getSelectors returns the comma-separated list of selectors.
264
266
func getSelectors (networkUUID string ) (string , error ) {
265
- selectors := [] string {}
267
+ // If network UUID is provided, use it as the only selector
266
268
if len (networkUUID ) > 0 {
267
- selectors = append ( selectors , fmt .Sprintf (`network_uuid="%s"` , networkUUID ))
269
+ return [] string { fmt .Sprintf (`network_uuid="%s"` , networkUUID )}
268
270
}
271
+
272
+ // Fall back to using Github labels as selectors
269
273
githubLabels := githubLabelsFromEnv ()
270
274
for label := range githubLabels {
271
275
value , err := githubLabels .GetStringVal (label )
@@ -277,5 +281,9 @@ func getSelectors(networkUUID string) (string, error) {
277
281
}
278
282
selectors = append (selectors , fmt .Sprintf (`%s="%s"` , label , value ))
279
283
}
284
+ if len (selectors ) == 0 {
285
+ return "" , errors .New ("no GH_* env vars set to use for selectors" )
286
+ }
287
+
280
288
return strings .Join (selectors , "," ), nil
281
289
}
0 commit comments