@@ -187,13 +187,13 @@ type errIndicator struct {
187187type FactorHealth struct {
188188 snapshot map [string ]healthBackendSnapshot
189189 indicators []errIndicator
190- mr metricsreader.MetricsReader
190+ mr metricsreader.MetricsQuerier
191191 bitNum int
192192 migrationsPerSecond float64
193193 lg * zap.Logger
194194}
195195
196- func NewFactorHealth (mr metricsreader.MetricsReader , lg * zap.Logger ) * FactorHealth {
196+ func NewFactorHealth (mr metricsreader.MetricsQuerier , lg * zap.Logger ) * FactorHealth {
197197 return & FactorHealth {
198198 mr : mr ,
199199 snapshot : make (map [string ]healthBackendSnapshot ),
@@ -203,7 +203,7 @@ func NewFactorHealth(mr metricsreader.MetricsReader, lg *zap.Logger) *FactorHeal
203203 }
204204}
205205
206- func initErrIndicator (mr metricsreader.MetricsReader ) []errIndicator {
206+ func initErrIndicator (mr metricsreader.MetricsQuerier ) []errIndicator {
207207 indicators := make ([]errIndicator , 0 , len (errDefinitions ))
208208 for _ , def := range errDefinitions {
209209 indicator := errIndicator {
@@ -268,7 +268,7 @@ func (fh *FactorHealth) UpdateScore(backends []scoredBackend) {
268268 fh .updateSnapshot (backends )
269269 }
270270 for i := range backends {
271- score := fh .caclErrScore (backends [i ].Addr ())
271+ score := fh .caclErrScore (backends [i ].ID ())
272272 backends [i ].addScore (score , fh .bitNum )
273273 }
274274}
@@ -281,6 +281,7 @@ func (fh *FactorHealth) updateSnapshot(backends []scoredBackend) {
281281 now := time .Now ()
282282 for _ , backend := range backends {
283283 addr := backend .Addr ()
284+ key := backend .ID ()
284285 // Get the current value range.
285286 updatedTime , valueRange , indicator , failureValue , totalValue := time.Time {}, valueRangeNormal , "" , 0.0 , 0.0
286287 for _ , ind := range fh .indicators {
@@ -310,7 +311,7 @@ func (fh *FactorHealth) updateSnapshot(backends []scoredBackend) {
310311 }
311312 }
312313 // If the metric is unavailable, try to reuse the latest one.
313- snapshot := fh .snapshot [addr ]
314+ snapshot := fh .snapshot [key ]
314315 if updatedTime .IsZero () {
315316 continue
316317 }
@@ -335,7 +336,7 @@ func (fh *FactorHealth) updateSnapshot(backends []scoredBackend) {
335336 zap .Float64 ("balance_count" , balanceCount ),
336337 zap .Int ("conn_score" , backend .ConnScore ()))
337338 }
338- fh .snapshot [addr ] = healthBackendSnapshot {
339+ fh .snapshot [key ] = healthBackendSnapshot {
339340 updatedTime : updatedTime ,
340341 valueRange : valueRange ,
341342 indicator : indicator ,
@@ -391,9 +392,9 @@ func calcValueRange(failureSample, totalSample *model.Sample, indicator errIndic
391392 return failureValue , totalValue , valueRangeMid
392393}
393394
394- func (fh * FactorHealth ) caclErrScore (addr string ) int {
395+ func (fh * FactorHealth ) caclErrScore (key string ) int {
395396 // If the backend has no metrics (not in snapshot), take it as healthy.
396- return int (fh .snapshot [addr ].valueRange )
397+ return int (fh .snapshot [key ].valueRange )
397398}
398399
399400func (fh * FactorHealth ) ScoreBitNum () int {
@@ -402,9 +403,9 @@ func (fh *FactorHealth) ScoreBitNum() int {
402403
403404func (fh * FactorHealth ) BalanceCount (from , to scoredBackend ) (BalanceAdvice , float64 , []zap.Field ) {
404405 // Only migrate connections when one is valueRangeNormal and the other is valueRangeAbnormal.
405- fromScore := fh .caclErrScore (from .Addr ())
406- toScore := fh .caclErrScore (to .Addr ())
407- snapshot := fh .snapshot [from .Addr ()]
406+ fromScore := fh .caclErrScore (from .ID ())
407+ toScore := fh .caclErrScore (to .ID ())
408+ snapshot := fh .snapshot [from .ID ()]
408409 var fields []zap.Field
409410 if snapshot .indicator != "" {
410411 fields = append (fields ,
0 commit comments