@@ -93,17 +93,17 @@ func (p *Process) swapState(expectedState, newState ProcessState) (ProcessState,
93
93
defer p .stateMutex .Unlock ()
94
94
95
95
if p .state != expectedState {
96
- p .proxyLogger .Warnf ("swapState() Unexpected current state %s, expected %s" , p .state , expectedState )
96
+ p .proxyLogger .Warnf ("<%s> swapState() Unexpected current state %s, expected %s" , p . ID , p .state , expectedState )
97
97
return p .state , ErrExpectedStateMismatch
98
98
}
99
99
100
100
if ! isValidTransition (p .state , newState ) {
101
- p .proxyLogger .Warnf ("swapState() Invalid state transition from %s to %s" , p .state , newState )
101
+ p .proxyLogger .Warnf ("<%s> swapState() Invalid state transition from %s to %s" , p . ID , p .state , newState )
102
102
return p .state , ErrInvalidStateTransition
103
103
}
104
104
105
105
p .state = newState
106
- p .proxyLogger .Debugf ("swapState() State transitioned from %s to %s" , expectedState , newState )
106
+ p .proxyLogger .Debugf ("<%s> swapState() State transitioned from %s to %s" , p . ID , expectedState , newState )
107
107
return p .state , nil
108
108
}
109
109
@@ -187,7 +187,7 @@ func (p *Process) start() error {
187
187
// Capture the exit error for later signaling
188
188
go func () {
189
189
exitErr := p .cmd .Wait ()
190
- p .proxyLogger .Debugf ("cmd.Wait() returned for [%s] error: %v" , p .ID , exitErr )
190
+ p .proxyLogger .Debugf ("<%s> cmd.Wait() returned error: %v" , p .ID , exitErr )
191
191
p .cmdWaitChan <- exitErr
192
192
}()
193
193
@@ -236,32 +236,32 @@ func (p *Process) start() error {
236
236
return errors .New ("health check interrupted due to shutdown" )
237
237
case exitErr := <- p .cmdWaitChan :
238
238
if exitErr != nil {
239
- p .proxyLogger .Warnf ("upstream command exited prematurely with error: %v" , exitErr )
239
+ p .proxyLogger .Warnf ("<%s> upstream command exited prematurely with error: %v" , p . ID , exitErr )
240
240
if curState , err := p .swapState (StateStarting , StateFailed ); err != nil {
241
241
return fmt .Errorf ("upstream command exited unexpectedly: %s AND state swap failed: %v, current state: %v" , exitErr .Error (), err , curState )
242
242
} else {
243
243
return fmt .Errorf ("upstream command exited unexpectedly: %s" , exitErr .Error ())
244
244
}
245
245
} else {
246
- p .proxyLogger .Warnf ("upstream command exited prematurely with no error" )
246
+ p .proxyLogger .Warnf ("<%s> upstream command exited prematurely but successfully" , p . ID )
247
247
if curState , err := p .swapState (StateStarting , StateFailed ); err != nil {
248
- return fmt .Errorf ("upstream command exited prematurely with no error AND state swap failed: %v, current state: %v" , err , curState )
248
+ return fmt .Errorf ("upstream command exited prematurely but successfully AND state swap failed: %v, current state: %v" , err , curState )
249
249
} else {
250
- return fmt .Errorf ("upstream command exited prematurely with no error " )
250
+ return fmt .Errorf ("upstream command exited prematurely but successfully " )
251
251
}
252
252
}
253
253
default :
254
254
if err := p .checkHealthEndpoint (healthURL ); err == nil {
255
- p .proxyLogger .Infof ("Health check passed on %s" , healthURL )
255
+ p .proxyLogger .Infof ("<%s> Health check passed on %s" , p . ID , healthURL )
256
256
cancelHealthCheck ()
257
257
break loop
258
258
} else {
259
259
if strings .Contains (err .Error (), "connection refused" ) {
260
260
endTime , _ := checkDeadline .Deadline ()
261
261
ttl := time .Until (endTime )
262
- p .proxyLogger .Infof ("Connection refused on %s, giving up in %.0fs" , healthURL , ttl .Seconds ())
262
+ p .proxyLogger .Infof ("<%s> Connection refused on %s, giving up in %.0fs" , p . ID , healthURL , ttl .Seconds ())
263
263
} else {
264
- p .proxyLogger .Infof ("Health check error on %s, %v" , healthURL , err )
264
+ p .proxyLogger .Infof ("<%s> Health check error on %s, %v" , p . ID , healthURL , err )
265
265
}
266
266
}
267
267
}
@@ -285,7 +285,7 @@ func (p *Process) start() error {
285
285
p .inFlightRequests .Wait ()
286
286
287
287
if time .Since (p .lastRequestHandled ) > maxDuration {
288
- p .proxyLogger .Infof ("Unloading model %s , TTL of %ds reached. " , p .ID , p .config .UnloadAfter )
288
+ p .proxyLogger .Infof ("<%s> Unloading model, TTL of %ds reached" , p .ID , p .config .UnloadAfter )
289
289
p .Stop ()
290
290
return
291
291
}
@@ -303,19 +303,19 @@ func (p *Process) start() error {
303
303
func (p * Process ) Stop () {
304
304
// wait for any inflight requests before proceeding
305
305
p .inFlightRequests .Wait ()
306
- p .proxyLogger .Debugf ("Stopping process [%s] " , p .ID )
306
+ p .proxyLogger .Debugf ("<%s> Stopping process" , p .ID )
307
307
308
308
// calling Stop() when state is invalid is a no-op
309
309
if curState , err := p .swapState (StateReady , StateStopping ); err != nil {
310
- p .proxyLogger .Infof ("Stop() Ready -> StateStopping err: %v, current state: %v" , err , curState )
310
+ p .proxyLogger .Infof ("<%s> Stop() Ready -> StateStopping err: %v, current state: %v" , p . ID , err , curState )
311
311
return
312
312
}
313
313
314
314
// stop the process with a graceful exit timeout
315
315
p .stopCommand (5 * time .Second )
316
316
317
317
if curState , err := p .swapState (StateStopping , StateStopped ); err != nil {
318
- p .proxyLogger .Infof ("Stop() StateStopping -> StateStopped err: %v, current state: %v" , err , curState )
318
+ p .proxyLogger .Infof ("<%s> Stop() StateStopping -> StateStopped err: %v, current state: %v" , p . ID , err , curState )
319
319
}
320
320
}
321
321
@@ -333,24 +333,24 @@ func (p *Process) Shutdown() {
333
333
func (p * Process ) stopCommand (sigtermTTL time.Duration ) {
334
334
stopStartTime := time .Now ()
335
335
defer func () {
336
- p .proxyLogger .Debugf ("Process [%s] stopCommand took %v" , p .ID , time .Since (stopStartTime ))
336
+ p .proxyLogger .Debugf ("<%s> stopCommand took %v" , p .ID , time .Since (stopStartTime ))
337
337
}()
338
338
339
339
sigtermTimeout , cancelTimeout := context .WithTimeout (context .Background (), sigtermTTL )
340
340
defer cancelTimeout ()
341
341
342
342
if p .cmd == nil || p .cmd .Process == nil {
343
- p .proxyLogger .Warnf ("Process [%s] cmd or cmd.Process is nil" , p .ID )
343
+ p .proxyLogger .Warnf ("<%s> cmd or cmd.Process is nil" , p .ID )
344
344
return
345
345
}
346
346
347
347
if err := p .terminateProcess (); err != nil {
348
- p .proxyLogger .Infof ("Failed to gracefully terminate process [%s] : %v" , p .ID , err )
348
+ p .proxyLogger .Infof ("<%s> Failed to gracefully terminate process: %v" , p .ID , err )
349
349
}
350
350
351
351
select {
352
352
case <- sigtermTimeout .Done ():
353
- p .proxyLogger .Infof ("Process [%s] timed out waiting to stop, sending KILL signal" , p .ID )
353
+ p .proxyLogger .Infof ("<%s> Process timed out waiting to stop, sending KILL signal" , p .ID )
354
354
p .cmd .Process .Kill ()
355
355
case err := <- p .cmdWaitChan :
356
356
// Note: in start(), p.cmdWaitChan also has a select { ... }. That should be OK
@@ -359,24 +359,23 @@ func (p *Process) stopCommand(sigtermTTL time.Duration) {
359
359
// succeeded but that's not a case llama-swap is handling for now.
360
360
if err != nil {
361
361
if errno , ok := err .(syscall.Errno ); ok {
362
- p .proxyLogger .Errorf ("Process [%s] errno >> %v" , p .ID , errno )
362
+ p .proxyLogger .Errorf ("<%s> errno >> %v" , p .ID , errno )
363
363
} else if exitError , ok := err .(* exec.ExitError ); ok {
364
364
if strings .Contains (exitError .String (), "signal: terminated" ) {
365
- p .proxyLogger .Infof ("Process [%s] stopped OK" , p .ID )
365
+ p .proxyLogger .Infof ("<%s> Process stopped OK" , p .ID )
366
366
} else if strings .Contains (exitError .String (), "signal: interrupt" ) {
367
- p .proxyLogger .Infof ("Process [%s] interrupted OK" , p .ID )
367
+ p .proxyLogger .Infof ("<%s> Process interrupted OK" , p .ID )
368
368
} else {
369
- p .proxyLogger .Warnf ("Process [%s] ExitError >> %v, exit code: %d" , p .ID , exitError , exitError .ExitCode ())
369
+ p .proxyLogger .Warnf ("<%s> ExitError >> %v, exit code: %d" , p .ID , exitError , exitError .ExitCode ())
370
370
}
371
371
} else {
372
- p .proxyLogger .Errorf ("Process [%s] exited >> %v" , p .ID , err )
372
+ p .proxyLogger .Errorf ("<%s> Process exited >> %v" , p .ID , err )
373
373
}
374
374
}
375
375
}
376
376
}
377
377
378
378
func (p * Process ) checkHealthEndpoint (healthURL string ) error {
379
-
380
379
client := & http.Client {
381
380
Timeout : 500 * time .Millisecond ,
382
381
}
@@ -471,6 +470,6 @@ func (p *Process) ProxyRequest(w http.ResponseWriter, r *http.Request) {
471
470
}
472
471
473
472
totalTime := time .Since (requestBeginTime )
474
- p .proxyLogger .Debugf ("Process [%s] request %s - start: %v, total: %v" ,
473
+ p .proxyLogger .Debugf ("<%s> request %s - start: %v, total: %v" ,
475
474
p .ID , r .RequestURI , startDuration , totalTime )
476
475
}
0 commit comments