Skip to content

Commit 632f31d

Browse files
tangcongspinlock
authored andcommitted
proxy:collects maxpipeline and maxproxyclient error (#1408)
* proxy:collects pipeline and proxyclient error * proxy:flush stats when session exit * proxy:delete unnecessary flushOpStats function
1 parent f25c643 commit 632f31d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pkg/proxy/session.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Session struct {
3434
stats struct {
3535
opmap map[string]*opStats
3636
total atomic2.Int64
37+
fails atomic2.Int64
3738
flush struct {
3839
n uint
3940
nano int64
@@ -116,6 +117,8 @@ func (s *Session) Start(d *Router) {
116117
go func() {
117118
s.Conn.Encode(redis.NewErrorf("ERR max number of clients reached"), true)
118119
s.CloseWithError(ErrTooManySessions)
120+
s.incrFails()
121+
s.flushOpStats(true)
119122
}()
120123
decrSessions()
121124
return
@@ -125,6 +128,8 @@ func (s *Session) Start(d *Router) {
125128
go func() {
126129
s.Conn.Encode(redis.NewErrorf("ERR router is not online"), true)
127130
s.CloseWithError(ErrRouterNotOnline)
131+
s.incrFails()
132+
s.flushOpStats(true)
128133
}()
129134
decrSessions()
130135
return
@@ -162,6 +167,7 @@ func (s *Session) loopReader(tasks *RequestChan, d *Router) (err error) {
162167
s.incrOpTotal()
163168

164169
if tasks.Buffered() > maxPipelineLen {
170+
s.incrFails()
165171
return ErrTooManyPipelinedRequests
166172
}
167173

@@ -629,6 +635,10 @@ func (s *Session) incrOpTotal() {
629635
s.stats.total.Incr()
630636
}
631637

638+
func (s *Session) incrFails() {
639+
s.stats.fails.Incr()
640+
}
641+
632642
func (s *Session) getOpStats(opstr string) *opStats {
633643
e := s.stats.opmap[opstr]
634644
if e == nil {
@@ -665,6 +675,7 @@ func (s *Session) flushOpStats(force bool) {
665675
s.stats.flush.nano = nano
666676

667677
incrOpTotal(s.stats.total.Swap(0))
678+
incrOpFails(s.stats.fails.Swap(0))
668679
for _, e := range s.stats.opmap {
669680
if e.calls.Int64() != 0 || e.fails.Int64() != 0 {
670681
incrOpStats(e)

pkg/proxy/stats.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ func incrOpTotal(n int64) {
149149
cmdstats.total.Add(n)
150150
}
151151

152+
func incrOpFails(n int64) {
153+
cmdstats.fails.Add(n)
154+
}
155+
152156
func incrOpStats(e *opStats) {
153157
s := getOpStats(e.opstr, true)
154158
s.calls.Add(e.calls.Swap(0))

0 commit comments

Comments
 (0)