2023-03-28 19:39:22 +01:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 09:12:13 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 19:39:22 +01:00
|
|
|
|
2020-09-09 16:37:43 -04:00
|
|
|
package router
|
|
|
|
|
2021-12-06 09:55:54 -06:00
|
|
|
import (
|
|
|
|
"github.com/hashicorp/consul/agent/metadata"
|
|
|
|
"github.com/hashicorp/consul/types"
|
|
|
|
)
|
2020-09-09 16:37:43 -04:00
|
|
|
|
2020-09-14 16:16:44 -04:00
|
|
|
// ServerTracker is called when Router is notified of a server being added or
|
|
|
|
// removed.
|
2020-09-09 16:37:43 -04:00
|
|
|
type ServerTracker interface {
|
2020-09-14 16:16:44 -04:00
|
|
|
NewRebalancer(dc string) func()
|
2021-12-06 09:55:54 -06:00
|
|
|
AddServer(types.AreaID, *metadata.Server)
|
|
|
|
RemoveServer(types.AreaID, *metadata.Server)
|
2020-09-09 16:37:43 -04:00
|
|
|
}
|
|
|
|
|
2020-09-14 16:16:44 -04:00
|
|
|
// Rebalancer is called periodically to re-order the servers so that the load on the
|
|
|
|
// servers is evenly balanced.
|
|
|
|
type Rebalancer func()
|
|
|
|
|
2020-09-09 16:37:43 -04:00
|
|
|
// NoOpServerTracker is a ServerTracker that does nothing. Used when gRPC is not
|
|
|
|
// enabled.
|
|
|
|
type NoOpServerTracker struct{}
|
|
|
|
|
2020-09-14 16:16:44 -04:00
|
|
|
// Rebalance does nothing
|
|
|
|
func (NoOpServerTracker) NewRebalancer(string) func() {
|
|
|
|
return func() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddServer does nothing
|
2021-12-06 09:55:54 -06:00
|
|
|
func (NoOpServerTracker) AddServer(types.AreaID, *metadata.Server) {}
|
2020-09-09 16:37:43 -04:00
|
|
|
|
2020-09-14 16:16:44 -04:00
|
|
|
// RemoveServer does nothing
|
2021-12-06 09:55:54 -06:00
|
|
|
func (NoOpServerTracker) RemoveServer(types.AreaID, *metadata.Server) {}
|