Skip to content

Commit 9604848

Browse files
authored
Merge pull request #172 from XiaoMi/dev
增加登录 capability 设置 make 时,增加 git dirty 检测 make 时,增加 git 版本记录 优化连接池,动态更改连接数量至 [capacity, maxCapacity] 之间 允许 gaea 登录版本配置修改
2 parents 5ffb307 + 3eb444d commit 9604848

12 files changed

Lines changed: 384 additions & 45 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ bin
44
logs
55
.coverage.*
66
.vscode
7+
.idea

cc/server.go

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ type ListNamespaceResp struct {
8080
Data []string `json:"data"`
8181
}
8282

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

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

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

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

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

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

297+
// @Summary 获取集群管理地址
298+
// @Description 获取集群名称, 返回集群管理地址, 未传入为默认集群
299+
// @Produce json
300+
// @Param cluster header string false "cluster name"
301+
// @Success 200 {object} proxyConfigFingerprintResp
302+
// @Security BasicAuth
303+
// @Router /api/cc/proxy/config/fingerprint [get]
249304
func (s *Server) proxyConfigFingerprint(c *gin.Context) {
250305
var err error
251306
r := &proxyConfigFingerprintResp{RetHeader: &RetHeader{RetCode: -1, RetMessage: ""}}

core/version.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ var (
2828
buildHost = "unknown"
2929
buildStatus = "unknown"
3030
buildTime = "unknown"
31+
buildBranch = "unknown"
32+
buildGitDirty = "0"
3133
)
3234

3335
// BuildInfo describes version information about the binary build.
@@ -39,6 +41,8 @@ type BuildInfo struct {
3941
GolangVersion string `json:"golang_version"`
4042
BuildStatus string `json:"status"`
4143
BuildTime string `json:"time"`
44+
BuildBranch string `json:"build_branch"`
45+
BuildGitDirty string `json:"build_git_dirty"`
4246
}
4347

4448
var (
@@ -54,13 +58,15 @@ var (
5458
// user@host-<version>-<git revision>-<build status>
5559
// ```
5660
func (b BuildInfo) String() string {
57-
return fmt.Sprintf("%v@%v-%v-%v-%v-%v",
61+
return fmt.Sprintf("%v@%v-%v-%v-%v-%v-%v-%v",
5862
b.User,
5963
b.Host,
6064
b.Version,
6165
b.GitRevision,
6266
b.BuildStatus,
63-
b.BuildTime)
67+
b.BuildTime,
68+
b.BuildBranch,
69+
b.BuildGitDirty)
6470
}
6571

6672
// LongForm returns a multi-line version information
@@ -81,14 +87,18 @@ User: %v@%v
8187
GolangVersion: %v
8288
BuildStatus: %v
8389
BuildTime: %v
90+
BuildBranch: %v
91+
BuildGitDirty: %v
8492
`,
8593
b.Version,
8694
b.GitRevision,
8795
b.User,
8896
b.Host,
8997
b.GolangVersion,
9098
b.BuildStatus,
91-
b.BuildTime)
99+
b.BuildTime,
100+
b.BuildBranch,
101+
b.BuildGitDirty)
92102
}
93103

94104
func init() {
@@ -100,5 +110,7 @@ func init() {
100110
GolangVersion: runtime.Version(),
101111
BuildStatus: buildStatus,
102112
BuildTime: buildTime,
113+
BuildBranch: buildBranch,
114+
BuildGitDirty: buildGitDirty,
103115
}
104116
}

etc/gaea.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ stats_interval=10
4444

4545
;encrypt key
4646
encrypt_key=1234abcd5678efg*
47+
48+
;server_version
49+
server_version=5.6.20-gaea

gen_version.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ else
1515
tree_status="Modified"
1616
fi
1717

18+
# Check for git branch and git dirty
19+
BRANCH=$(git rev-parse --abbrev-ref HEAD)
20+
GIT_DIRTY=$(git diff --no-ext-diff 2> /dev/null | wc -l)
21+
1822
# XXX This needs to be updated to accomodate tags added after building, rather than prior to builds
1923
RELEASE_TAG=$(git describe --match '[0-9]*\.[0-9]*\.[0-9]*' --exact-match --tags 2> /dev/null || echo "")
2024

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

29-
# used by pkg/version
33+
# used by core/version
3034
echo buildVersion "${VERSION}"
3135
echo buildGitRevision "${BUILD_GIT_REVISION}"
3236
echo buildUser "$(whoami)"
3337
echo buildHost "$(hostname -f)"
3438
echo buildStatus "${tree_status}"
3539
echo buildTime "$(date +%Y-%m-%d--%T)"
40+
echo buildBranch "${BRANCH}"
41+
echo buildGitDirty "${GIT_DIRTY}"

models/proxy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type Proxy struct {
6161
StatsInterval int `ini:"stats_interval"` // set stats interval of connect pool
6262

6363
EncryptKey string `ini:"encrypt_key"`
64+
65+
ServerVersion string `ini:"server_version"`
6466
}
6567

6668
// ParseProxyConfigFromFile parser proxy config from file

proxy/server/admin.go

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ func (s *AdminServer) registerURL() {
161161
})
162162
}
163163

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)