зеркало из https://github.com/mozilla/mig.git
dispatch: generate warning if messages are being dropped
This commit is contained in:
Родитель
263c517f1d
Коммит
ab29f79ae9
|
@ -16,6 +16,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
"mig.ninja/mig"
|
"mig.ninja/mig"
|
||||||
"mig.ninja/mig/modules"
|
"mig.ninja/mig/modules"
|
||||||
|
@ -61,6 +62,10 @@ var agtHostname string
|
||||||
// runDispatch
|
// runDispatch
|
||||||
var messageBuf chan string
|
var messageBuf chan string
|
||||||
|
|
||||||
|
// lastDrop stores the last time a message was dropped by the dispatch module
|
||||||
|
var lastDrop time.Time
|
||||||
|
var dropCounter int
|
||||||
|
|
||||||
// Dispatch record describes the formatting of JSON data submitted from the dispatch
|
// Dispatch record describes the formatting of JSON data submitted from the dispatch
|
||||||
// module.
|
// module.
|
||||||
type DispatchRecord struct {
|
type DispatchRecord struct {
|
||||||
|
@ -128,7 +133,15 @@ func dispatchIn(msg string) {
|
||||||
select {
|
select {
|
||||||
case messageBuf <- msg:
|
case messageBuf <- msg:
|
||||||
default:
|
default:
|
||||||
|
dropCounter++
|
||||||
// If we can't queue the message it is just dropped
|
// If we can't queue the message it is just dropped
|
||||||
|
now := time.Now()
|
||||||
|
if now.After(lastDrop.Add(time.Duration(time.Minute * 5))) {
|
||||||
|
logChan <- fmt.Sprintf("warning, dispatch module dropping messages "+
|
||||||
|
"(buffer full, %v dropped since last warning)", dropCounter)
|
||||||
|
lastDrop = now
|
||||||
|
dropCounter = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче