-
Notifications
You must be signed in to change notification settings - Fork 720
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
mcs: support config http interface in scheduling server #7278
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cbdae92
mcs: support config http interface in scheduling server
lhy1024 08927e5
Merge branch 'master' of github.com:tikv/pd into sche-redirect9
lhy1024 bd12406
move and fix test
lhy1024 4baba6d
add more test
lhy1024 e3bf609
make test stable
lhy1024 d6c89cd
remove uncommon interfaces
lhy1024 ab8bc53
fix
lhy1024 ab06849
fix lint
lhy1024 41f35c2
make test stable
lhy1024 adc7879
add more test
lhy1024 5261c00
Merge branch 'master' into sche-redirect9
ti-chi-bot[bot] b8f59a1
fix test
lhy1024 860ea5c
Merge branch 'master' into sche-redirect9
ti-chi-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
"github.com/pingcap/errcode" | ||
"github.com/pingcap/errors" | ||
"github.com/pingcap/log" | ||
"github.com/tikv/pd/pkg/errs" | ||
"github.com/tikv/pd/pkg/mcs/utils" | ||
sc "github.com/tikv/pd/pkg/schedule/config" | ||
"github.com/tikv/pd/pkg/utils/apiutil" | ||
"github.com/tikv/pd/pkg/utils/jsonutil" | ||
|
@@ -60,7 +62,24 @@ | |
// @Router /config [get] | ||
func (h *confHandler) GetConfig(w http.ResponseWriter, r *http.Request) { | ||
cfg := h.svr.GetConfig() | ||
cfg.Schedule.MaxMergeRegionKeys = cfg.Schedule.GetMaxMergeRegionKeys() | ||
if h.svr.IsAPIServiceMode() { | ||
b, err := h.GetSchedulingServerConfig("config") | ||
if err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
var configSchedulingServer config.Config | ||
err = json.Unmarshal(b, &configSchedulingServer) | ||
if err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
cfg.Schedule = configSchedulingServer.Schedule | ||
cfg.Replication = configSchedulingServer.Replication | ||
// TODO: will we support config/store? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: will we support config/store? |
||
} else { | ||
cfg.Schedule.MaxMergeRegionKeys = cfg.Schedule.GetMaxMergeRegionKeys() | ||
} | ||
h.rd.JSON(w, http.StatusOK, cfg) | ||
} | ||
|
||
|
@@ -301,6 +320,21 @@ | |
// @Success 200 {object} sc.ScheduleConfig | ||
// @Router /config/schedule [get] | ||
func (h *confHandler) GetScheduleConfig(w http.ResponseWriter, r *http.Request) { | ||
if h.svr.IsAPIServiceMode() { | ||
b, err := h.GetSchedulingServerConfig("config/schedule") | ||
if err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
var cfg sc.ScheduleConfig | ||
err = json.Unmarshal(b, &cfg) | ||
if err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
h.rd.JSON(w, http.StatusOK, cfg) | ||
return | ||
} | ||
cfg := h.svr.GetScheduleConfig() | ||
cfg.MaxMergeRegionKeys = cfg.GetMaxMergeRegionKeys() | ||
h.rd.JSON(w, http.StatusOK, cfg) | ||
|
@@ -364,6 +398,21 @@ | |
// @Success 200 {object} sc.ReplicationConfig | ||
// @Router /config/replicate [get] | ||
func (h *confHandler) GetReplicationConfig(w http.ResponseWriter, r *http.Request) { | ||
if h.svr.IsAPIServiceMode() { | ||
b, err := h.GetSchedulingServerConfig("config/replicate") | ||
if err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
var cfg sc.ReplicationConfig | ||
err = json.Unmarshal(b, &cfg) | ||
if err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
h.rd.JSON(w, http.StatusOK, cfg) | ||
return | ||
} | ||
h.rd.JSON(w, http.StatusOK, h.svr.GetReplicationConfig()) | ||
} | ||
|
||
|
@@ -505,3 +554,24 @@ | |
func (h *confHandler) GetPDServerConfig(w http.ResponseWriter, r *http.Request) { | ||
h.rd.JSON(w, http.StatusOK, h.svr.GetPDServerConfig()) | ||
} | ||
|
||
func (h *confHandler) GetSchedulingServerConfig(path string) ([]byte, error) { | ||
addr, ok := h.svr.GetServicePrimaryAddr(h.svr.Context(), utils.SchedulingServiceName) | ||
if !ok { | ||
return nil, errs.ErrNotFoundSchedulingAddr.FastGenByArgs() | ||
} | ||
url := fmt.Sprintf("%s/scheduling/api/v1/%s", addr, path) | ||
req, err := http.NewRequest(http.MethodGet, url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp, err := h.svr.GetHTTPClient().Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode != http.StatusOK { | ||
return nil, errs.ErrSchedulingServer.FastGenByArgs(resp.StatusCode) | ||
} | ||
return io.ReadAll(resp.Body) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if we need these APIs, I think they are barely used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because api server has the same interface. Maybe we also call "/config" in api server for these interfaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can cancel "/config/schedule" and "/config/replicate", which are in "/config". But we should keep "config/store", otherwise we have no way to get store config, which is not in "/config".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can put store config into "/config" and add a new struct for it. How about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, make sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or only remove "/config/store", I found there is no "/config/store" in api server