vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletserver/throttle/check_result.go (about) 1 /* 2 Copyright 2017 GitHub Inc. 3 4 Licensed under MIT License. See https://github.com/github/freno/blob/master/LICENSE 5 */ 6 7 package throttle 8 9 import ( 10 "net/http" 11 12 "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base" 13 ) 14 15 // CheckResult is the result for an app inquiring on a metric. It also exports as JSON via the API 16 type CheckResult struct { 17 StatusCode int `json:"StatusCode"` 18 Value float64 `json:"Value"` 19 Threshold float64 `json:"Threshold"` 20 Error error `json:"-"` 21 Message string `json:"Message"` 22 } 23 24 // NewCheckResult returns a CheckResult 25 func NewCheckResult(statusCode int, value float64, threshold float64, err error) *CheckResult { 26 result := &CheckResult{ 27 StatusCode: statusCode, 28 Value: value, 29 Threshold: threshold, 30 Error: err, 31 } 32 if err != nil { 33 result.Message = err.Error() 34 } 35 return result 36 } 37 38 // NewErrorCheckResult returns a check result that indicates an error 39 func NewErrorCheckResult(statusCode int, err error) *CheckResult { 40 return NewCheckResult(statusCode, 0, 0, err) 41 } 42 43 // NoSuchMetricCheckResult is a result returns when a metric is unknown 44 var NoSuchMetricCheckResult = NewErrorCheckResult(http.StatusNotFound, base.ErrNoSuchMetric) 45 46 var okMetricCheckResult = NewCheckResult(http.StatusOK, 0, 0, nil) 47 48 var invalidCheckTypeCheckResult = NewErrorCheckResult(http.StatusInternalServerError, base.ErrInvalidCheckType)