clean up WorkersState metric handling
I think there's no need for that counter map - it seems the performance benefit
doesn't justify the readability cost.
concourse/concourse#4985
@@ -667,28 +667,22 @@ type WorkersState struct {
}
func (event WorkersState) Emit(logger lager.Logger) {
- var (
- perStateCounter = map[db.WorkerState]int{}
- eventState EventState
- )
+ var eventState EventState
+ for _, state := range db.AllWorkerStates() {
+ count := 0
for _, workerState := range event.WorkerStateByName {
- _, exists := perStateCounter[workerState]
- if !exists {
- perStateCounter[workerState] = 1
- continue
+ if workerState == state {
+ count += 1
}
-
- perStateCounter[workerState] += 1
}
- for _, state := range db.AllWorkerStates() {
- count := perStateCounter[state]
if state == db.WorkerStateStalled && count > 0 {
eventState = EventStateWarning
} else {
eventState = EventStateOK
}
+
emit(
logger.Session("worker-state"),
Event{
