mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: container initialization monitoring (#1288)
Container initialization phase consumes resource tracker resources (token), during lengthy operations. In order for agent stability/liveness, this phase has to be evictable/cancelable and time bounded. With this change, introducing a new system wide environment setting to bound the time spent in container initialization phase. This phase includes docker-pull, docker-create, docker-attach, docker-start and UDS wait operations. This initialization period is also now considered evictable.
This commit is contained in:
@@ -40,6 +40,10 @@ type AppRequest struct {
|
||||
IsDebug bool `json:"isDebug,omitempty"`
|
||||
// simulate crash
|
||||
IsCrash bool `json:"isCrash,omitempty"`
|
||||
// abrupt exit code
|
||||
ExitCode int `json:"exitCode,omitempty"`
|
||||
// enable abrupt exit
|
||||
IsExit bool `json:"isExit,omitempty"`
|
||||
// shutdown UDS after request
|
||||
IsShutdown bool `json:"isShutdown,omitempty"`
|
||||
// read a file from disk
|
||||
@@ -232,6 +236,11 @@ func processRequest(ctx context.Context, in io.Reader) (*AppRequest, *AppRespons
|
||||
log.Fatalln("Crash requested")
|
||||
}
|
||||
|
||||
if request.IsExit {
|
||||
log.Printf("Exit requested %+v", request.ExitCode)
|
||||
os.Exit(request.ExitCode)
|
||||
}
|
||||
|
||||
if request.ExpectHeaders != nil {
|
||||
for name, header := range request.ExpectHeaders {
|
||||
if h2 := fnctx.Header().Get(name); header[0] != h2 {
|
||||
@@ -316,6 +325,15 @@ func main() {
|
||||
time.Sleep(time.Millisecond * time.Duration(delay))
|
||||
}
|
||||
|
||||
if initExit := os.Getenv("ENABLE_INIT_EXIT"); initExit != "" {
|
||||
log.Printf("Container start exit %v", initExit)
|
||||
exitCode, err := strconv.ParseInt(initExit, 10, 64)
|
||||
if err != nil {
|
||||
log.Fatalf("cannot parse ENABLE_INIT_EXIT %v", err)
|
||||
}
|
||||
os.Exit(int(exitCode))
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
GlobCancel = cancel
|
||||
fdk.HandleContext(ctx, fdk.HandlerFunc(AppHandler)) // XXX(reed): can extract & instrument
|
||||
|
||||
Reference in New Issue
Block a user