Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
reverseproxy: Remove circuitbreaker module (see #3331)
Moving to https://github.com/caddyserver/circuitbreaker Nobody was using it anyway -- it works well, but something got fumbled in a refactoring *months* ago. Turns out that we forgot the interface guards AND botched a method name (my bad) - Ok() should have been OK(). So it would always have thrown a runtime panic if it tried to be loaded. The module itself works well, but obviously nobody used it because nobody reported the error. Fixing this while we move it to the new repo. Removing this removes the last Bazaar/Launchpad dependency (I think).
Matthew Holt committed
May 1, 2020 at 19:47 UTC
a507a5bbc72b70cba4e252b8ec7cbffdc09b4a86
4 files changed
+2
-172
go.mod
-1
@@ -24,7 +24,6 @@ require (
24
github.com/smallstep/certificates v0.14.2
25
github.com/smallstep/cli v0.14.2
26
github.com/smallstep/truststore v0.9.5
27
- github.com/vulcand/oxy v1.1.0
27
github.com/yuin/goldmark v1.1.28
28
github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691
29
go.uber.org/zap v1.14.1
go.sum
-13
@@ -161,8 +161,6 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
161
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
162
github.com/cloudflare/cloudflare-go v0.10.2 h1:VBodKICVPnwmDxstcW3biKcDSpFIfS/RELUXsZSBYK4=
163
github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY=
164
-github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd h1:qMd81Ts1T2OTKmB4acZcyKaMtRnY5Y44NuXGX2GFJ1w=
165
-github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
164
github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA=
165
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
166
github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
@@ -375,10 +373,8 @@ github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
373
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
374
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
375
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
378
-github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
376
github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE=
377
github.com/gostaticanalysis/analysisutil v0.0.3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE=
381
-github.com/gravitational/trace v0.0.0-20190726142706-a535a178675f/go.mod h1:RvdOUHE4SHqR3oXlFFKnGzms8a5dugHygGw1bqDstYI=
378
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
379
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
380
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE=
@@ -477,11 +473,6 @@ github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm
473
github.com/magiconair/properties v1.7.6/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
474
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
475
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
480
-github.com/mailgun/minheap v0.0.0-20170619185613-3dbe6c6bf55f/go.mod h1:V3EvCedtJTvUYzJF2GZMRB0JMlai+6cBu3VCTQz33GQ=
481
-github.com/mailgun/multibuf v0.0.0-20150714184110-565402cd71fb/go.mod h1:E0vRBBIQUHcRtmL/oR6w/jehh4FJqJFxe86gBnw9gXc=
482
-github.com/mailgun/timetools v0.0.0-20141028012446-7e6055773c51 h1:Kg/NPZLLC3aAFr1YToMs98dbCdhootQ1hZIvZU28hAQ=
483
-github.com/mailgun/timetools v0.0.0-20141028012446-7e6055773c51/go.mod h1:RYmqHbhWwIz3z9eVmQ2rx82rulEMG0t+Q1bzfc9DYN4=
484
-github.com/mailgun/ttlmap v0.0.0-20170619185759-c1c17f74874f/go.mod h1:8heskWJ5c0v5J9WH89ADhyal1DOZcayll8fSbhB+/9A=
476
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
477
github.com/manifoldco/promptui v0.3.1/go.mod h1:zoCNXiJnyM03LlBgTsWv8mq28s7aTC71UgKasqRJHww=
478
github.com/manifoldco/promptui v0.7.0 h1:3l11YT8tm9MnwGFQ4kETwkzpAwY2Jt9lCrumCUW4+z4=
@@ -774,9 +765,6 @@ github.com/valyala/quicktemplate v1.2.0/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOV
765
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
766
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
767
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
777
-github.com/vulcand/oxy v1.1.0 h1:DbBijGo1+6cFqR9jarkMxasdj0lgWwrrFtue6ijek4Q=
778
-github.com/vulcand/oxy v1.1.0/go.mod h1:ADiMYHi8gkGl2987yQIzDRoXZilANF4WtKaQ92OppKY=
779
-github.com/vulcand/predicate v1.1.0/go.mod h1:mlccC5IRBoc2cIFmCB8ZM62I3VDb6p2GXESMHa3CnZg=
768
github.com/vultr/govultr v0.1.4 h1:UnNMixYFVO0p80itc8PcweoVENyo1PasfvwKhoasR9U=
769
github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA=
770
github.com/weppos/publicsuffix-go v0.4.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k=
@@ -1203,7 +1191,6 @@ howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqp
1191
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
1192
howett.net/plist v0.0.0-20200225050739-77e249a2e2ba h1:HiEs/6jQFMHpFqsdPBAk3ieVcsSS8IV+D93f43UuDPo=
1193
howett.net/plist v0.0.0-20200225050739-77e249a2e2ba/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
1206
-launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
1194
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
1195
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
1196
mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34/go.mod h1:H6SUd1XjIs+qQCyskXg5OFSrilMRUkD8ePJpHKDPaeY=
modules/caddyhttp/reverseproxy/circuitbreaker.go
deleted
-157
@@ -1,157 +0,0 @@
1
-// Copyright 2015 Matthew Holt and The Caddy Authors
2
-//
3
-// Licensed under the Apache License, Version 2.0 (the "License");
4
-// you may not use this file except in compliance with the License.
5
-// You may obtain a copy of the License at
6
-//
7
-// http://www.apache.org/licenses/LICENSE-2.0
8
-//
9
-// Unless required by applicable law or agreed to in writing, software
10
-// distributed under the License is distributed on an "AS IS" BASIS,
11
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
-// See the License for the specific language governing permissions and
13
-// limitations under the License.
14
-
15
-package reverseproxy
16
-
17
-import (
18
- "fmt"
19
- "sync/atomic"
20
- "time"
21
-
22
- "github.com/caddyserver/caddy/v2"
23
- "github.com/vulcand/oxy/memmetrics"
24
-)
25
-
26
-func init() {
27
- caddy.RegisterModule(internalCircuitBreaker{})
28
-}
29
-
30
-// internalCircuitBreaker implements circuit breaking functionality
31
-// for requests within this process over a sliding time window.
32
-type internalCircuitBreaker struct {
33
- tripped int32
34
- cbFactor int32
35
- threshold float64
36
- metrics *memmetrics.RTMetrics
37
- tripTime time.Duration
38
- Config
39
-}
40
-
41
-// CaddyModule returns the Caddy module information.
42
-func (internalCircuitBreaker) CaddyModule() caddy.ModuleInfo {
43
- return caddy.ModuleInfo{
44
- ID: "http.reverse_proxy.circuit_breakers.internal",
45
- New: func() caddy.Module { return new(internalCircuitBreaker) },
46
- }
47
-}
48
-
49
-// Provision sets up a configured circuit breaker.
50
-func (c *internalCircuitBreaker) Provision(ctx caddy.Context) error {
51
- f, ok := typeCB[c.Factor]
52
- if !ok {
53
- return fmt.Errorf("type is not defined")
54
- }
55
-
56
- if c.TripTime == "" {
57
- c.TripTime = defaultTripTime
58
- }
59
-
60
- tw, err := time.ParseDuration(c.TripTime)
61
- if err != nil {
62
- return fmt.Errorf("cannot parse trip_time duration, %v", err.Error())
63
- }
64
-
65
- mt, err := memmetrics.NewRTMetrics()
66
- if err != nil {
67
- return fmt.Errorf("cannot create new metrics: %v", err.Error())
68
- }
69
-
70
- c.cbFactor = f
71
- c.tripTime = tw
72
- c.threshold = c.Threshold
73
- c.metrics = mt
74
- c.tripped = 0
75
-
76
- return nil
77
-}
78
-
79
-// Ok returns whether the circuit breaker is tripped or not.
80
-func (c *internalCircuitBreaker) Ok() bool {
81
- tripped := atomic.LoadInt32(&c.tripped)
82
- return tripped == 0
83
-}
84
-
85
-// RecordMetric records a response status code and execution time of a request. This function should be run in a separate goroutine.
86
-func (c *internalCircuitBreaker) RecordMetric(statusCode int, latency time.Duration) {
87
- c.metrics.Record(statusCode, latency)
88
- c.checkAndSet()
89
-}
90
-
91
-// Ok checks our metrics to see if we should trip our circuit breaker, or if the fallback duration has completed.
92
-func (c *internalCircuitBreaker) checkAndSet() {
93
- var isTripped bool
94
-
95
- switch c.cbFactor {
96
- case factorErrorRatio:
97
- // check if amount of network errors exceed threshold over sliding window, threshold for comparison should be < 1.0 i.e. .5 = 50th percentile
98
- if c.metrics.NetworkErrorRatio() > c.threshold {
99
- isTripped = true
100
- }
101
- case factorLatency:
102
- // check if threshold in milliseconds is reached and trip
103
- hist, err := c.metrics.LatencyHistogram()
104
- if err != nil {
105
- return
106
- }
107
-
108
- l := hist.LatencyAtQuantile(c.threshold)
109
- if l.Nanoseconds()/int64(time.Millisecond) > int64(c.threshold) {
110
- isTripped = true
111
- }
112
- case factorStatusCodeRatio:
113
- // check ratio of error status codes of sliding window, threshold for comparison should be < 1.0 i.e. .5 = 50th percentile
114
- if c.metrics.ResponseCodeRatio(500, 600, 0, 600) > c.threshold {
115
- isTripped = true
116
- }
117
- }
118
-
119
- if isTripped {
120
- c.metrics.Reset()
121
- atomic.AddInt32(&c.tripped, 1)
122
-
123
- // wait tripTime amount before allowing operations to resume.
124
- t := time.NewTimer(c.tripTime)
125
- <-t.C
126
-
127
- atomic.AddInt32(&c.tripped, -1)
128
- }
129
-}
130
-
131
-// Config represents the configuration of a circuit breaker.
132
-type Config struct {
133
- // The threshold over sliding window that would trip the circuit breaker
134
- Threshold float64 `json:"threshold"`
135
- // Possible values: latency, error_ratio, and status_ratio. It
136
- // defaults to latency.
137
- Factor string `json:"factor"`
138
- // How long to wait after the circuit is tripped before allowing operations to resume.
139
- // The default is 5s.
140
- TripTime string `json:"trip_time"`
141
-}
142
-
143
-const (
144
- factorLatency = iota + 1
145
- factorErrorRatio
146
- factorStatusCodeRatio
147
- defaultTripTime = "5s"
148
-)
149
-
150
-var (
151
- // typeCB handles converting a Config Factor value to the internal circuit breaker types.
152
- typeCB = map[string]int32{
153
- "latency": factorLatency,
154
- "error_ratio": factorErrorRatio,
155
- "status_ratio": factorStatusCodeRatio,
156
- }
157
-)
modules/caddyhttp/reverseproxy/healthchecks.go
+2
-1
@@ -113,7 +113,8 @@ type PassiveHealthChecks struct {
113
114
// CircuitBreaker is a type that can act as an early-warning
115
// system for the health checker when backends are getting
116
-// overloaded.
116
+// overloaded. This interface is still experimental and is
117
+// subject to change.
118
type CircuitBreaker interface {
119
OK() bool
120
RecordMetric(statusCode int, latency time.Duration)