func (m *Manager) checkAddress() {
	dashboardAddress := m.srv.GetPersistOptions().GetDashboardAddress()
	switch dashboardAddress {
	case "auto":
		if m.isLeader && len(m.members) > 0 {
			m.setNewAddress()
		}
		return
	case "none":
		m.redirector.SetAddress("")
		m.stopService()
		return
	default:
		if m.isLeader && m.needResetAddress(dashboardAddress) {
			m.setNewAddress()
			return
		}
	}
	m.redirector.SetAddress(dashboardAddress)
	clientUrls := m.srv.GetMemberInfo().GetClientUrls()
	if len(clientUrls) > 0 && clientUrls[0] == dashboardAddress {
		m.startService()
	} else {
		m.stopService()
	}
}
checkDashboardAddress checks if the dashboard service needs to change due to dashboard address is changed.
package adapter
import (
	"context"
	"sort"
	"sync"
	"time"
	"github.com/pingcap/kvproto/pkg/pdpb"
	"github.com/pingcap/tidb-dashboard/pkg/apiserver"
	"github.com/pingcap/log"
	"github.com/tikv/pd/pkg/errs"
	"github.com/tikv/pd/pkg/logutil"
	"github.com/tikv/pd/server"
	"github.com/tikv/pd/server/cluster"
)
var (
	CheckInterval = time.Second
)
type Manager struct {
	ctx    context.Context
	cancel context.CancelFunc
	wg     sync.WaitGroup
	srv        *server.Server
	service    *apiserver.Service
	redirector *Redirector
	isLeader bool
	members  []*pdpb.Member
}
func NewManager(srv *server.Server, s *apiserver.Service, redirector *Redirector) *Manager {
	return &Manager{
		srv:        srv,
		service:    s,
		redirector: redirector,
	}
}
func (m *Manager) Start() {
	m.ctx, m.cancel = context.WithCancel(m.srv.Context())
	m.wg.Add(1)
	m.isLeader = false
	m.members = nil
	go m.serviceLoop()
}
func (m *Manager) Stop() {
	m.cancel()
	m.wg.Wait()
	log.Info("exit dashboard loop")
}
func (m *Manager) serviceLoop() {
	defer logutil.LogPanic()
	defer m.wg.Done()
	ticker := time.NewTicker(CheckInterval)
	defer ticker.Stop()
	for {
		select {
		case <-m.ctx.Done():
			m.stopService()
			return
		case <-ticker.C:
			m.updateInfo()
			m.checkAddress()
		}
	}
}
func (m *Manager) updateInfo() {
	if !m.srv.GetMember().IsLeader() {
		m.isLeader = false
		m.members = nil
		if err := m.srv.GetPersistOptions().Reload(m.srv.GetStorage()); err != nil {
			log.Warn("failed to reload persist options")
		}
		return
	}
	m.isLeader = true
	var err error
	if m.members, err = cluster.GetMembers(m.srv.GetClient()); err != nil {
		log.Warn("failed to get members", errs.ZapError(err))
		m.members = nil
		return
	}
	allHasClientUrls := true
	for _, member := range m.members {
		if len(member.GetClientUrls()) == 0 {
			allHasClientUrls = false
		}
	}
	if !allHasClientUrls {
		log.Warn("failed to get member client urls")
		m.members = nil
	}
}