Merge pull request #5212 from wpaulino/wtclient-update-stats-after-backup

wtclient: decrement pending tasks stats upon accepted task
This commit is contained in:
Olaoluwa Osuntokun 2021-04-22 15:49:11 -07:00 committed by GitHub
commit d07202d17b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

@ -336,7 +336,7 @@ func (c *WatchtowerClient) Stats(ctx context.Context,
stats.NumTasksAccepted += stat.NumTasksAccepted stats.NumTasksAccepted += stat.NumTasksAccepted
stats.NumTasksIneligible += stat.NumTasksIneligible stats.NumTasksIneligible += stat.NumTasksIneligible
stats.NumTasksReceived += stat.NumTasksReceived stats.NumTasksPending += stat.NumTasksPending
stats.NumSessionsAcquired += stat.NumSessionsAcquired stats.NumSessionsAcquired += stat.NumSessionsAcquired
stats.NumSessionsExhausted += stat.NumSessionsExhausted stats.NumSessionsExhausted += stat.NumSessionsExhausted
} }
@ -344,7 +344,7 @@ func (c *WatchtowerClient) Stats(ctx context.Context,
return &StatsResponse{ return &StatsResponse{
NumBackups: uint32(stats.NumTasksAccepted), NumBackups: uint32(stats.NumTasksAccepted),
NumFailedBackups: uint32(stats.NumTasksIneligible), NumFailedBackups: uint32(stats.NumTasksIneligible),
NumPendingBackups: uint32(stats.NumTasksReceived), NumPendingBackups: uint32(stats.NumTasksPending),
NumSessionsAcquired: uint32(stats.NumSessionsAcquired), NumSessionsAcquired: uint32(stats.NumSessionsAcquired),
NumSessionsExhausted: uint32(stats.NumSessionsExhausted), NumSessionsExhausted: uint32(stats.NumSessionsExhausted),
}, nil }, nil

@ -10,9 +10,9 @@ import (
type ClientStats struct { type ClientStats struct {
mu sync.Mutex mu sync.Mutex
// NumTasksReceived is the total number of backups that are pending to // NumTasksPending is the total number of backups that are pending to
// be acknowledged by all active and exhausted watchtower sessions. // be acknowledged by all active and exhausted watchtower sessions.
NumTasksReceived int NumTasksPending int
// NumTasksAccepted is the total number of backups made to all active // NumTasksAccepted is the total number of backups made to all active
// and exhausted watchtower sessions. // and exhausted watchtower sessions.
@ -36,7 +36,7 @@ type ClientStats struct {
func (s *ClientStats) taskReceived() { func (s *ClientStats) taskReceived() {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
s.NumTasksReceived++ s.NumTasksPending++
} }
// taskAccepted increments the number of tasks that have been assigned to active // taskAccepted increments the number of tasks that have been assigned to active
@ -45,6 +45,7 @@ func (s *ClientStats) taskAccepted() {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
s.NumTasksAccepted++ s.NumTasksAccepted++
s.NumTasksPending--
} }
// taskIneligible increments the number of tasks that were unable to satisfy the // taskIneligible increments the number of tasks that were unable to satisfy the
@ -78,7 +79,7 @@ func (s *ClientStats) String() string {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
return fmt.Sprintf("tasks(received=%d accepted=%d ineligible=%d) "+ return fmt.Sprintf("tasks(received=%d accepted=%d ineligible=%d) "+
"sessions(acquired=%d exhausted=%d)", s.NumTasksReceived, "sessions(acquired=%d exhausted=%d)", s.NumTasksPending,
s.NumTasksAccepted, s.NumTasksIneligible, s.NumSessionsAcquired, s.NumTasksAccepted, s.NumTasksIneligible, s.NumSessionsAcquired,
s.NumSessionsExhausted) s.NumSessionsExhausted)
} }
@ -88,7 +89,7 @@ func (s *ClientStats) Copy() ClientStats {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
return ClientStats{ return ClientStats{
NumTasksReceived: s.NumTasksReceived, NumTasksPending: s.NumTasksPending,
NumTasksAccepted: s.NumTasksAccepted, NumTasksAccepted: s.NumTasksAccepted,
NumTasksIneligible: s.NumTasksIneligible, NumTasksIneligible: s.NumTasksIneligible,
NumSessionsAcquired: s.NumSessionsAcquired, NumSessionsAcquired: s.NumSessionsAcquired,