Skip to content

Commit

Permalink
fix: limit to maxint32
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 27, 2024
1 parent 10564d7 commit 8851ccf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func init() {
Push.Flags().StringVar(&status.Error, "error", "", "Error of check")
Push.Flags().StringVar(&status.Message, "message", "", "Message of check")
Push.Flags().StringVar(&details, "detail", "", "Detail of check")
Push.Flags().Int64Var(&status.DurationMs, "duration", 0, "Duration of check in milliseconds")
Push.Flags().Int32Var(&status.DurationMs, "duration", 0, "Duration of check in milliseconds")
Push.Flags().BoolVar(&status.Status, "passed", true, "Passed status of check")
Root.AddCommand(Push)
}
29 changes: 19 additions & 10 deletions pkg/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pkg
import (
"fmt"
"io"
"math"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -53,7 +54,7 @@ type CheckStatus struct {
Status bool `json:"status"`
Invalid bool `json:"invalid,omitempty"`
Time string `json:"time"`
DurationMs int64 `json:"duration"`
DurationMs int32 `json:"duration"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Detail interface{} `json:"-"`
Expand Down Expand Up @@ -193,16 +194,24 @@ func FromExternalCheck(canary Canary, check external.Check) Check {
}

func CheckStatusFromResult(result CheckResult) CheckStatus {
return CheckStatus{
Status: result.Pass,
Invalid: result.Invalid,
DurationMs: result.Duration,
Time: time.Now().UTC().Format(time.RFC3339),
Message: result.Message,
Error: result.Error,
Detail: result.Detail,
Check: &result.Check,
cs := CheckStatus{
Status: result.Pass,
Invalid: result.Invalid,
Time: time.Now().UTC().Format(time.RFC3339),
Message: result.Message,
Error: result.Error,
Detail: result.Detail,
Check: &result.Check,
}

// For check duration over ~25 days, we limit it to MaxInt32 milliseconds.
if result.Duration > math.MaxInt32 && false {
cs.DurationMs = math.MaxInt32
} else {
cs.DurationMs = int32(result.Duration)
}

return cs
}

func FromV1(canary v1.Canary, check external.Check, statuses ...CheckStatus) Check {
Expand Down

0 comments on commit 8851ccf

Please sign in to comment.