Skip to content

Commit

Permalink
fixup: Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maru-ava committed Feb 24, 2025
1 parent c3cac81 commit 049efef
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions tests/fixture/tmpnet/check_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

type getCountFunc func() (int, error)

// waitForCount waits until the provided function returns greater than zero.
func waitForCount(ctx context.Context, log logging.Logger, name string, getCount getCountFunc) error {
if err := pollUntilContextCancel(ctx, func(_ context.Context) (bool, error) {
count, err := getCount()
Expand Down Expand Up @@ -54,11 +55,14 @@ func CheckLogsExist(ctx context.Context, log logging.Logger, networkUUID string)
if err != nil {
return fmt.Errorf("failed to get collector credentials: %w", err)
}
query, err := getCheckLogsQuery(networkUUID)

url := getLokiURL()

selectors, err := getSelectors(networkUUID)
if err != nil {
return err
}
url := getLokiURL()
query := fmt.Sprintf("sum(count_over_time({%s}[1h]))", selectors)

log.Info("checking if logs exist",
zap.String("url", url),
Expand All @@ -70,15 +74,6 @@ func CheckLogsExist(ctx context.Context, log logging.Logger, networkUUID string)
})
}

// getCheckLogsQuery returns the query to check if logs exist.
func getCheckLogsQuery(networkUUID string) (string, error) {
selectors, err := getSelectors(networkUUID)
if err != nil {
return "", err
}
return fmt.Sprintf("sum(count_over_time({%s}[1h]))", selectors), nil
}

func queryLoki(
ctx context.Context,
lokiURL string,
Expand Down Expand Up @@ -159,11 +154,14 @@ func CheckMetricsExist(ctx context.Context, log logging.Logger, networkUUID stri
if err != nil {
return fmt.Errorf("failed to get collector credentials: %w", err)
}
query, err := getCheckMetricsQuery(networkUUID)

url := getPrometheusURL()

selectors, err := getSelectors(networkUUID)
if err != nil {
return err
}
url := getPrometheusURL()
query := fmt.Sprintf("count({%s})", selectors)

log.Info("checking if metrics exist",
zap.String("url", url),
Expand All @@ -175,15 +173,6 @@ func CheckMetricsExist(ctx context.Context, log logging.Logger, networkUUID stri
})
}

// getCheckMetricsQuery returns the query to check if metrics exist.
func getCheckMetricsQuery(networkUUID string) (string, error) {
selectors, err := getSelectors(networkUUID)
if err != nil {
return "", err
}
return fmt.Sprintf("count({%s})", selectors), nil
}

func queryPrometheus(
ctx context.Context,
log logging.Logger,
Expand Down

0 comments on commit 049efef

Please sign in to comment.