Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PD config incompatible when retrieving dashboard address #638

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/golang/protobuf v1.3.4
github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.4
github.com/jeremywohl/flatten v1.0.1
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/joomcode/errorx v1.0.1
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80s
github.com/jackc/pgx v3.6.1+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
github.com/jeremywohl/flatten v1.0.1 h1:LrsxmB3hfwJuE+ptGOijix1PIfOoKLJ3Uee/mzbgtrs=
github.com/jeremywohl/flatten v1.0.1/go.mod h1:4AmD/VxjWcI5SRB0n6szE2A6s2fsNHDLO0nAlMHgfLQ=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jinzhu/gorm v1.9.12/go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
Expand Down
16 changes: 13 additions & 3 deletions pkg/cluster/api/pdapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"sort"
"time"

"github.com/jeremywohl/flatten"
"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
pdserverapi "github.com/pingcap/pd/v4/server/api"
pdserverconfig "github.com/pingcap/pd/v4/server/config"
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
"github.com/pingcap/tiup/pkg/logger/log"
"github.com/pingcap/tiup/pkg/utils"
Expand Down Expand Up @@ -232,7 +232,9 @@ func (pc *PDClient) GetMembers() (*pdpb.GetMembersResponse, error) {
func (pc *PDClient) GetDashboardAddress() (string, error) {
endpoints := pc.getEndpoints(pdConfigURI)

pdConfig := pdserverconfig.Config{}
// We don't use the `github.com/pingcap/pd/v4/server/config` directly because
// there is compatible issue: https://github.com/pingcap/tiup/issues/637
pdConfig := map[string]interface{}{}

_, err := tryURLs(endpoints, func(endpoint string) ([]byte, error) {
body, err := pc.httpClient.Get(endpoint)
Expand All @@ -242,12 +244,20 @@ func (pc *PDClient) GetDashboardAddress() (string, error) {

return body, json.Unmarshal(body, &pdConfig)
})
if err != nil {
return "", errors.AddStack(err)
}

cfg, err := flatten.Flatten(pdConfig, "", flatten.DotStyle)
if err != nil {
return "", errors.AddStack(err)
}

return pdConfig.PDServerCfg.DashboardAddress, nil
addr, ok := cfg["pd-server.dashboard-address"].(string)
if !ok {
return "", errors.New("cannot found dashboard address")
}
return addr, nil
}

// EvictPDLeader evicts the PD leader
Expand Down