-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release v2023.05.08.1 [skip pd_pr] (#1523)
* distinguish tiflash_compute node (#1513) * pkg: add resource manager api (#1511) Signed-off-by: husharp <jinhao.hu@pingcap.com> * slowquery: fix 500 when parsing binary plan fails (#1518) Signed-off-by: mornyx <mornyx.z@gmail.com> * feat: implement resource manager app (#1514) * fix: fix monitoring doc ref link for tidb-dashboard op (#1520) * fix: hide capacity warning if estimate ru fails (#1521) * refine: add tidb and tikv cpu quota for resource manager (#1522) * update version: 2023.05.08.1 --------- Signed-off-by: husharp <jinhao.hu@pingcap.com> Signed-off-by: mornyx <mornyx.z@gmail.com> Co-authored-by: guo-shaoge <shaoge1994@163.com> Co-authored-by: Hu# <ihusharp@gmail.com> Co-authored-by: Yexiang Zhang <mornyx.z@gmail.com>
- Loading branch information
1 parent
c90c070
commit d6e0218
Showing
45 changed files
with
1,843 additions
and
52 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2023 PingCAP, Inc. Licensed under Apache-2.0. | ||
|
||
package resourcemanager | ||
|
||
import "go.uber.org/fx" | ||
|
||
var Module = fx.Options( | ||
fx.Provide(newService), | ||
fx.Invoke(registerRouter), | ||
) |
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 |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// Copyright 2023 PingCAP, Inc. Licensed under Apache-2.0. | ||
|
||
package resourcemanager | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
"go.uber.org/fx" | ||
|
||
"github.com/pingcap/tidb-dashboard/pkg/apiserver/user" | ||
"github.com/pingcap/tidb-dashboard/pkg/apiserver/utils" | ||
"github.com/pingcap/tidb-dashboard/pkg/tidb" | ||
"github.com/pingcap/tidb-dashboard/util/featureflag" | ||
"github.com/pingcap/tidb-dashboard/util/rest" | ||
) | ||
|
||
type ServiceParams struct { | ||
fx.In | ||
TiDBClient *tidb.Client | ||
} | ||
|
||
type Service struct { | ||
FeatureResourceManager *featureflag.FeatureFlag | ||
|
||
params ServiceParams | ||
} | ||
|
||
func newService(p ServiceParams, ff *featureflag.Registry) *Service { | ||
return &Service{params: p, FeatureResourceManager: ff.Register("resource_manager", ">= 7.1.0")} | ||
} | ||
|
||
func registerRouter(r *gin.RouterGroup, auth *user.AuthService, s *Service) { | ||
endpoint := r.Group("/resource_manager") | ||
endpoint.Use( | ||
auth.MWAuthRequired(), | ||
s.FeatureResourceManager.VersionGuard(), | ||
utils.MWConnectTiDB(s.params.TiDBClient), | ||
) | ||
{ | ||
endpoint.GET("/config", s.GetConfig) | ||
endpoint.GET("/information", s.GetInformation) | ||
endpoint.GET("/calibrate/hardware", s.GetCalibrateByHardware) | ||
endpoint.GET("/calibrate/actual", s.GetCalibrateByActual) | ||
} | ||
} | ||
|
||
type GetConfigResponse struct { | ||
Enable bool `json:"enable" gorm:"column:tidb_enable_resource_control"` | ||
} | ||
|
||
// @Summary Get Resource Control enable config | ||
// @Router /resource_manager/config [get] | ||
// @Security JwtAuth | ||
// @Success 200 {object} GetConfigResponse | ||
// @Failure 401 {object} rest.ErrorResponse | ||
// @Failure 500 {object} rest.ErrorResponse | ||
func (s *Service) GetConfig(c *gin.Context) { | ||
db := utils.GetTiDBConnection(c) | ||
resp := &GetConfigResponse{} | ||
err := db.Raw("SELECT @@GLOBAL.tidb_enable_resource_control as tidb_enable_resource_control").Find(resp).Error | ||
if err != nil { | ||
rest.Error(c, err) | ||
return | ||
} | ||
c.JSON(http.StatusOK, resp) | ||
} | ||
|
||
type ResourceInfoRowDef struct { | ||
Name string `json:"name" gorm:"column:NAME"` | ||
RuPerSec string `json:"ru_per_sec" gorm:"column:RU_PER_SEC"` | ||
Priority string `json:"priority" gorm:"column:PRIORITY"` | ||
Burstable string `json:"burstable" gorm:"column:BURSTABLE"` | ||
} | ||
|
||
// @Summary Get Information of Resource Groups | ||
// @Router /resource_manager/information [get] | ||
// @Security JwtAuth | ||
// @Success 200 {object} []ResourceInfoRowDef | ||
// @Failure 401 {object} rest.ErrorResponse | ||
// @Failure 500 {object} rest.ErrorResponse | ||
func (s *Service) GetInformation(c *gin.Context) { | ||
db := utils.GetTiDBConnection(c) | ||
var cfg []ResourceInfoRowDef | ||
err := db.Table("INFORMATION_SCHEMA.RESOURCE_GROUPS").Scan(&cfg).Error | ||
if err != nil { | ||
rest.Error(c, err) | ||
return | ||
} | ||
c.JSON(http.StatusOK, cfg) | ||
} | ||
|
||
type CalibrateResponse struct { | ||
EstimatedCapacity int `json:"estimated_capacity" gorm:"column:QUOTA"` | ||
} | ||
|
||
// @Summary Get calibrate of Resource Groups by hardware deployment | ||
// @Router /resource_manager/calibrate/hardware [get] | ||
// @Param workload query string true "workload" default("tpcc") | ||
// @Security JwtAuth | ||
// @Success 200 {object} CalibrateResponse | ||
// @Failure 401 {object} rest.ErrorResponse | ||
// @Failure 500 {object} rest.ErrorResponse | ||
func (s *Service) GetCalibrateByHardware(c *gin.Context) { | ||
w := c.Query("workload") | ||
if w == "" { | ||
rest.Error(c, rest.ErrBadRequest.New("workload cannot be empty")) | ||
return | ||
} | ||
|
||
db := utils.GetTiDBConnection(c) | ||
resp := &CalibrateResponse{} | ||
err := db.Raw(fmt.Sprintf("calibrate resource workload %s", w)).Scan(resp).Error | ||
if err != nil { | ||
rest.Error(c, err) | ||
return | ||
} | ||
c.JSON(http.StatusOK, resp) | ||
} | ||
|
||
type GetCalibrateByActualRequest struct { | ||
StartTime int64 `json:"start_time" form:"start_time"` | ||
EndTime int64 `json:"end_time" form:"end_time"` | ||
} | ||
|
||
// @Summary Get calibrate of Resource Groups by actual workload | ||
// @Router /resource_manager/calibrate/actual [get] | ||
// @Param q query GetCalibrateByActualRequest true "Query" | ||
// @Security JwtAuth | ||
// @Success 200 {object} CalibrateResponse | ||
// @Failure 401 {object} rest.ErrorResponse | ||
// @Failure 500 {object} rest.ErrorResponse | ||
func (s *Service) GetCalibrateByActual(c *gin.Context) { | ||
var req GetCalibrateByActualRequest | ||
if err := c.ShouldBindQuery(&req); err != nil { | ||
rest.Error(c, rest.ErrBadRequest.NewWithNoMessage()) | ||
return | ||
} | ||
|
||
startTime := time.Unix(req.StartTime, 0).Format("2006-01-02 15:04:05") | ||
endTime := time.Unix(req.EndTime, 0).Format("2006-01-02 15:04:05") | ||
|
||
db := utils.GetTiDBConnection(c) | ||
resp := &CalibrateResponse{} | ||
err := db.Raw(fmt.Sprintf("calibrate resource start_time '%s' end_time '%s'", startTime, endTime)).Scan(resp).Error | ||
if err != nil { | ||
rest.Error(c, err) | ||
return | ||
} | ||
c.JSON(http.StatusOK, resp) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# This file specifies the TiDB Dashboard internal version, which will be printed in `--version` | ||
# and UI. In release branch, changing this file will result in publishing a new version and tag. | ||
7.0.0 | ||
2023.05.08.1 | ||
|
Oops, something went wrong.