mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user