Skip to content

Commit

Permalink
make message verbose when unhealthy
Browse files Browse the repository at this point in the history
  • Loading branch information
theoremoon committed Nov 21, 2019
1 parent be28d0c commit 57b7a50
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cmd/bgproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ type target struct {
DeployedAt time.Time
}

func (t *target) Check() bool {
func (t *target) Check() (bool, string) {
r, err := http.Get(t.Url.String())
if err != nil {
return false
return false, err.Error()
}
if r.StatusCode != t.ExpectedStatus {
return false
return false, fmt.Sprintf("Returned status code: %d", r.StatusCode)
}
return true
return true, ""
}

/// Stop stops the target
Expand Down Expand Up @@ -118,10 +118,10 @@ rollback:

case <-ticker.C:
// check the health
if s.Green.Check() {
if ok, reason := s.Green.Check(); ok {
unhealthyCount = 0
} else {
logger.Println("Unhealthy")
logger.Println("Unhealthy: " + reason)
unhealthyCount++
if unhealthyCount >= s.Green.UnhealthyLimit {
break rollback
Expand All @@ -147,7 +147,9 @@ rollback:

func (s *service) SetGreen(ctx context.Context, req *pb.Target) (*pb.Result, error) {
if s.Green != nil {
logger.Println("to be implemented")
return &bp.Result{
Msg: "Green exists. First roll it back",
}, nil
}
url, err := url.Parse(req.GetUrl())
if err != nil {
Expand Down

0 comments on commit 57b7a50

Please sign in to comment.