Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9 from StrongMonkey/small-fix
Browse files Browse the repository at this point in the history
Fix calculation bug
  • Loading branch information
StrongMonkey authored Dec 13, 2019
2 parents eb81b61 + b5c0db3 commit 61389ac
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions pkg/controllers/servicescale/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ func (s *SimpleScale) scrape() error {
defer resp.Body.Close()
scannner := bufio.NewScanner(resp.Body)

inboundActiveRequests = calculateActiveRequests(scannner, requestTotalMatchCriteria, responseTotalMatchCriteria, true)
outbountActiveRequests = calculateActiveRequests(scannner, requestTotalMatchCriteria, responseTotalMatchCriteria, false)
totalActiveRequest = inboundActiveRequests + outbountActiveRequests
inboundActiveRequests += calculateActiveRequests(scannner, requestTotalMatchCriteria, responseTotalMatchCriteria, true)
outbountActiveRequests += calculateActiveRequests(scannner, requestTotalMatchCriteria, responseTotalMatchCriteria, false)
readyPods++
}
totalActiveRequest = inboundActiveRequests + outbountActiveRequests

if readyPods == 0 {
stat.activeRequest = 0
Expand All @@ -302,22 +302,30 @@ func calculateActiveRequests(scanner *bufio.Scanner, requestMatch, responseMatch
}
var request, response int
for scanner.Scan() {
response = match(scanner, responseMatch, direction)
request = match(scanner, requestMatch, direction)
if v, ok := match(scanner.Text(), responseMatch, direction); ok {
response = v
}
if v, ok := match(scanner.Text(), requestMatch, direction); ok {
request = v
}
}
if request-response < 0 {
return 0
}
return request - response
}

func match(scanner *bufio.Scanner, m, direction string) int {
func match(text, m, direction string) (int, bool) {
var result int
if strings.Contains(scanner.Text(), m) && strings.Contains(scanner.Text(), direction) {
parts := strings.Split(scanner.Text(), " ")
if strings.Contains(text, m) && strings.Contains(text, direction) {
parts := strings.Split(text, " ")
if len(parts) == 2 {
rqs, _ := strconv.Atoi(parts[1])
result = rqs
return result, true
}
}
return result
return result, false
}

func bounded(value, lower, upper int32) int32 {
Expand Down

0 comments on commit 61389ac

Please sign in to comment.