4
4
"net/http"
5
5
"strconv"
6
6
"strings"
7
+ "sync/atomic"
7
8
8
9
"github.com/caddyserver/caddy/v2"
9
10
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
@@ -16,9 +17,10 @@ import (
16
17
)
17
18
18
19
type DevxUpstreamsModule struct {
19
- hub * sentry.Hub
20
- logger * zap.Logger
21
- listener * storelistener.Listener
20
+ hub * sentry.Hub
21
+ logger * zap.Logger
22
+ listener * storelistener.Listener
23
+ failureCount * atomic.Int64
22
24
}
23
25
24
26
func init () {
@@ -29,15 +31,18 @@ func init() {
29
31
// CaddyModule returns the Caddy module information.
30
32
func (DevxUpstreamsModule ) CaddyModule () caddy.ModuleInfo {
31
33
return caddy.ModuleInfo {
32
- ID : "http.reverse_proxy.upstreams.devx" ,
33
- New : func () caddy.Module { return new (DevxUpstreamsModule ) },
34
+ ID : "http.reverse_proxy.upstreams.devx" ,
35
+ New : func () caddy.Module {
36
+ return new (DevxUpstreamsModule )
37
+ },
34
38
}
35
39
}
36
40
37
41
func (d * DevxUpstreamsModule ) Provision (ctx caddy.Context ) error {
38
42
// Get logger for the context of this caddy module instance
39
43
d .logger = ctx .Logger (d )
40
44
d .logger .Info ("Provision called" )
45
+ d .failureCount = & atomic.Int64 {}
41
46
return nil
42
47
}
43
48
@@ -60,6 +65,11 @@ func (d *DevxUpstreamsModule) GetUpstreams(r *http.Request) ([]*reverseproxy.Ups
60
65
61
66
// If no upstream was selected log and return error
62
67
if data .UpstreamHost == "" {
68
+ if n := d .failureCount .Add (1 ); n > 10 {
69
+ // FIXME: Shut down and restart listeners if we have several issues in a short period
70
+ d .failureCount .Store (0 )
71
+ }
72
+
63
73
err := upstreamMissingError (data )
64
74
d .logger .Warn (
65
75
"Failed to get upstream" ,
0 commit comments