44 "context"
55 "encoding/base64"
66 "encoding/json"
7- "fmt"
8- "math"
97 "strconv"
108 "strings"
119 "time"
@@ -14,8 +12,6 @@ import (
1412 "github.com/localstack/lambda-runtime-init/internal/logging"
1513 log "github.com/sirupsen/logrus"
1614 "go.amzn.com/lambda/interop"
17- "go.amzn.com/lambda/metering"
18- "go.amzn.com/lambda/rapidcore"
1915 "go.amzn.com/lambda/rapidcore/env"
2016)
2117
@@ -62,12 +58,13 @@ func NewLocalStackService(
6258}
6359
6460func (ls * LocalStackService ) Initialize (bs interop.Bootstrap ) error {
65- timeout , err := time .ParseDuration (ls .function .FunctionTimeoutSec + "s" )
61+ initTimeout := time .Second * 10
62+ invokeTimeout , err := time .ParseDuration (ls .function .FunctionTimeoutSec + "s" )
6663 if err != nil {
6764 log .WithError (err ).
6865 WithField ("AWS_LAMBDA_FUNCTION_TIMEOUT" , ls .function .FunctionTimeoutSec ).
6966 Warnf ("Failed to set function timeout from environment. Defaulting to 30s." )
70- timeout = time .Second * 30
67+ invokeTimeout = time .Second * 30
7168 }
7269
7370 memorySize , err := strconv .ParseUint (ls .function .FunctionMemorySizeMb , 10 , 64 )
@@ -81,8 +78,8 @@ func (ls *LocalStackService) Initialize(bs interop.Bootstrap) error {
8178 initRequest := & interop.Init {
8279 AccountID : ls .aws .Credentials .AccountID ,
8380 Handler : ls .function .FunctionHandler ,
84- InvokeTimeoutMs : timeout .Milliseconds (),
85- InitTimeoutMs : timeout .Milliseconds (),
81+ InvokeTimeoutMs : invokeTimeout .Milliseconds (),
82+ InitTimeoutMs : initTimeout .Milliseconds (),
8683 InstanceMaxMemory : memorySize ,
8784 // TODO: LocalStack does not correctly set this to the LS container's <IP>:<PORT>
8885 XRayDaemonAddress : ls .xrayEndpoint ,
@@ -101,10 +98,15 @@ func (ls *LocalStackService) Initialize(bs interop.Bootstrap) error {
10198 Bootstrap : bs ,
10299 }
103100
104- initStart := metering .Monotime ()
105- err = ls .sandbox .Init (initRequest , timeout .Milliseconds ())
106- ls .initDuration = float64 (metering .Monotime ()- initStart ) / float64 (time .Millisecond )
107- return err
101+ // initStart := metering.Monotime()
102+ // err = ls.sandbox.Init(initRequest, initRequest.InvokeTimeoutMs)
103+ // ls.initDuration = float64(metering.Monotime()-initStart) / float64(time.Millisecond)
104+
105+ // if err != nil {
106+ // _, _ = fmt.Fprintf(ls.logCollector, "INIT_REPORT Init Duration: %.2f ms Phase: init Status: %s", ls.initDuration)
107+ // }
108+
109+ return ls .sandbox .Init (initRequest , initRequest .InvokeTimeoutMs )
108110}
109111
110112func (ls * LocalStackService ) SendStatus (status LocalStackStatus , payload []byte ) error {
@@ -130,7 +132,7 @@ func (ls *LocalStackService) SendResponse(invokeId string, payload []byte) error
130132func (ls * LocalStackService ) InvokeForward (invoke InvokeRequest ) ([]byte , error ) {
131133 proxyResponseWriter := NewResponseWriterProxy ()
132134
133- _ , _ = fmt .Fprintf (ls .logCollector , "START RequestId: %s Version: %s\n " , invoke .InvokeId , ls .function .FunctionVersion )
135+ // _, _ = fmt.Fprintf(ls.logCollector, "START RequestId: %s Version: %s\n", invoke.InvokeId, ls.function.FunctionVersion)
134136
135137 clientContext , err := base64 .StdEncoding .DecodeString (invoke .ClientContext )
136138 if err != nil {
@@ -152,28 +154,28 @@ func (ls *LocalStackService) InvokeForward(invoke InvokeRequest) ([]byte, error)
152154 log .WithError (invokeErr ).Error ("Failed invocation." )
153155 }
154156
155- invokeStartTime := invokePayload .InvokeReceivedTime
156- invokeEndTime := metering .Monotime ()
157+ // invokeStartTime := invokePayload.InvokeReceivedTime
158+ // invokeEndTime := metering.Monotime()
157159
158- durationMs := float64 (invokeEndTime - invokeStartTime ) / float64 (time .Millisecond )
160+ // durationMs := float64(invokeEndTime-invokeStartTime) / float64(time.Millisecond)
159161
160- report := InvokeReport {
161- InvokeId : invoke .InvokeId ,
162- DurationMs : durationMs ,
163- BilledDurationMs : math .Ceil (durationMs ),
164- MemorySizeMB : ls .function .FunctionMemorySizeMb ,
165- MaxMemoryUsedMB : ls .function .FunctionMemorySizeMb ,
166- InitDurationMs : ls .initDuration ,
167- }
162+ // report := InvokeReport{
163+ // InvokeId: invoke.InvokeId,
164+ // DurationMs: durationMs,
165+ // BilledDurationMs: math.Ceil(durationMs),
166+ // MemorySizeMB: ls.function.FunctionMemorySizeMb,
167+ // MaxMemoryUsedMB: ls.function.FunctionMemorySizeMb,
168+ // InitDurationMs: ls.initDuration,
169+ // }
168170
169- switch invokeErr {
170- case rapidcore .ErrInvokeTimeout :
171- report .Status = "timeout"
172- }
171+ // switch invokeErr {
172+ // case rapidcore.ErrInvokeTimeout:
173+ // report.Status = "timeout"
174+ // }
173175
174- if err := report .Print (ls .logCollector ); err != nil {
175- log .WithError (err ).Error ("Failed to write END report." )
176- }
176+ // if err := report.Print(ls.logCollector); err != nil {
177+ // log.WithError(err).Error("Failed to write END report.")
178+ // }
177179
178180 return proxyResponseWriter .Body (), invokeErr
179181}
0 commit comments