Skip to content

Commit

Permalink
Merge f34e907 into cede7c6
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlogic committed Jun 6, 2020
2 parents cede7c6 + f34e907 commit 7e73b4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ type Server struct {
getMap sync.Map
countMap map[int]string
getLoad int
getMapB map[string]int
mapLock *sync.Mutex
}

type httpGetter interface {
Expand Down Expand Up @@ -138,6 +140,8 @@ func InitServer() *Server {
s.lockNames = make(map[string]string)
s.elector = &prodElector{dial: s.DoDial}
s.countMap = make(map[int]string)
s.getMapB = make(map[string]int)
s.mapLock = &sync.Mutex{}
return s
}

Expand Down
16 changes: 15 additions & 1 deletion discoveryv2api.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,22 @@ func (s *Server) Get(ctx context.Context, req *pb.GetRequest) (*pb.GetResponse,
s.getLoad--
}()

jobName := "unknown"
if len(req.GetJob()) > 0 {
jobName = req.GetJob()
}
s.mapLock.Lock()
s.getMapB[jobName]++
s.mapLock.Unlock()

defer func() {
s.mapLock.Lock()
s.getMapB[jobName]--
s.mapLock.Unlock()
}()

if s.getLoad > 50 {
s.RaiseIssue(ctx, "Overload", fmt.Sprintf("Discover on %v is recording %v get calls", s.Registry, s.getLoad), false)
s.RaiseIssue(ctx, "Overload", fmt.Sprintf("Discover on %v is recording %v get calls: %v", s.Registry, s.getLoad, s.getMapB), false)
}

if s.getLoad > 100 {
Expand Down

0 comments on commit 7e73b4e

Please sign in to comment.