Skip to content

Commit bd1e6c9

Browse files
committed
Improved Logging
1 parent 5c6a0ae commit bd1e6c9

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

cmd/simulator/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ func main() {
5656
log.Panicf("Error while initializing HTTP Server: %v", err.Error())
5757
}
5858

59-
if err := http.ListenAndServe(fmt.Sprint("0.0.0.0:", env.Port), e); err != http.ErrServerClosed {
59+
hostPort := fmt.Sprint("0.0.0.0:", env.Port)
60+
61+
log.Infof("Listening on %v", hostPort)
62+
if err := http.ListenAndServe(hostPort, e); err != http.ErrServerClosed {
6063
log.Fatal(err)
6164
}
6265
}

pkg/controller/runtime.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func (r RuntimeController) NextInvocation(c echo.Context) error {
4141
return err
4242
}
4343

44+
if next == nil {
45+
return echo.NewHTTPError(http.StatusNotFound)
46+
}
47+
4448
c.Response().Header().Set(lambda.HeaderLambdaRuntimeAwsRequestId, next.Id)
4549
c.Response().Header().Set(lambda.HeaderLambdaRuntimeInvokedFunctionArn, r.config.Arn)
4650
c.Response().Header().Set(lambda.HeaderLambdaRuntimeDeadlineMs, fmt.Sprint(next.Timeout.Unix()))

pkg/event/service.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewService(cfg *config.Runtime) *Service {
3939
}
4040

4141
func (s *Service) ResetAll() error {
42-
log.Warn("Resetting internal cache")
42+
log.Warn("Resetting internal cache. All pending invocations will return nil")
4343
prevChan := s.channel
4444
s.channel = make(chan *Invocation, 100)
4545
if prevChan != nil {
@@ -62,9 +62,11 @@ func (s Service) GetNextInvocation() (*Invocation, error) {
6262
}
6363

6464
func (s Service) PushInvocation(body string) (string, error) {
65+
log.Debugf("Pushing new invocation: %v", body)
6566
var b interface{}
6667
err := json.Unmarshal([]byte(body), &b)
6768
if err != nil {
69+
log.Errorf("Invalid JSON: %v", err)
6870
return "", err
6971
}
7072

@@ -77,6 +79,7 @@ func (s Service) PushInvocation(body string) (string, error) {
7779
}
7880

7981
invocation.Timeout = now.Add(time.Duration(s.config.TimeoutInSeconds) * time.Second)
82+
log.Debugf("Invocation ID: %v", invocation.Id)
8083

8184
s.holder[invocation.Id] = &invocation
8285
s.channel <- &invocation
@@ -97,11 +100,12 @@ func (s Service) SendResponse(id string, body []byte) error {
97100
}
98101

99102
var b interface{}
100-
err := json.Unmarshal([]byte(body), &b)
103+
err := json.Unmarshal(body, &b)
101104
if err != nil {
102105
return err
103106
}
104107

108+
log.Debugf("Response received %v: %v", id, b)
105109
diff := now.Sub(inv.StartedAt)
106110

107111
inv.Response = b
@@ -130,6 +134,8 @@ func (s Service) SendError(id string, error *RuntimeError, errorType string) err
130134
inv.ErrorType = &errorType
131135
}
132136

137+
log.Debugf("Error received %v: %v,%v", id, error, errorType)
138+
133139
diff := now.Sub(inv.StartedAt)
134140
inv.Duration = utils.ToPointer(int(diff.Seconds()))
135141
return nil

0 commit comments

Comments
 (0)