Skip to content

Commit

Permalink
Merge branch 'redis-ooo' of github.com:felixhao/overlord into redis-ooo
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhao committed Jul 31, 2018
2 parents 43344ae + e32aba4 commit 559ebd1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
2 changes: 2 additions & 0 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func main() {
go http.ListenAndServe(c.Pprof, nil)
if c.Proxy.UseMetrics {
prom.Init()
} else {
prom.On = false
}
}
// new proxy
Expand Down
10 changes: 2 additions & 8 deletions lib/prom/prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@ var (
clusterNodeErrLabels = []string{"cluster", "node", "cmd", "error"}
clusterCmdLabels = []string{"cluster", "cmd"}
clusterNodeCmdLabels = []string{"cluster", "node", "cmd"}

on bool
// On Prom switch
On = true
)

// On return if open prom metrics.
func On() bool {
return on
}

// Init init prometheus.
func Init() {
on = true
conns = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: statConns,
Expand Down
4 changes: 2 additions & 2 deletions proto/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (m *MsgBatch) Msgs() []*Message {
// BatchDone will set done and report prom HandleTime.
func (m *MsgBatch) BatchDone(cluster, addr string) {
m.Done()
if prom.On() {
if prom.On {
for _, msg := range m.Msgs() {
prom.HandleTime(cluster, addr, msg.Request().CmdString(), int64(msg.RemoteDur()/time.Microsecond))
}
Expand All @@ -123,7 +123,7 @@ func (m *MsgBatch) BatchDoneWithError(cluster, addr string, err error) {
if log.V(1) {
log.Errorf("cluster(%s) Msg(%s) cluster process handle error:%+v", cluster, msg.Request().Key(), err)
}
if prom.On() {
if prom.On {
prom.ErrIncr(cluster, addr, msg.Request().CmdString(), errors.Cause(err).Error())
}
}
Expand Down
4 changes: 2 additions & 2 deletions proto/memcache/binary/node_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (n *nodeConn) fillMCRequest(mcr *MCRequest, data []byte) (size int, err err
bl := binary.BigEndian.Uint32(mcr.bodyLen)
if bl == 0 {
if mcr.rTp == RequestTypeGet || mcr.rTp == RequestTypeGetQ || mcr.rTp == RequestTypeGetK || mcr.rTp == RequestTypeGetKQ {
if prom.On() {
if prom.On {
prom.Miss(n.cluster, n.addr)
}
}
Expand All @@ -186,7 +186,7 @@ func (n *nodeConn) fillMCRequest(mcr *MCRequest, data []byte) (size int, err err
mcr.data = data[requestHeaderLen : requestHeaderLen+bl]

if mcr.rTp == RequestTypeGet || mcr.rTp == RequestTypeGetQ || mcr.rTp == RequestTypeGetK || mcr.rTp == RequestTypeGetKQ {
if prom.On() {
if prom.On {
prom.Hit(n.cluster, n.addr)
}
}
Expand Down
4 changes: 2 additions & 2 deletions proto/memcache/node_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ func (n *nodeConn) fillMCRequest(mcr *MCRequest, data []byte) (size int, err err
}

if bytes.Equal(bs, endBytes) {
if prom.On() {
if prom.On {
prom.Miss(n.cluster, n.addr)
}
return
}
if prom.On() {
if prom.On {
prom.Hit(n.cluster, n.addr)
}
length, err := findLength(bs, mcr.rTp == RequestTypeGets || mcr.rTp == RequestTypeGats)
Expand Down
4 changes: 2 additions & 2 deletions proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (h *Handler) handle() {
}
msg.MarkEnd()
msg.ReleaseSubs()
if prom.On() {
if prom.On {
prom.ProxyTime(h.cluster.cc.Name, h.toStr(msg.Request().Cmd()), int64(msg.TotalDur()/time.Microsecond))
}
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func (h *Handler) closeWithError(err error) {
h.cancel()
h.msgCh.Close()
_ = h.conn.Close()
if prom.On() {
if prom.On {
prom.ConnDecr(h.cluster.cc.Name)
}
if log.V(3) {
Expand Down

0 comments on commit 559ebd1

Please sign in to comment.