Skip to content

Commit

Permalink
Release v2023.05.08.1 [skip pd_pr] (#1523)
Browse files Browse the repository at this point in the history
* 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
4 people authored May 8, 2023
1 parent c90c070 commit d6e0218
Show file tree
Hide file tree
Showing 45 changed files with 1,843 additions and 52 deletions.
2 changes: 2 additions & 0 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (

// "github.com/pingcap/tidb-dashboard/pkg/apiserver/__APP_NAME__"
// NOTE: Don't remove above comment line, it is a placeholder for code generator.
resourcemanager "github.com/pingcap/tidb-dashboard/pkg/apiserver/resource_manager"
"github.com/pingcap/tidb-dashboard/pkg/apiserver/slowquery"
"github.com/pingcap/tidb-dashboard/pkg/apiserver/statement"
"github.com/pingcap/tidb-dashboard/pkg/apiserver/user"
Expand Down Expand Up @@ -139,6 +140,7 @@ var Modules = fx.Options(
topsql.Module,
visualplan.Module,
deadlock.Module,
resourcemanager.Module,
)

func (s *Service) Start(ctx context.Context) error {
Expand Down
10 changes: 10 additions & 0 deletions pkg/apiserver/resource_manager/module.go
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),
)
153 changes: 153 additions & 0 deletions pkg/apiserver/resource_manager/service.go
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)
}
12 changes: 7 additions & 5 deletions pkg/apiserver/slowquery/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ func (s *Service) getDetails(c *gin.Context) {
}

// generate binary plan
result.BinaryPlan, err = utils.GenerateBinaryPlanJSON(result.BinaryPlan)
if err != nil {
rest.Error(c, err)
return
}
//
// Due to a kernel bug, the binary plan may fail to parse due to
// encoding issues. Additionally, since the binary plan field is
// not a required field, we can mask this error.
//
// See: https://github.com/pingcap/tidb-dashboard/issues/1515
result.BinaryPlan, _ = utils.GenerateBinaryPlanJSON(result.BinaryPlan)

c.JSON(http.StatusOK, *result)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/topology/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func FetchStoreTopology(pdClient *pd.Client) ([]StoreInfo, []StoreInfo, error) {
for _, store := range stores {
isTiFlash := false
for _, label := range store.Labels {
if label.Key == "engine" && label.Value == "tiflash" {
if label.Key == "engine" && (label.Value == "tiflash" || label.Value == "tiflash_compute") {
isTiFlash = true
}
}
Expand Down
3 changes: 2 additions & 1 deletion release-version
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

Loading

0 comments on commit d6e0218

Please sign in to comment.