Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
26 changes: 25 additions & 1 deletion cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/tikv/pd/pkg/dashboard"
"github.com/tikv/pd/pkg/errs"
resource_manager "github.com/tikv/pd/pkg/mcs/resourcemanager/server"
router "github.com/tikv/pd/pkg/mcs/router/server"
scheduling "github.com/tikv/pd/pkg/mcs/scheduling/server"
tso "github.com/tikv/pd/pkg/mcs/tso/server"
Expand All @@ -49,6 +50,7 @@ import (
const (
apiMode = "api"
tsoMode = "tso"
rmMode = "resource-manager"
serviceModeEnv = "PD_SERVICE_MODE"
)

Expand All @@ -73,9 +75,10 @@ func main() {
func NewServiceCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "services <mode>",
Short: "Run services, for example, tso, scheduling, router",
Short: "Run services, for example, tso, scheduling, router, resource_manager",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "Run services, for example, tso, scheduling, router, resource_manager",
Short: "Run services, for example, tso, scheduling, router, resource-manager",

}
cmd.AddCommand(NewTSOServiceCommand())
cmd.AddCommand(NewResourceManagerServiceCommand())
cmd.AddCommand(NewSchedulingServiceCommand())
cmd.AddCommand(NewRouterServiceCommand())
cmd.AddCommand(NewPDServiceCommand())
Expand Down Expand Up @@ -124,6 +127,27 @@ func NewSchedulingServiceCommand() *cobra.Command {
return cmd
}

// NewResourceManagerServiceCommand returns the resource manager service command.
func NewResourceManagerServiceCommand() *cobra.Command {
cmd := &cobra.Command{
Use: rmMode,
Short: "Run the resource manager service",
Run: resource_manager.CreateServerWrapper,
}
cmd.Flags().StringP("name", "", "", "human-readable name for this resource manager member")
cmd.Flags().BoolP("version", "V", false, "print version information and exit")
cmd.Flags().StringP("config", "", "", "config file")
cmd.Flags().StringP("backend-endpoints", "", "", "url for etcd client")
cmd.Flags().StringP("listen-addr", "", "", "listen address for resource management service")
cmd.Flags().StringP("advertise-listen-addr", "", "", "advertise urls for listen address (default '${listen-addr}')")
cmd.Flags().StringP("cacert", "", "", "path of file that contains list of trusted TLS CAs")
cmd.Flags().StringP("cert", "", "", "path of file that contains X509 certificate in PEM format")
cmd.Flags().StringP("key", "", "", "path of file that contains X509 key in PEM format")
cmd.Flags().StringP("log-level", "L", "", "log level: debug, info, warn, error, fatal (default 'info')")
cmd.Flags().StringP("log-file", "", "", "log file path")
return cmd
}

// NewRouterServiceCommand returns the router service command.
func NewRouterServiceCommand() *cobra.Command {
cmd := &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/discovery/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Discover(cli *clientv3.Client, serviceName string) ([]string, error) {
// GetMSMembers returns all the members of the specified service name.
func GetMSMembers(serviceName string, client *clientv3.Client) ([]ServiceRegistryEntry, error) {
switch serviceName {
case constant.TSOServiceName, constant.SchedulingServiceName:
case constant.TSOServiceName, constant.SchedulingServiceName, constant.ResourceManagerServiceName:
servicePath := keypath.ServicePath(serviceName)
resps, err := kv.NewSlowLogTxn(client).Then(clientv3.OpGet(servicePath, clientv3.WithPrefix())).Commit()
if err != nil {
Expand Down
25 changes: 25 additions & 0 deletions pkg/mcs/resourcemanager/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import (
"github.com/gin-gonic/gin"

rmpb "github.com/pingcap/kvproto/pkg/resource_manager"
"github.com/pingcap/log"

"github.com/tikv/pd/pkg/errs"
rmserver "github.com/tikv/pd/pkg/mcs/resourcemanager/server"
"github.com/tikv/pd/pkg/mcs/utils"
"github.com/tikv/pd/pkg/utils/apiutil"
"github.com/tikv/pd/pkg/utils/apiutil/multiservicesapi"
"github.com/tikv/pd/pkg/utils/logutil"
"github.com/tikv/pd/pkg/utils/reflectutil"
)

Expand Down Expand Up @@ -84,10 +86,17 @@ func NewService(srv *rmserver.Service) *Service {
apiHandlerEngine: apiHandlerEngine,
root: endpoint,
}
s.RegisterAdminRouter()
s.RegisterRouter()
return s
}

// RegisterAdminRouter registers the router of the TSO admin handler.
func (s *Service) RegisterAdminRouter() {
router := s.root.Group("admin")
router.PUT("/log", changeLogLevel)
}

// RegisterRouter registers the router of the service.
func (s *Service) RegisterRouter() {
configEndpoint := s.root.Group("/config")
Expand All @@ -112,6 +121,22 @@ func (s *Service) handler() http.Handler {
})
}

func changeLogLevel(c *gin.Context) {
svr := c.MustGet(multiservicesapi.ServiceContextKey).(*rmserver.Service)
var level string
if err := c.Bind(&level); err != nil {
c.String(http.StatusBadRequest, err.Error())
return
}

if err := svr.SetLogLevel(level); err != nil {
c.String(http.StatusBadRequest, err.Error())
return
}
log.SetLevel(logutil.StringToZapLogLevel(level))
c.String(http.StatusOK, "The log level is updated.")
}

// postResourceGroup
//
// @Tags ResourceManager
Expand Down
3 changes: 3 additions & 0 deletions pkg/mcs/resourcemanager/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/pingcap/failpoint"
"github.com/pingcap/log"
"github.com/pingcap/metering_sdk/config"

"github.com/tikv/pd/pkg/mcs/utils/constant"
"github.com/tikv/pd/pkg/utils/configutil"
Expand Down Expand Up @@ -88,6 +89,8 @@ type Config struct {
LeaderLease int64 `toml:"lease" json:"lease"`

Controller ControllerConfig `toml:"controller" json:"controller"`

Metering config.MeteringConfig `toml:"metering" json:"metering"`
}

// ControllerConfig is the configuration of the resource manager controller which includes some option for client needed.
Expand Down
3 changes: 2 additions & 1 deletion pkg/mcs/resourcemanager/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func (dummyRestService) ServeHTTP(w http.ResponseWriter, _ *http.Request) {

// Service is the gRPC service for resource manager.
type Service struct {
ctx context.Context
ctx context.Context
*Server
manager *Manager
// settings
}
Expand Down
Loading