Extend stats to report Failed calls

This commit is contained in:
Nigel Deakin
2017-09-22 17:36:43 +01:00
parent ab7352ce40
commit 54407f7b74
2 changed files with 35 additions and 4 deletions

View File

@@ -173,6 +173,7 @@ func (a *agent) Submit(callI Call) error {
default: default:
} }
// increment queued count
a.stats.Enqueue(callI.Model().Path) a.stats.Enqueue(callI.Model().Path)
call := callI.(*call) call := callI.(*call)
@@ -202,13 +203,20 @@ func (a *agent) Submit(callI Call) error {
return err return err
} }
a.stats.Start(callI.Model().Path) // decrement queued count, increment running count
a.stats.DequeueAndStart(callI.Model().Path)
err = slot.exec(ctx, call) err = slot.exec(ctx, call)
// pass this error (nil or otherwise) to end directly, to store status, etc // pass this error (nil or otherwise) to end directly, to store status, etc
// End may rewrite the error or elect to return it // End may rewrite the error or elect to return it
a.stats.Complete(callI.Model().Path) if err == nil {
// decrement running count, increment completed count
a.stats.Complete(callI.Model().Path)
} else {
// decrement running count, increment failed count
a.stats.Failed(callI.Model().Path)
}
// TODO: we need to allocate more time to store the call + logs in case the call timed out, // TODO: we need to allocate more time to store the call + logs in case the call timed out,
// but this could put us over the timeout if the call did not reply yet (need better policy). // but this could put us over the timeout if the call did not reply yet (need better policy).

View File

@@ -13,6 +13,7 @@ type stats struct {
queue uint64 queue uint64
running uint64 running uint64
complete uint64 complete uint64
failed uint64
// statistics for individual functions, keyed by function path // statistics for individual functions, keyed by function path
functionStatsMap map[string]*functionStats functionStatsMap map[string]*functionStats
} }
@@ -22,6 +23,7 @@ type functionStats struct {
queue uint64 queue uint64
running uint64 running uint64
complete uint64 complete uint64
failed uint64
} }
type Stats struct { type Stats struct {
@@ -29,6 +31,7 @@ type Stats struct {
Queue uint64 Queue uint64
Running uint64 Running uint64
Complete uint64 Complete uint64
Failed uint64
// statistics for individual functions, keyed by function path // statistics for individual functions, keyed by function path
FunctionStatsMap map[string]*FunctionStats FunctionStatsMap map[string]*FunctionStats
} }
@@ -38,6 +41,7 @@ type FunctionStats struct {
Queue uint64 Queue uint64
Running uint64 Running uint64
Complete uint64 Complete uint64
Failed uint64
} }
func (s *stats) getStatsForFunction(path string) *functionStats { func (s *stats) getStatsForFunction(path string) *functionStats {
@@ -68,7 +72,7 @@ func (s *stats) Dequeue(path string) {
s.mu.Unlock() s.mu.Unlock()
} }
func (s *stats) Start(path string) { func (s *stats) DequeueAndStart(path string) {
s.mu.Lock() s.mu.Lock()
s.queue-- s.queue--
s.getStatsForFunction(path).queue-- s.getStatsForFunction(path).queue--
@@ -86,15 +90,34 @@ func (s *stats) Complete(path string) {
s.mu.Unlock() s.mu.Unlock()
} }
func (s *stats) Failed(path string) {
s.mu.Lock()
s.running--
s.getStatsForFunction(path).running--
s.failed++
s.getStatsForFunction(path).failed++
s.mu.Unlock()
}
func (s *stats) DequeueAndFail(path string) {
s.mu.Lock()
s.queue--
s.getStatsForFunction(path).queue--
s.failed++
s.getStatsForFunction(path).failed++
s.mu.Unlock()
}
func (s *stats) Stats() Stats { func (s *stats) Stats() Stats {
var stats Stats var stats Stats
s.mu.Lock() s.mu.Lock()
stats.Running = s.running stats.Running = s.running
stats.Complete = s.complete stats.Complete = s.complete
stats.Queue = s.queue stats.Queue = s.queue
stats.Failed = s.failed
stats.FunctionStatsMap = make(map[string]*FunctionStats) stats.FunctionStatsMap = make(map[string]*FunctionStats)
for key, value := range s.functionStatsMap { for key, value := range s.functionStatsMap {
thisFunctionStats := &FunctionStats{Queue: value.queue, Running: value.running, Complete: value.complete} thisFunctionStats := &FunctionStats{Queue: value.queue, Running: value.running, Complete: value.complete, Failed: value.failed}
stats.FunctionStatsMap[key] = thisFunctionStats stats.FunctionStatsMap[key] = thisFunctionStats
} }
s.mu.Unlock() s.mu.Unlock()