Skip to content

Commit

Permalink
executor: add tiproxy in cluster_config (pingcap#47785)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox committed Oct 31, 2023
1 parent 926a1e5 commit 56e0959
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/executor/memtable_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ func fetchClusterConfig(sctx sessionctx.Context, nodeTypes, nodeAddrs set.String
url = fmt.Sprintf("%s://%s%s", util.InternalHTTPSchema(), statusAddr, pdapi.Config)
case "tikv", "tidb", "tiflash":
url = fmt.Sprintf("%s://%s/config", util.InternalHTTPSchema(), statusAddr)
case "tiproxy":
url = fmt.Sprintf("%s://%s/api/admin/config?format=json", util.InternalHTTPSchema(), statusAddr)
default:
ch <- result{err: errors.Errorf("currently we do not support get config from node type: %s(%s)", typ, address)}
return
Expand Down
28 changes: 22 additions & 6 deletions pkg/executor/memtable_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ func TestTiDBClusterConfig(t *testing.T) {
router.Handle(pdapi.Config, fn.Wrap(mockConfig))
// TiDB/TiKV config
router.Handle("/config", fn.Wrap(mockConfig))
// Tiproxy config
router.Handle("/api/admin/config", fn.Wrap(mockConfig))

// mock servers
var servers []string
for _, typ := range []string{"tidb", "tikv", "tiflash", "pd"} {
for _, typ := range []string{"tidb", "tikv", "tiflash", "tiproxy", "pd"} {
for _, server := range testServers {
servers = append(servers, strings.Join([]string{typ, server.address, server.address}, ","))
}
Expand Down Expand Up @@ -195,6 +197,15 @@ func TestTiDBClusterConfig(t *testing.T) {
"tiflash key1 value1",
"tiflash key2.nest1 n-value1",
"tiflash key2.nest2 n-value2",
"tiproxy key1 value1",
"tiproxy key2.nest1 n-value1",
"tiproxy key2.nest2 n-value2",
"tiproxy key1 value1",
"tiproxy key2.nest1 n-value1",
"tiproxy key2.nest2 n-value2",
"tiproxy key1 value1",
"tiproxy key2.nest1 n-value1",
"tiproxy key2.nest2 n-value2",
"pd key1 value1",
"pd key2.nest1 n-value1",
"pd key2.nest2 n-value2",
Expand All @@ -207,7 +218,7 @@ func TestTiDBClusterConfig(t *testing.T) {
))
warnings := tk.Session().GetSessionVars().StmtCtx.GetWarnings()
require.Len(t, warnings, 0, fmt.Sprintf("unexpected warnings: %+v", warnings))
require.Equal(t, int32(12), requestCounter)
require.Equal(t, int32(15), requestCounter)

// TODO: we need remove it when index usage is GA.
rs := tk.MustQuery("show config").Rows()
Expand All @@ -224,7 +235,7 @@ func TestTiDBClusterConfig(t *testing.T) {

// type => server index => row
rows := map[string][][]string{}
for _, typ := range []string{"tidb", "tikv", "tiflash", "pd"} {
for _, typ := range []string{"tidb", "tikv", "tiflash", "tiproxy", "pd"} {
for _, server := range testServers {
rows[typ] = append(rows[typ], []string{
fmt.Sprintf("%s %s key1 value1", typ, server.address),
Expand All @@ -247,7 +258,7 @@ func TestTiDBClusterConfig(t *testing.T) {
}{
{
sql: "select * from information_schema.cluster_config",
reqCount: 12,
reqCount: 15,
rows: flatten(
rows["tidb"][0],
rows["tidb"][1],
Expand All @@ -258,6 +269,9 @@ func TestTiDBClusterConfig(t *testing.T) {
rows["tiflash"][0],
rows["tiflash"][1],
rows["tiflash"][2],
rows["tiproxy"][0],
rows["tiproxy"][1],
rows["tiproxy"][2],
rows["pd"][0],
rows["pd"][1],
rows["pd"][2],
Expand All @@ -277,11 +291,12 @@ func TestTiDBClusterConfig(t *testing.T) {
},
{
sql: "select * from information_schema.cluster_config where type='pd' or instance='" + testServers[0].address + "'",
reqCount: 12,
reqCount: 15,
rows: flatten(
rows["tidb"][0],
rows["tikv"][0],
rows["tiflash"][0],
rows["tiproxy"][0],
rows["pd"][0],
rows["pd"][1],
rows["pd"][2],
Expand Down Expand Up @@ -357,11 +372,12 @@ func TestTiDBClusterConfig(t *testing.T) {
{
sql: fmt.Sprintf(`select * from information_schema.cluster_config where instance='%s'`,
testServers[0].address),
reqCount: 4,
reqCount: 5,
rows: flatten(
rows["tidb"][0],
rows["tikv"][0],
rows["tiflash"][0],
rows["tiproxy"][0],
rows["pd"][0],
),
},
Expand Down

0 comments on commit 56e0959

Please sign in to comment.