Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Sep 28, 2023
1 parent 4eb9aea commit 4246086
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 140 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/check.yaml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/pd-docker-image.yaml

This file was deleted.

60 changes: 30 additions & 30 deletions .github/workflows/pd-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
strategy:
fail-fast: true
matrix:
worker_id: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
worker_id: [1]
outputs:
job-total: 13
job-total: 1
steps:
- uses: actions/setup-go@v3
with:
Expand All @@ -48,31 +48,31 @@ jobs:
JOB_COUNT: 10 # 11, 12 13 are for other integrations jobs
run: |
make ci-test-job JOB_COUNT=$(($JOB_COUNT)) JOB_INDEX=$WORKER_ID
mv covprofile covprofile_$WORKER_ID
sed -i "/failpoint_binding/d" covprofile_$WORKER_ID
- name: Upload coverage result ${{ matrix.worker_id }}
uses: actions/upload-artifact@v2
with:
name: cover-reports
path: covprofile_${{ matrix.worker_id }}
report-coverage:
needs: chunks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download chunk report
uses: actions/download-artifact@v2
with:
name: cover-reports
- name: Merge
env:
TOTAL_JOBS: ${{needs.chunks.outputs.job-total}}
run: for i in $(seq 1 $TOTAL_JOBS); do cat covprofile_$i >> covprofile; done
- name: Send coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV }}
file: ./covprofile
flags: unittests
name: codecov-umbrella
# mv covprofile covprofile_$WORKER_ID
# sed -i "/failpoint_binding/d" covprofile_$WORKER_ID
# - name: Upload coverage result ${{ matrix.worker_id }}
# uses: actions/upload-artifact@v2
# with:
# name: cover-reports
# path: covprofile_${{ matrix.worker_id }}
# report-coverage:
# needs: chunks
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Download chunk report
# uses: actions/download-artifact@v2
# with:
# name: cover-reports
# - name: Merge
# env:
# TOTAL_JOBS: ${{needs.chunks.outputs.job-total}}
# run: for i in $(seq 1 $TOTAL_JOBS); do cat covprofile_$i >> covprofile; done
# - name: Send coverage
# uses: codecov/codecov-action@v1
# with:
# token: ${{ secrets.CODECOV }}
# file: ./covprofile
# flags: unittests
# name: codecov-umbrella
17 changes: 0 additions & 17 deletions .github/workflows/tso-consistency-test.yaml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/tso-function-test.yaml

This file was deleted.

10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,8 @@ basic-test: install-tools
@$(FAILPOINT_DISABLE)

ci-test-job: install-tools dashboard-ui
@$(FAILPOINT_ENABLE)
if [[ $(JOB_INDEX) -le 10 ]]; then \
CGO_ENABLED=1 go test -timeout=15m -tags deadlock -race -covermode=atomic -coverprofile=covprofile -coverpkg=./... $(shell ./scripts/ci-subtask.sh $(JOB_COUNT) $(JOB_INDEX)); \
else \
for mod in $(shell ./scripts/ci-subtask.sh $(JOB_COUNT) $(JOB_INDEX)); do cd $$mod && $(MAKE) ci-test-job && cd $(ROOT_PATH) > /dev/null && cat $$mod/covprofile >> covprofile; done; \
fi
CGO_ENABLED=1 go test -v -timeout=15m -tags deadlock -race github.com/tikv/pd/tests/dashboard
@$(FAILPOINT_DISABLE)

TSO_INTEGRATION_TEST_PKGS := $(PD_PKG)/tests/server/tso

Expand Down Expand Up @@ -286,4 +282,4 @@ clean-build:
rm -rf $(BUILD_BIN_PATH)
rm -rf $(GO_TOOLS_BIN_PATH)

.PHONY: clean clean-test clean-build
.PHONY: clean clean-test clean-build
16 changes: 16 additions & 0 deletions pkg/dashboard/adapter/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package adapter

import (
"context"
"go.uber.org/zap"
"sync"
"time"

"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"
"github.com/pingcap/tidb-dashboard/pkg/apiserver"
Expand Down Expand Up @@ -78,10 +80,15 @@ func (m *Manager) serviceLoop() {

ticker := time.NewTicker(CheckInterval)
defer ticker.Stop()
failpoint.Inject("fastCheckAddress", func() {
ticker.Stop()
ticker = time.NewTicker(100 * time.Millisecond)
})

for {
select {
case <-m.ctx.Done():
log.Info("dashboard manager is closed")
m.stopService()
return
case <-ticker.C:
Expand All @@ -94,6 +101,7 @@ func (m *Manager) serviceLoop() {
// updateInfo updates information from the server.
func (m *Manager) updateInfo() {
if !m.srv.GetMember().IsLeader() {
log.Info("dashboard is not leader", zap.String("svr-name", m.srv.Name()))
m.isLeader = false
m.members = nil
if err := m.srv.GetPersistOptions().Reload(m.srv.GetStorage()); err != nil {
Expand All @@ -110,6 +118,7 @@ func (m *Manager) updateInfo() {
m.members = nil
return
}
log.Info("get members", zap.String("svr-name", m.srv.Name()))

for _, member := range m.members {
if len(member.GetClientUrls()) == 0 {
Expand All @@ -123,18 +132,22 @@ func (m *Manager) updateInfo() {
// checkDashboardAddress checks if the dashboard service needs to change due to dashboard address is changed.
func (m *Manager) checkAddress() {
dashboardAddress := m.srv.GetPersistOptions().GetDashboardAddress()
log.Info("check dashboard address", zap.String("svr-name", m.srv.Name()), logutil.ZapRedactString("dashboardAddress", dashboardAddress))
switch dashboardAddress {
case "auto":
log.Info("dashboard address is auto", zap.Int("members", len(m.members)), zap.Bool("isLeader", m.isLeader))
if m.isLeader && len(m.members) > 0 {
m.setNewAddress()
}
return
case "none":
log.Info("dashboard address is none")
m.redirector.SetAddress("")
m.stopService()
return
default:
if m.isLeader && m.needResetAddress(dashboardAddress) {
log.Info("dashboard address is changed")
m.setNewAddress()
return
}
Expand All @@ -144,8 +157,10 @@ func (m *Manager) checkAddress() {

clientUrls := m.srv.GetMemberInfo().GetClientUrls()
if len(clientUrls) > 0 && clientUrls[0] == dashboardAddress {
log.Info("dashboard server is running", zap.String("svr-name", m.srv.Name()), zap.String("svr-addr", m.srv.GetAddr()), zap.Int("clientUrls", len(clientUrls)))
m.startService()
} else {
log.Info("dashboard server is not running", zap.String("svr-name", m.srv.Name()), zap.String("svr-addr", m.srv.GetAddr()), zap.Int("clientUrls", len(clientUrls)))
m.stopService()
}
}
Expand Down Expand Up @@ -199,6 +214,7 @@ func (m *Manager) startService() {

func (m *Manager) stopService() {
if !m.service.IsRunning() {
log.Info("dashboard server is not running by check")
return
}
if err := m.service.Stop(context.Background()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ type PDServerConfig struct {
// RuntimeServices is the running extension services.
RuntimeServices typeutil.StringSlice `toml:"runtime-services" json:"runtime-services"`
// MetricStorage is the cluster metric storage.
// Currently we use prometheus as metric storage, we may use PD/TiKV as metric storage later.
// Currently, we use prometheus as metric storage, we may use PD/TiKV as metric storage later.
MetricStorage string `toml:"metric-storage" json:"metric-storage"`
// There are some values supported: "auto", "none", or a specific address, default: "auto"
DashboardAddress string `toml:"dashboard-address" json:"dashboard-address"`
Expand Down
23 changes: 20 additions & 3 deletions tests/dashboard/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ import (
"github.com/stretchr/testify/suite"
"go.uber.org/goleak"

"github.com/pingcap/failpoint"
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/dashboard"
"github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/server/config"
"github.com/tikv/pd/tests"
"github.com/tikv/pd/tests/pdctl"
pdctlCmd "github.com/tikv/pd/tools/pd-ctl/pdctl"
"go.uber.org/zap"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -69,12 +72,14 @@ func (suite *dashboardTestSuite) TearDownSuite() {
}

func (suite *dashboardTestSuite) TestDashboardRedirect() {
println("TestDashboardRedirect")
suite.testDashboard(false)
}

func (suite *dashboardTestSuite) TestDashboardProxy() {
suite.testDashboard(true)
}
//func (suite *dashboardTestSuite) TestDashboardProxy() {
// println("TestDashboardProxy")
// suite.testDashboard(true)
//}

func (suite *dashboardTestSuite) checkRespCode(url string, code int) {
resp, err := suite.httpClient.Get(url)
Expand All @@ -96,6 +101,8 @@ func (suite *dashboardTestSuite) checkServiceIsStarted(internalProxy bool, serve
for _, srv := range servers {
suite.Equal(dashboardAddress, srv.GetPersistOptions().GetDashboardAddress())
addr := srv.GetAddr()
log.Info("checkServiceIsStarted", zap.String("addr", addr), zap.String("dashboardAddress", dashboardAddress),
zap.String("now", srv.GetPersistOptions().GetDashboardAddress()), zap.Bool("internalProxy", internalProxy))
if addr == dashboardAddress || internalProxy {
suite.checkRespCode(fmt.Sprintf("%s/dashboard/", addr), http.StatusOK)
suite.checkRespCode(fmt.Sprintf("%s/dashboard/api/keyvisual/heatmaps", addr), http.StatusUnauthorized)
Expand All @@ -122,6 +129,11 @@ func (suite *dashboardTestSuite) checkServiceIsStopped(servers map[string]*tests
}

func (suite *dashboardTestSuite) testDashboard(internalProxy bool) {
re := suite.Require()
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/dashboard/adapter/fastCheckAddress", `return(true)`))
defer func() {
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/dashboard/adapter/fastCheckAddress"))
}()
cluster, err := tests.NewTestCluster(suite.ctx, 3, func(conf *config.Config, serverName string) {
conf.Dashboard.InternalProxy = internalProxy
})
Expand All @@ -138,7 +150,9 @@ func (suite *dashboardTestSuite) testDashboard(internalProxy bool) {
leaderAddr := leader.GetAddr()

// auto select node
log.Info("auto select node")
dashboardAddress1 := suite.checkServiceIsStarted(internalProxy, servers, leader)
log.Info("auto select node finished")

// pd-ctl set another addr
var dashboardAddress2 string
Expand All @@ -151,7 +165,10 @@ func (suite *dashboardTestSuite) testDashboard(internalProxy bool) {
args := []string{"-u", leaderAddr, "config", "set", "dashboard-address", dashboardAddress2}
_, err = pdctl.ExecuteCommand(cmd, args...)
suite.NoError(err)

log.Info("ctl check node")
suite.checkServiceIsStarted(internalProxy, servers, leader)
log.Info("ctl check node finished")
suite.Equal(dashboardAddress2, leader.GetServer().GetPersistOptions().GetDashboardAddress())

// pd-ctl set stop
Expand Down

0 comments on commit 4246086

Please sign in to comment.