Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <admin@liudos.us>
  • Loading branch information
lhy1024 committed Nov 7, 2023
1 parent d814868 commit 077f284
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
6 changes: 2 additions & 4 deletions pkg/mcs/scheduling/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package apis

import (
"encoding/hex"
"fmt"
"net/http"
"strconv"
"sync"
Expand Down Expand Up @@ -118,7 +117,6 @@ func NewService(srv *scheserver.Service) *Service {
s.RegisterSchedulersRouter()
s.RegisterCheckersRouter()
s.RegisterHotspotRouter()
s.RegisterConfigRouter()
return s
}

Expand Down Expand Up @@ -188,7 +186,7 @@ func (s *Service) RegisterConfigRouter() {

groups := router.Group("rule_groups")
groups.GET("", getAllGroupConfigs)
groups.GET("/:id", getGroupConfig)
groups.GET("/:id", getRuleGroupConfig)

placementRule := router.Group("placement-rule")
placementRule.GET("", getPlacementRules)
Expand Down Expand Up @@ -892,7 +890,7 @@ func getAllGroupConfigs(c *gin.Context) {
// @Failure 412 {string} string "Placement rules feature is disabled."
// @Failure 500 {string} string "PD server failed to proceed the request."
// @Router /config/rule_groups/{id} [get]
func getGroupConfig(c *gin.Context) {
func getRuleGroupConfig(c *gin.Context) {
handler := c.MustGet(handlerKey).(*handler.Handler)
manager, err := handler.GetRuleManager()
if err == errs.ErrPlacementDisabled {
Expand Down
5 changes: 3 additions & 2 deletions pkg/utils/apiutil/serverapi/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (h *redirector) matchMicroServiceRedirectRules(r *http.Request) (bool, stri
r.URL.Path = strings.TrimRight(r.URL.Path, "/")
for _, rule := range h.microserviceRedirectRules {
if strings.HasPrefix(r.URL.Path, rule.matchPath) && slice.Contains(rule.matchMethods, r.Method) {
origin := r.URL.Path
addr, ok := h.s.GetServicePrimaryAddr(r.Context(), rule.targetServiceName)
if !ok || addr == "" {
log.Warn("failed to get the service primary addr when trying to match redirect rules",
Expand All @@ -134,8 +135,8 @@ func (h *redirector) matchMicroServiceRedirectRules(r *http.Request) (bool, stri
} else {
r.URL.Path = rule.targetPath
}
log.Debug("redirect to micro service", zap.String("path", r.URL.Path), zap.String("target", addr),
zap.String("method", r.Method))
log.Debug("redirect to micro service", zap.String("path", r.URL.Path), zap.String("origin-path", origin),
zap.String("target", addr), zap.String("method", r.Method))
return true, addr
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ func NewHandler(_ context.Context, svr *server.Server) (http.Handler, apiutil.AP
mcs.SchedulingServiceName,
[]string{http.MethodGet}),
serverapi.MicroserviceRedirectRule(
prefix+"/config/rule",
prefix+"/config/rule/",
scheapi.APIPathPrefix+"/config/rule",
mcs.SchedulingServiceName,
[]string{http.MethodGet}),
serverapi.MicroserviceRedirectRule(
prefix+"/config/rule_group",
prefix+"/config/rule_group/",
scheapi.APIPathPrefix+"/config/rule_groups", // Note: this is a typo in the original code
mcs.SchedulingServiceName,
[]string{http.MethodGet}),
Expand Down
10 changes: 7 additions & 3 deletions tests/pdctl/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"os"
"reflect"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -409,9 +410,12 @@ func (suite *configTestSuite) checkPlacementRuleGroups(cluster *tests.TestCluste

// test show
var group placement.RuleGroup
output, err = pdctl.ExecuteCommand(cmd, "-u", pdAddr, "config", "placement-rules", "rule-group", "show", "pd")
re.NoError(err)
re.NoError(json.Unmarshal(output, &group))
testutil.Eventually(re, func() bool { // wait for the config to be synced to the scheduling server
output, err = pdctl.ExecuteCommand(cmd, "-u", pdAddr, "config", "placement-rules", "rule-group", "show", "pd")
re.NoError(err)
return !strings.Contains(string(output), "404")
})
re.NoError(json.Unmarshal(output, &group), string(output))
re.Equal(placement.RuleGroup{ID: "pd"}, group)

// test set
Expand Down

0 comments on commit 077f284

Please sign in to comment.