Skip to content

Commit d234056

Browse files
committed
fixup: Use the network UUID or GH_* as selectors, but not both
1 parent 6f3825f commit d234056

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tests/fixture/tmpnet/check_monitoring.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import (
2727

2828
type getCountFunc func() (int, error)
2929

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.
3233
func CheckMonitoring(ctx context.Context, log logging.Logger, networkUUID string) error {
3334
return errors.Join(
3435
CheckLogsExist(ctx, log, networkUUID),
@@ -64,8 +65,9 @@ func waitForCount(ctx context.Context, log logging.Logger, name string, getCount
6465
return nil
6566
}
6667

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.
6971
func CheckLogsExist(ctx context.Context, log logging.Logger, networkUUID string) error {
7072
username, password, err := getCollectorCredentials(promtailCmd)
7173
if err != nil {
@@ -262,10 +264,12 @@ func (b *basicAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, er
262264

263265
// getSelectors returns the comma-separated list of selectors.
264266
func getSelectors(networkUUID string) (string, error) {
265-
selectors := []string{}
267+
// If network UUID is provided, use it as the only selector
266268
if len(networkUUID) > 0 {
267-
selectors = append(selectors, fmt.Sprintf(`network_uuid="%s"`, networkUUID))
269+
return []string{fmt.Sprintf(`network_uuid="%s"`, networkUUID)}
268270
}
271+
272+
// Fall back to using Github labels as selectors
269273
githubLabels := githubLabelsFromEnv()
270274
for label := range githubLabels {
271275
value, err := githubLabels.GetStringVal(label)
@@ -277,5 +281,9 @@ func getSelectors(networkUUID string) (string, error) {
277281
}
278282
selectors = append(selectors, fmt.Sprintf(`%s="%s"`, label, value))
279283
}
284+
if len(selectors) == 0 {
285+
return "", errors.New("no GH_* env vars set to use for selectors")
286+
}
287+
280288
return strings.Join(selectors, ","), nil
281289
}

0 commit comments

Comments
 (0)