Skip to content

Commit

Permalink
🧹 return error for CheckApiHealth function (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock authored Jan 17, 2023
1 parent 170a740 commit dff7736
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 5 additions & 1 deletion apps/cnquery/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ Status sends a ping to Mondoo Platform to verify the credentials.
}

// check server health and clock skew
s.Upstream = health.CheckApiHealth(opts.UpstreamApiEndpoint())
upstreamStatus, err := health.CheckApiHealth(opts.UpstreamApiEndpoint())
if err != nil {
log.Error().Err(err).Msg("could not check upstream health")
}
s.Upstream = upstreamStatus

// check valid agent authentication
plugins := []ranger.ClientPlugin{}
Expand Down
9 changes: 4 additions & 5 deletions upstream/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"time"

"github.com/rs/zerolog/log"
"go.mondoo.com/ranger-rpc"
)

Expand All @@ -21,18 +20,18 @@ type Status struct {
Warnings []string `json:"warnings,omitempty"`
}

func CheckApiHealth(endpoint string) Status {
func CheckApiHealth(endpoint string) (Status, error) {
status := Status{}
status.API.Endpoint = endpoint

sendTime := time.Now()
healthClient, err := NewHealthClient(endpoint, ranger.DefaultHttpClient())
if err != nil {
log.Error().Err(err).Msg("could not run api health check")
return status, err
}
healthResp, err := healthClient.Check(context.Background(), &HealthCheckRequest{})
if err != nil {
log.Error().Err(err).Msg("could not run api health check")
return status, err
} else {
status.API.Status = healthResp.Status.String()
status.API.Timestamp = healthResp.Time
Expand All @@ -55,7 +54,7 @@ func CheckApiHealth(endpoint string) Status {
}
}
}
return status
return status, nil
}

func abs(a time.Duration) time.Duration {
Expand Down

0 comments on commit dff7736

Please sign in to comment.