fn: paused and evicted container stats (#1209)

* fn: paused and evicted container stats

With this change, now stats reports paused state
as well as incidents of container exit due to evictions.

* fn: update/document state transitions in state tracker

There's no case of a transition moving from done to waiting. This
must be deprecated behavior.
This commit is contained in:
Tolga Ceylan
2018-09-13 16:24:26 -07:00
committed by GitHub
parent ede5b93c34
commit 4dcdb7d982
4 changed files with 48 additions and 13 deletions

View File

@@ -47,12 +47,13 @@ const (
)
const (
ContainerStateNone ContainerStateType = iota // uninitialized
ContainerStateWait // resource (cpu + mem) waiting
ContainerStateStart // launching
ContainerStateIdle // running idle
ContainerStateBusy // running busy
ContainerStateDone // exited/failed/done
ContainerStateNone ContainerStateType = iota // uninitialized
ContainerStateWait // resource (cpu + mem) waiting
ContainerStateStart // launching
ContainerStateIdle // running: idle but not paused
ContainerStatePaused // running: idle but paused
ContainerStateBusy // running: busy
ContainerStateDone // exited/failed/done
ContainerStateMax
)
@@ -61,14 +62,16 @@ var containerGaugeKeys = [ContainerStateMax]string{
"container_wait_total",
"container_start_total",
"container_idle_total",
"container_paused_total",
"container_busy_total",
"container_done_total",
}
var containerTimeKeys = [ContainerStateMax]string{
"",
"container_wait_duration_seconds",
"container_start_duration_seconds",
"container_idle_duration_seconds",
"container_paused_duration_seconds",
"container_busy_duration_seconds",
}
@@ -101,6 +104,10 @@ func (c *requestState) UpdateState(ctx context.Context, newState RequestStateTyp
}
}
func isIdleState(state ContainerStateType) bool {
return state == ContainerStateIdle || state == ContainerStatePaused
}
func (c *containerState) UpdateState(ctx context.Context, newState ContainerStateType, slots *slotQueue) {
var now time.Time
@@ -109,11 +116,13 @@ func (c *containerState) UpdateState(ctx context.Context, newState ContainerStat
c.lock.Lock()
// except for 1) switching back to idle from busy (hot containers) or 2)
// to waiting from done, otherwise we can only move forward in states
// Only the following state transitions are allowed:
// 1) any move forward in states as per ContainerStateType order
// 2) move back: from paused to idle
// 3) move back: from busy to idle/paused
if c.state < newState ||
(c.state == ContainerStateBusy && newState == ContainerStateIdle) ||
(c.state == ContainerStateDone && newState == ContainerStateIdle) {
(c.state == ContainerStatePaused && newState == ContainerStateIdle) ||
(c.state == ContainerStateBusy && isIdleState(newState)) {
now = time.Now()
oldState = c.state