@@ -56,11 +56,16 @@ func (opt Options) String() string {
56
56
return fmt .Sprintf ("[Hostname: %s Headers: %v Path: %s Port: %d Interval: %s Timeout: %s]" , opt .Hostname , opt .Headers , opt .Path , opt .Port , opt .Interval , opt .Timeout )
57
57
}
58
58
59
+ type backendURL struct {
60
+ url * url.URL
61
+ weight int
62
+ }
63
+
59
64
// BackendConfig HealthCheck configuration for a backend
60
65
type BackendConfig struct {
61
66
Options
62
67
name string
63
- disabledURLs []* url. URL
68
+ disabledURLs []backendURL
64
69
}
65
70
66
71
func (b * BackendConfig ) newRequest (serverURL * url.URL ) (* http.Request , error ) {
@@ -135,21 +140,22 @@ func (hc *HealthCheck) execute(ctx context.Context, backend *BackendConfig) {
135
140
136
141
func (hc * HealthCheck ) checkBackend (backend * BackendConfig ) {
137
142
enabledURLs := backend .LB .Servers ()
138
- var newDisabledURLs []* url. URL
143
+ var newDisabledURLs []backendURL
139
144
// FIXME re enable metrics
140
145
for _ , disableURL := range backend .disabledURLs {
141
146
// FIXME serverUpMetricValue := float64(0)
142
- if err := checkHealth (disableURL , backend ); err == nil {
143
- log .Warnf ("Health check up: Returning to server list. Backend: %q URL: %q" , backend .name , disableURL .String ())
144
- if err = backend .LB .UpsertServer (disableURL , roundrobin .Weight (1 )); err != nil {
147
+ if err := checkHealth (disableURL .url , backend ); err == nil {
148
+ log .Warnf ("Health check up: Returning to server list. Backend: %q URL: %q Weight: %d" ,
149
+ backend .name , disableURL .url .String (), disableURL .weight )
150
+ if err = backend .LB .UpsertServer (disableURL .url , roundrobin .Weight (disableURL .weight )); err != nil {
145
151
log .Error (err )
146
152
}
147
153
// FIXME serverUpMetricValue = 1
148
154
} else {
149
- log .Warnf ("Health check still failing. Backend: %q URL: %q Reason: %s" , backend .name , disableURL .String (), err )
155
+ log .Warnf ("Health check still failing. Backend: %q URL: %q Reason: %s" , backend .name , disableURL .url . String (), err )
150
156
newDisabledURLs = append (newDisabledURLs , disableURL )
151
157
}
152
- // FIXME labelValues := []string{"backend", backend.name, "url", disableURL .String()}
158
+ // FIXME labelValues := []string{"backend", backend.name, "url", backendurl.url .String()}
153
159
// FIXME hc.metrics.BackendServerUpGauge().With(labelValues...).Set(serverUpMetricValue)
154
160
}
155
161
backend .disabledURLs = newDisabledURLs
@@ -158,11 +164,20 @@ func (hc *HealthCheck) checkBackend(backend *BackendConfig) {
158
164
for _ , enableURL := range enabledURLs {
159
165
// FIXME serverUpMetricValue := float64(1)
160
166
if err := checkHealth (enableURL , backend ); err != nil {
161
- log .Warnf ("Health check failed: Remove from server list. Backend: %q URL: %q Reason: %s" , backend .name , enableURL .String (), err )
167
+ weight := 1
168
+ rr , ok := backend .LB .(* roundrobin.RoundRobin )
169
+ if ok {
170
+ var gotWeight bool
171
+ weight , gotWeight = rr .ServerWeight (enableURL )
172
+ if ! gotWeight {
173
+ weight = 1
174
+ }
175
+ }
176
+ log .Warnf ("Health check failed: Remove from server list. Backend: %q URL: %q Weight: %d Reason: %s" , backend .name , enableURL .String (), weight , err )
162
177
if err := backend .LB .RemoveServer (enableURL ); err != nil {
163
178
log .Error (err )
164
179
}
165
- backend .disabledURLs = append (backend .disabledURLs , enableURL )
180
+ backend .disabledURLs = append (backend .disabledURLs , backendURL { enableURL , weight } )
166
181
// FIXME serverUpMetricValue = 0
167
182
}
168
183
// FIXME labelValues := []string{"backend", backend.name, "url", enableURL.String()}
0 commit comments