Skip to content

Commit

Permalink
server: Add git hash into status api (#1724)
Browse files Browse the repository at this point in the history
It is more convenient to get git hash from http api then from log file.
  • Loading branch information
shenli authored and coocood committed Sep 14, 2016
1 parent efa2db0 commit a82abef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/server.go
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/arena"
"github.com/pingcap/tidb/util/printer"
// For prometheus init
_ "github.com/pingcap/tidb/util/metrics"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -213,7 +214,12 @@ func (s *Server) startStatusHTTP() {
go func() {
http.HandleFunc("/status", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
s := status{TPS: tidb.GetTPS(), Connections: s.ConnectionCount(), Version: mysql.ServerVersion}
s := status{
TPS: tidb.GetTPS(),
Connections: s.ConnectionCount(),
Version: mysql.ServerVersion,
GitHash: printer.TiDBGitHash,
}
js, err := json.Marshal(s)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -243,6 +249,7 @@ type status struct {
TPS int64 `json:"tps"`
Connections int `json:"connections"`
Version string `json:"version"`
GitHash string `json:"git_hash"`
}

// Server error codes.
Expand Down
2 changes: 2 additions & 0 deletions server/server_test.go
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/go-sql-driver/mysql"
. "github.com/pingcap/check"
tmysql "github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/util/printer"
)

func TestT(t *testing.T) {
Expand Down Expand Up @@ -453,6 +454,7 @@ func runTestStatusAPI(c *C) {
err = decoder.Decode(&data)
c.Assert(err, IsNil)
c.Assert(data.Version, Equals, tmysql.ServerVersion)
c.Assert(data.GitHash, Equals, printer.TiDBGitHash)
}

func runTestMultiPacket(c *C) {
Expand Down

0 comments on commit a82abef

Please sign in to comment.