@@ -32,9 +32,7 @@ import (
32
32
// TODO herd launch prevention part deux
33
33
// TODO storing logs / call can push call over the timeout
34
34
// TODO all Datastore methods need to take unit of tenancy (app or route) at least (e.g. not just call id)
35
- // TODO limit the request body length when making calls
36
35
// TODO discuss concrete policy for hot launch or timeout / timeout vs time left
37
- // TODO call env need to be map[string][]string to match headers behavior...
38
36
// TODO it may be nice to have an interchange type for Dispatch that can have
39
37
// all the info we need to build e.g. http req, grpc req, json, etc. so that
40
38
// we can easily do e.g. http->grpc, grpc->http, http->json. ofc grpc<->http is
@@ -50,7 +48,6 @@ import (
50
48
// end up that the client doesn't get a reply until long after the timeout (b/c of container removal, async it?)
51
49
// TODO the call api should fill in all the fields
52
50
// TODO the log api should be plaintext (or at least offer it)
53
- // TODO func logger needs to be hanged, dragged and quartered. in reverse order.
54
51
// TODO we should probably differentiate ran-but-timeout vs timeout-before-run
55
52
// TODO between calls, logs and stderr can contain output/ids from previous call. need elegant solution. grossness.
56
53
// TODO if async would store requests (or interchange format) it would be slick, but
@@ -428,7 +425,6 @@ type slot interface {
428
425
type coldSlot struct {
429
426
cookie drivers.Cookie
430
427
tok Token
431
- stderr io.Closer
432
428
}
433
429
434
430
func (s * coldSlot ) exec (ctx context.Context , call * call ) error {
@@ -459,7 +455,6 @@ func (s *coldSlot) Close() error {
459
455
s .cookie .Close (context .Background ()) // ensure container removal, separate ctx
460
456
}
461
457
s .tok .Close ()
462
- s .stderr .Close ()
463
458
return nil
464
459
}
465
460
@@ -477,20 +472,11 @@ func (s *hotSlot) exec(ctx context.Context, call *call) error {
477
472
span , ctx := opentracing .StartSpanFromContext (ctx , "agent_hot_exec" )
478
473
defer span .Finish ()
479
474
480
- stderr := NewFuncLogger (ctx , call .AppName , call .Path , call .Image , call .ID , call .ds )
481
- if call .w == nil {
482
- // send STDOUT to logs if no writer given (async...)
483
- // TODO fuck func logger, change it to not need a context and make calls
484
- // require providing their own stderr and writer instead of this crap. punting atm.
485
- call .w = stderr
486
- }
487
-
488
475
// link the container id and id in the logs [for us!]
489
476
common .Logger (ctx ).WithField ("container_id" , s .container .id ).Info ("starting call" )
490
477
491
- // swap in the new id and the new stderr logger
492
- s .container .swap (stderr )
493
- defer stderr .Close () // TODO shove in Close / elsewhere (to upload logs after exec exits)
478
+ // swap in the new stderr logger
479
+ s .container .swap (call .stderr )
494
480
495
481
errApp := make (chan error , 1 )
496
482
go func () {
@@ -541,15 +527,6 @@ func (a *agent) launch(ctx context.Context, slots chan<- slot, call *call, tok T
541
527
}
542
528
543
529
func (a * agent ) prepCold (ctx context.Context , slots chan <- slot , call * call , tok Token ) error {
544
- // TODO dupe stderr code, reduce me
545
- stderr := NewFuncLogger (ctx , call .AppName , call .Path , call .Image , call .ID , call .ds )
546
- if call .w == nil {
547
- // send STDOUT to logs if no writer given (async...)
548
- // TODO fuck func logger, change it to not need a context and make calls
549
- // require providing their own stderr and writer instead of this crap. punting atm.
550
- call .w = stderr
551
- }
552
-
553
530
container := & container {
554
531
id : id .New ().String (), // XXX we could just let docker generate ids...
555
532
image : call .Image ,
@@ -558,7 +535,7 @@ func (a *agent) prepCold(ctx context.Context, slots chan<- slot, call *call, tok
558
535
timeout : time .Duration (call .Timeout ) * time .Second , // this is unnecessary, but in case removal fails...
559
536
stdin : call .req .Body ,
560
537
stdout : call .w ,
561
- stderr : stderr ,
538
+ stderr : call . stderr ,
562
539
}
563
540
564
541
// pull & create container before we return a slot, so as to be friendly
@@ -569,7 +546,7 @@ func (a *agent) prepCold(ctx context.Context, slots chan<- slot, call *call, tok
569
546
return err
570
547
}
571
548
572
- slot := & coldSlot {cookie , tok , stderr }
549
+ slot := & coldSlot {cookie , tok }
573
550
select {
574
551
case slots <- slot : // TODO need to make sure receiver will be ready (go routine race)
575
552
default :
@@ -600,19 +577,22 @@ func (a *agent) runHot(slots chan<- slot, call *call, tok Token) error {
600
577
ctx , shutdownContainer := context .WithCancel (context .Background ())
601
578
defer shutdownContainer () // close this if our waiter returns
602
579
580
+ cid := id .New ().String ()
581
+
603
582
// set up the stderr for the first one to capture any logs before the slot is
604
- // executed.
605
- // TODO need to figure out stderr logging for hot functions at a high level
606
- stderr := & ghostWriter {inner : newLineWriter (& logWriter {ctx : ctx , appName : call .AppName , path : call .Path , image : call .Image , reqID : call .ID })}
583
+ // executed and between hot functions TODO this is still a little tobias funke
584
+ stderr := newLineWriter (& logWriter {
585
+ logrus .WithFields (logrus.Fields {"between_log" : true , "app_name" : call .AppName , "path" : call .Path , "image" : call .Image , "container_id" : cid }),
586
+ })
607
587
608
588
container := & container {
609
- id : id . New (). String () , // XXX we could just let docker generate ids...
589
+ id : cid , // XXX we could just let docker generate ids...
610
590
image : call .Image ,
611
591
env : call .BaseEnv , // only base env
612
592
memory : call .Memory ,
613
593
stdin : stdinRead ,
614
594
stdout : stdoutWrite ,
615
- stderr : stderr ,
595
+ stderr : & ghostWriter { inner : stderr } ,
616
596
}
617
597
618
598
logger := logrus .WithFields (logrus.Fields {"id" : container .id , "app" : call .AppName , "route" : call .Path , "image" : call .Image , "memory" : call .Memory , "format" : call .Format , "idle_timeout" : call .IdleTimeout })
@@ -663,6 +643,7 @@ func (a *agent) runHot(slots chan<- slot, call *call, tok Token) error {
663
643
// wait for this call to finish
664
644
// NOTE do NOT select with shutdown / other channels. slot handles this.
665
645
<- done
646
+ container .swap (stderr ) // log between tasks
666
647
}
667
648
}()
668
649
0 commit comments