Skip to content

Commit

Permalink
Merge pull request #172 from XiaoMi/dev
Browse files Browse the repository at this point in the history
增加登录 capability 设置
make 时,增加 git dirty 检测
make 时,增加 git 版本记录
优化连接池,动态更改连接数量至 [capacity, maxCapacity] 之间
允许 gaea 登录版本配置修改
  • Loading branch information
xiyangxixian authored Sep 29, 2021
2 parents 5ffb307 + 3eb444d commit 9604848
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ bin
logs
.coverage.*
.vscode
.idea
57 changes: 56 additions & 1 deletion cc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ type ListNamespaceResp struct {
Data []string `json:"data"`
}

// return names of all namespace
// @Summary 返回所有namespace名称
// @Description 获取集群名称, 返回所有namespace名称, 未传入为默认集群
// @Produce json
// @Param cluster header string false "cluster name"
// @Success 200 {object} ListNamespaceResp
// @Security BasicAuth
// @Router /api/cc/namespace/list [get]
func (s *Server) listNamespace(c *gin.Context) {
var err error
r := &ListNamespaceResp{RetHeader: &RetHeader{RetCode: -1, RetMessage: ""}}
Expand Down Expand Up @@ -109,6 +115,15 @@ type QueryNamespaceResp struct {
Data []*models.Namespace `json:"data"`
}

// @Summary 返回namespace配置详情, 已废弃
// @Description 获取集群名称, 返回多个指定namespace配置详情, 未传入为默认集群, 已废弃
// @Accept json
// @Produce json
// @Param cluster header string false "cluster name"
// @Param names body json true "{"names":["namespace_1","namespace_2"]}"
// @Success 200 {object} QueryNamespaceResp
// @Security BasicAuth
// @Router /api/cc/namespace [get]
func (s *Server) queryNamespace(c *gin.Context) {
var err error
var req QueryReq
Expand Down Expand Up @@ -136,6 +151,14 @@ func (s *Server) queryNamespace(c *gin.Context) {
return
}

// @Summary 返回namespace配置详情
// @Description 获取集群名称, 返回指定namespace配置详情, 未传入为默认集群
// @Produce json
// @Param cluster header string false "cluster name"
// @Param name path string true "namespace Name"
// @Success 200 {object} QueryNamespaceResp
// @Security BasicAuth
// @Router /api/cc/namespace/detail/{name} [get]
func (s *Server) detailNamespace(c *gin.Context) {
var err error
var names []string
Expand Down Expand Up @@ -164,6 +187,15 @@ func (s *Server) detailNamespace(c *gin.Context) {
return
}

// @Summary 创建修改namespace配置
// @Description 获取集群名称, 根据json body创建或修改namespace配置, 未传入为默认集群
// @Accept json
// @Produce json
// @Param cluster header string false "cluster name"
// @Param name body json true "namespace"
// @Success 200 {object} RetHeader
// @Security BasicAuth
// @Router /api/cc/namespace/modify [put]
func (s *Server) modifyNamespace(c *gin.Context) {
var err error
var namespace models.Namespace
Expand All @@ -190,6 +222,14 @@ func (s *Server) modifyNamespace(c *gin.Context) {
return
}

// @Summary 删除namespace配置
// @Description 获取集群名称, 根据namespace name删除namespace, 未传入为默认集群
// @Produce json
// @Param cluster header string false "cluster name"
// @Param name path string true "namespace name"
// @Success 200 {object} RetHeader
// @Security BasicAuth
// @Router /api/cc/namespace/delete/{name} [put]
func (s *Server) delNamespace(c *gin.Context) {
var err error
h := &RetHeader{RetCode: -1, RetMessage: ""}
Expand Down Expand Up @@ -219,6 +259,14 @@ type sqlFingerprintResp struct {
SlowSQLs map[string]string `json:"slow_sqls"`
}

// @Summary 获取namespce慢SQL、错误SQL
// @Description 获取集群名称, 根据namespace name获取该namespce慢SQL、错误SQL, 未传入为默认集群
// @Produce json
// @Param cluster header string false "cluster name"
// @Param name path string true "namespace name"
// @Success 200 {object} sqlFingerprintResp
// @Security BasicAuth
// @Router /api/cc/namespace/sqlfingerprint/{name} [get]
func (s *Server) sqlFingerprint(c *gin.Context) {
var err error
r := &sqlFingerprintResp{RetHeader: &RetHeader{RetCode: -1, RetMessage: ""}}
Expand Down Expand Up @@ -246,6 +294,13 @@ type proxyConfigFingerprintResp struct {
Data map[string]string `json:"data"` // key: ip:port value: md5 of config
}

// @Summary 获取集群管理地址
// @Description 获取集群名称, 返回集群管理地址, 未传入为默认集群
// @Produce json
// @Param cluster header string false "cluster name"
// @Success 200 {object} proxyConfigFingerprintResp
// @Security BasicAuth
// @Router /api/cc/proxy/config/fingerprint [get]
func (s *Server) proxyConfigFingerprint(c *gin.Context) {
var err error
r := &proxyConfigFingerprintResp{RetHeader: &RetHeader{RetCode: -1, RetMessage: ""}}
Expand Down
18 changes: 15 additions & 3 deletions core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var (
buildHost = "unknown"
buildStatus = "unknown"
buildTime = "unknown"
buildBranch = "unknown"
buildGitDirty = "0"
)

// BuildInfo describes version information about the binary build.
Expand All @@ -39,6 +41,8 @@ type BuildInfo struct {
GolangVersion string `json:"golang_version"`
BuildStatus string `json:"status"`
BuildTime string `json:"time"`
BuildBranch string `json:"build_branch"`
BuildGitDirty string `json:"build_git_dirty"`
}

var (
Expand All @@ -54,13 +58,15 @@ var (
// user@host-<version>-<git revision>-<build status>
// ```
func (b BuildInfo) String() string {
return fmt.Sprintf("%v@%v-%v-%v-%v-%v",
return fmt.Sprintf("%v@%v-%v-%v-%v-%v-%v-%v",
b.User,
b.Host,
b.Version,
b.GitRevision,
b.BuildStatus,
b.BuildTime)
b.BuildTime,
b.BuildBranch,
b.BuildGitDirty)
}

// LongForm returns a multi-line version information
Expand All @@ -81,14 +87,18 @@ User: %v@%v
GolangVersion: %v
BuildStatus: %v
BuildTime: %v
BuildBranch: %v
BuildGitDirty: %v
`,
b.Version,
b.GitRevision,
b.User,
b.Host,
b.GolangVersion,
b.BuildStatus,
b.BuildTime)
b.BuildTime,
b.BuildBranch,
b.BuildGitDirty)
}

func init() {
Expand All @@ -100,5 +110,7 @@ func init() {
GolangVersion: runtime.Version(),
BuildStatus: buildStatus,
BuildTime: buildTime,
BuildBranch: buildBranch,
BuildGitDirty: buildGitDirty,
}
}
3 changes: 3 additions & 0 deletions etc/gaea.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ stats_interval=10

;encrypt key
encrypt_key=1234abcd5678efg*

;server_version
server_version=5.6.20-gaea
8 changes: 7 additions & 1 deletion gen_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ else
tree_status="Modified"
fi

# Check for git branch and git dirty
BRANCH=$(git rev-parse --abbrev-ref HEAD)
GIT_DIRTY=$(git diff --no-ext-diff 2> /dev/null | wc -l)

# XXX This needs to be updated to accomodate tags added after building, rather than prior to builds
RELEASE_TAG=$(git describe --match '[0-9]*\.[0-9]*\.[0-9]*' --exact-match --tags 2> /dev/null || echo "")

Expand All @@ -26,10 +30,12 @@ elif [[ -n ${MY_VERSION} ]]; then
VERSION="${MY_VERSION}"
fi

# used by pkg/version
# used by core/version
echo buildVersion "${VERSION}"
echo buildGitRevision "${BUILD_GIT_REVISION}"
echo buildUser "$(whoami)"
echo buildHost "$(hostname -f)"
echo buildStatus "${tree_status}"
echo buildTime "$(date +%Y-%m-%d--%T)"
echo buildBranch "${BRANCH}"
echo buildGitDirty "${GIT_DIRTY}"
2 changes: 2 additions & 0 deletions models/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type Proxy struct {
StatsInterval int `ini:"stats_interval"` // set stats interval of connect pool

EncryptKey string `ini:"encrypt_key"`

ServerVersion string `ini:"server_version"`
}

// ParseProxyConfigFromFile parser proxy config from file
Expand Down
65 changes: 64 additions & 1 deletion proxy/server/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func (s *AdminServer) registerURL() {
})
}

// @Summary 获取proxy prometheus指标信息
// @Description 获取gaea proxy prometheus指标信息
// @Security BasicAuth
// @Router /api/metric/metrics [get]
func (s *AdminServer) registerMetric() {
metricGroup := s.engine.Group("/api/metric", gin.BasicAuth(gin.Accounts{s.adminUser: s.adminPassword}))
for path, handler := range s.proxy.manager.GetStatisticManager().GetHandlers() {
Expand Down Expand Up @@ -254,10 +258,22 @@ func (s *AdminServer) unregisterProxy() error {
return nil
}

// @Summary 获取proxy admin接口状态
// @Description 获取proxy admin接口状态
// @Success 200 {string} string "OK"
// @Security BasicAuth
// @Router /api/proxy/ping [get]
func (s *AdminServer) ping(c *gin.Context) {
c.JSON(http.StatusOK, "OK")
}

// @Summary prepare namespace配置
// @Description 通过管理接口, 二阶段提交, prepare namespace配置
// @Produce json
// @Param name path string true "namespace name"
// @Success 200 {string} string "OK"
// @Security BasicAuth
// @Router /api/proxy/config/prepare/{name} [put]
func (s *AdminServer) prepareConfig(c *gin.Context) {
name := strings.TrimSpace(c.Param("name"))
if name == "" {
Expand All @@ -275,6 +291,13 @@ func (s *AdminServer) prepareConfig(c *gin.Context) {
c.JSON(http.StatusOK, "OK")
}

// @Summary commit namespace配置
// @Description 通过管理接口, 二阶段提交, commit namespace配置, 使etcd配置生效
// @Produce json
// @Param name path string true "namespace name"
// @Success 200 {string} string "OK"
// @Security BasicAuth
// @Router /api/proxy/config/commit/{name} [put]
func (s *AdminServer) commitConfig(c *gin.Context) {
name := strings.TrimSpace(c.Param("name"))
if name == "" {
Expand All @@ -289,6 +312,13 @@ func (s *AdminServer) commitConfig(c *gin.Context) {
c.JSON(http.StatusOK, "OK")
}

// @Summary 删除namespace配置
// @Description 通过管理接口删除指定namespace配置
// @Produce json
// @Param name path string true "namespace name"
// @Success 200 {string} string "OK"
// @Security BasicAuth
// @Router /api/proxy/config/delete/{name} [put]
func (s *AdminServer) deleteNamespace(c *gin.Context) {
name := strings.TrimSpace(c.Param("name"))
if name == "" {
Expand All @@ -304,11 +334,23 @@ func (s *AdminServer) deleteNamespace(c *gin.Context) {
c.JSON(http.StatusOK, "OK")
}

// @Summary 返回配置指纹
// @Description 返回配置指纹, 指纹随配置变化而变化
// @Produce json
// @Success 200 {string} string "Config Fingerprint"
// @Security BasicAuth
// @Router /api/proxy/config/fingerprint [get]
func (s *AdminServer) configFingerprint(c *gin.Context) {
c.JSON(http.StatusOK, s.proxy.manager.ConfigFingerprint())
}

// getNamespaceSessionSQLFingerprint return namespace sql fingerprint information
// @Summary 获取Porxy 慢SQL、错误SQL信息
// @Description 通过管理接口获取Porxy 慢SQL、错误SQL信息
// @Produce json
// @Param namespace path string true "namespace name"
// @Success 200 {object} SQLFingerprint
// @Security BasicAuth
// @Router /api/proxy/stats/sessionsqlfingerprint/{namespace} [get]
func (s *AdminServer) getNamespaceSessionSQLFingerprint(c *gin.Context) {
ns := strings.TrimSpace(c.Param("namespace"))
namespace := s.proxy.manager.GetNamespace(ns)
Expand All @@ -324,6 +366,13 @@ func (s *AdminServer) getNamespaceSessionSQLFingerprint(c *gin.Context) {
c.JSON(http.StatusOK, ret)
}

// @Summary 获取后端节点慢SQL、错误SQL信息
// @Description 通过管理接口获取后端节点慢SQL、错误SQL信息
// @Produce json
// @Param namespace path string true "namespace name"
// @Success 200 {object} SQLFingerprint
// @Security BasicAuth
// @Router /api/proxy/stats/backendsqlfingerprint/{namespace} [get]
func (s *AdminServer) getNamespaceBackendSQLFingerprint(c *gin.Context) {
ns := strings.TrimSpace(c.Param("namespace"))
namespace := s.proxy.manager.GetNamespace(ns)
Expand All @@ -339,6 +388,13 @@ func (s *AdminServer) getNamespaceBackendSQLFingerprint(c *gin.Context) {
c.JSON(http.StatusOK, ret)
}

// @Summary 清空Porxy节点慢SQL、错误SQL信息
// @Description 通过管理接口清空Porxy慢SQL、错误SQL信息
// @Produce json
// @Param namespace path string true "namespace name"
// @Success 200 {object} SQLFingerprint
// @Security BasicAuth
// @Router /api/proxy/stats/sessionsqlfingerprint/{namespace} [delete]
func (s *AdminServer) clearNamespaceSessionSQLFingerprint(c *gin.Context) {
ns := strings.TrimSpace(c.Param("namespace"))
namespace := s.proxy.manager.GetNamespace(ns)
Expand All @@ -353,6 +409,13 @@ func (s *AdminServer) clearNamespaceSessionSQLFingerprint(c *gin.Context) {
c.JSON(http.StatusOK, "OK")
}

// @Summary 清空后端节点慢SQL、错误SQL信息
// @Description 通过管理接口清空后端节点慢SQL、错误SQL信息
// @Produce json
// @Param namespace path string true "namespace name"
// @Success 200 {object} SQLFingerprint
// @Security BasicAuth
// @Router /api/proxy/stats/backendsqlfingerprint/{namespace} [delete]
func (s *AdminServer) clearNamespaceBackendSQLFingerprint(c *gin.Context) {
ns := strings.TrimSpace(c.Param("namespace"))
namespace := s.proxy.manager.GetNamespace(ns)
Expand Down
Loading

0 comments on commit 9604848

Please sign in to comment.