@@ -86,8 +86,8 @@ type JSONGateResolver struct {
86
86
var (
87
87
buildCount = stats .NewCounter ("JsonDiscoveryBuild" , "JSON host discovery rebuilt the host list" )
88
88
unchangedCount = stats .NewCounter ("JsonDiscoveryUnchanged" , "JSON host discovery parsed and determined no change to the file" )
89
- affinityCount = stats .NewCountersWithSingleLabel ("JsonDiscoveryHostAffinity" , "Count of hosts returned from discovery by AZ affinity" , "affinity" )
90
- poolTypeCount = stats .NewCountersWithSingleLabel ("JsonDiscoveryHostPoolType" , "Count of hosts returned from discovery by pool type" , "type" )
89
+ affinityCount = stats .NewGaugesWithSingleLabel ("JsonDiscoveryHostAffinity" , "Count of hosts returned from discovery by AZ affinity" , "affinity" )
90
+ poolTypeCount = stats .NewGaugesWithSingleLabel ("JsonDiscoveryHostPoolType" , "Count of hosts returned from discovery by pool type" , "type" )
91
91
)
92
92
93
93
func RegisterJSONGateResolver (
@@ -173,7 +173,11 @@ func (b *JSONGateResolverBuilder) start() error {
173
173
fileStat = checkFileStat
174
174
175
175
contentsChanged , err := b .parse ()
176
- if err != nil || ! contentsChanged {
176
+ if err != nil {
177
+ log .Error (err )
178
+ continue
179
+ }
180
+ if ! contentsChanged {
177
181
unchangedCount .Add (1 )
178
182
continue
179
183
}
@@ -217,6 +221,7 @@ func (b *JSONGateResolverBuilder) parse() (bool, error) {
217
221
return false , fmt .Errorf ("error parsing JSON discovery file %s: %v" , b .jsonPath , err )
218
222
}
219
223
224
+ var targets []targetHost
220
225
for _ , host := range hosts {
221
226
address , hasAddress := host [b .addressField ]
222
227
port , hasPort := host [b .portField ]
@@ -257,8 +262,9 @@ func (b *JSONGateResolverBuilder) parse() (bool, error) {
257
262
return false , fmt .Errorf ("error parsing JSON discovery file %s: port field %s has invalid value %v" , b .jsonPath , b .portField , port )
258
263
}
259
264
260
- b . targets = append (b . targets , targetHost {fmt .Sprintf ("%s:%s" , address , port ), poolType .(string ), affinity .(string )})
265
+ targets = append (targets , targetHost {fmt .Sprintf ("%s:%s" , address , port ), poolType .(string ), affinity .(string )})
261
266
}
267
+ b .targets = targets
262
268
263
269
return true , nil
264
270
}
@@ -319,11 +325,11 @@ func (b *JSONGateResolverBuilder) update(r *JSONGateResolver) {
319
325
}
320
326
}
321
327
if unknown != 0 {
322
- affinityCount .Add ("unknown" , unknown )
328
+ affinityCount .Set ("unknown" , unknown )
323
329
}
324
- affinityCount .Add ("local" , local )
325
- affinityCount .Add ("remote" , remote )
326
- poolTypeCount .Add (r .poolType , int64 (len (targets )))
330
+ affinityCount .Set ("local" , local )
331
+ affinityCount .Set ("remote" , remote )
332
+ poolTypeCount .Set (r .poolType , int64 (len (targets )))
327
333
328
334
log .V (100 ).Infof ("updated targets for %s to %v (local %d / remote %d)" , r .target .URL .String (), targets , local , remote )
329
335
0 commit comments