Skip to content

Commit 17cbc51

Browse files
committed
reinitalise targets when parsing host list
1 parent 5ea7ded commit 17cbc51

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

go/vt/vtgateproxy/discovery.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ type JSONGateResolver struct {
8686
var (
8787
buildCount = stats.NewCounter("JsonDiscoveryBuild", "JSON host discovery rebuilt the host list")
8888
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")
9191
)
9292

9393
func RegisterJSONGateResolver(
@@ -173,7 +173,11 @@ func (b *JSONGateResolverBuilder) start() error {
173173
fileStat = checkFileStat
174174

175175
contentsChanged, err := b.parse()
176-
if err != nil || !contentsChanged {
176+
if err != nil {
177+
log.Error(err)
178+
continue
179+
}
180+
if !contentsChanged {
177181
unchangedCount.Add(1)
178182
continue
179183
}
@@ -217,6 +221,7 @@ func (b *JSONGateResolverBuilder) parse() (bool, error) {
217221
return false, fmt.Errorf("error parsing JSON discovery file %s: %v", b.jsonPath, err)
218222
}
219223

224+
var targets []targetHost
220225
for _, host := range hosts {
221226
address, hasAddress := host[b.addressField]
222227
port, hasPort := host[b.portField]
@@ -257,8 +262,9 @@ func (b *JSONGateResolverBuilder) parse() (bool, error) {
257262
return false, fmt.Errorf("error parsing JSON discovery file %s: port field %s has invalid value %v", b.jsonPath, b.portField, port)
258263
}
259264

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)})
261266
}
267+
b.targets = targets
262268

263269
return true, nil
264270
}
@@ -319,11 +325,11 @@ func (b *JSONGateResolverBuilder) update(r *JSONGateResolver) {
319325
}
320326
}
321327
if unknown != 0 {
322-
affinityCount.Add("unknown", unknown)
328+
affinityCount.Set("unknown", unknown)
323329
}
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)))
327333

328334
log.V(100).Infof("updated targets for %s to %v (local %d / remote %d)", r.target.URL.String(), targets, local, remote)
329335

0 commit comments

Comments
 (0)