Skip to content

Commit d055ea8

Browse files
committed
Return 200 for no hosts
1 parent b3fbe7e commit d055ea8

File tree

8 files changed

+27
-8
lines changed

8 files changed

+27
-8
lines changed

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ require (
1717
vitess.io/vitess v2.1.1+incompatible
1818
)
1919

20+
require github.com/stretchr/testify v1.3.0
21+
2022
require (
23+
github.com/davecgh/go-spew v1.1.0 // indirect
2124
github.com/golang/protobuf v1.2.0 // indirect
2225
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
2326
github.com/hashicorp/golang-lru v0.5.0 // indirect
27+
github.com/pmezard/go-difflib v1.0.0 // indirect
2428
)

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pO
1010
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
1111
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
1212
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
13+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
1314
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1415
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
1516
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
@@ -35,6 +36,7 @@ github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144T
3536
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
3637
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
3738
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
39+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3840
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3941
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
4042
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
@@ -43,6 +45,7 @@ github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R
4345
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 h1:dY6ETXrvDG7Sa4vE8ZQG4yqWg6UnOcbqTAahkV813vQ=
4446
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
4547
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
48+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
4649
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
4750
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
4851
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

pkg/base/throttle_metric.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type MetricResult interface {
1717
type MetricResultFunc func() (metricResult MetricResult, threshold float64)
1818

1919
var ThresholdExceededError = errors.New("Threshold exceeded")
20-
var noHostsError = errors.New("No hosts found")
20+
var NoHostsError = errors.New("No hosts found")
2121
var noResultYetError = errors.New("Metric not collected yet")
2222
var NoSuchMetricError = errors.New("No such metric")
2323

@@ -31,7 +31,7 @@ func IsDialTcpError(e error) bool {
3131
type noHostsMetricResult struct{}
3232

3333
func (metricResult *noHostsMetricResult) Get() (float64, error) {
34-
return 0, noHostsError
34+
return 0, NoHostsError
3535
}
3636

3737
var NoHostsMetricResult = &noHostsMetricResult{}

pkg/mysql/mysql_inventory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package mysql
77

88
import (
99
"fmt"
10+
1011
"github.com/github/freno/pkg/base"
1112
)
1213

pkg/throttle/check.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77

88
"fmt"
99

10+
"errors"
11+
1012
"github.com/github/freno/pkg/base"
1113
metrics "github.com/rcrowley/go-metrics"
1214
)
@@ -65,6 +67,9 @@ func (check *ThrottlerCheck) checkAppMetricResult(appName string, storeType stri
6567
} else if err == base.NoSuchMetricError {
6668
// not collected yet, or metric does not exist
6769
statusCode = http.StatusNotFound // 404
70+
} else if errors.Is(err, base.NoHostsError) {
71+
// If no hosts we report 0 for the metric.
72+
statusCode = http.StatusOK // 200
6873
} else if err != nil {
6974
// any error
7075
statusCode = http.StatusInternalServerError // 500

pkg/throttle/check_result.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package throttle
22

33
import (
4-
"github.com/github/freno/pkg/base"
54
"net/http"
5+
6+
"github.com/github/freno/pkg/base"
67
)
78

89
// CheckResult is the result for an app inquiring on a metric. It also exports as JSON via the API

vendor/github.com/patrickmn/go-cache/cache.go

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ github.com/boltdb/bolt
1010
# github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
1111
## explicit; go 1.12
1212
github.com/bradfitz/gomemcache/memcache
13+
# github.com/davecgh/go-spew v1.1.0
14+
## explicit
15+
github.com/davecgh/go-spew/spew
1316
# github.com/go-sql-driver/mysql v1.6.0
1417
## explicit; go 1.10
1518
github.com/go-sql-driver/mysql
@@ -36,10 +39,16 @@ github.com/outbrain/golib/tests
3639
# github.com/patrickmn/go-cache v2.1.0+incompatible
3740
## explicit
3841
github.com/patrickmn/go-cache
42+
# github.com/pmezard/go-difflib v1.0.0
43+
## explicit
44+
github.com/pmezard/go-difflib/difflib
3945
# github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563
4046
## explicit
4147
github.com/rcrowley/go-metrics
4248
github.com/rcrowley/go-metrics/exp
49+
# github.com/stretchr/testify v1.3.0
50+
## explicit
51+
github.com/stretchr/testify/assert
4352
# golang.org/x/sys v0.1.0
4453
## explicit; go 1.17
4554
golang.org/x/sys/unix

0 commit comments

Comments
 (0)