Skip to content

Commit

Permalink
Merge pull request #24 from newrelic/mwhelan/unfixHostAndTime
Browse files Browse the repository at this point in the history
Work arounds for Lambda platform bugs
  • Loading branch information
Matt Whelan authored Nov 12, 2020
2 parents 268b461 + 72eb51c commit 4db8dd9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lambda/logserver/logserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
const (
platformLogBufferSize = 100
defaultHost = "sandbox"
fallbackHost = "169.254.79.130"
)

type LogLine struct {
Expand Down Expand Up @@ -127,9 +128,13 @@ func Start() (*LogServer, error) {
}

func startInternal(host string) (*LogServer, error) {
listener, err := net.Listen("tcp", host+":")
// TODO: replace fallbackHost with host and remove the fallback in the error handler once 'sandbox' resolves.
listener, err := net.Listen("tcp", fallbackHost+":")
if err != nil {
return nil, err
listener, err = net.Listen("tcp", host+":")
if err != nil {
return nil, err
}
}

server := http.Server{}
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ func mainLoop(invocationClient *client.InvocationClient, batch *telemetry.Batch,
// Await agent telemetry. This may time out, so we race the timeout against the telemetry channel
// timeoutInstant is when the invocation will time out
timeoutInstant := time.Unix(0, event.DeadlineMs*int64(time.Millisecond))
// TODO: Delete this after the deadlineMs bug is fixed in all regions
if timeoutInstant.Before(time.Now()) {
timeoutInstant = eventStart.Add(15 * time.Minute) // Max timeout; disables timeout detection
}

// Set the timeout timer for a smidge before the actual timeout; we can recover from early.
timeout := time.NewTimer(timeoutInstant.Sub(time.Now()) - time.Millisecond)
select {
Expand Down
2 changes: 1 addition & 1 deletion telemetry/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func CompressedPayloadsForLogEvents(logsEvents []LogsEvent, functionName string,
FunctionName: functionName,
InvokedFunctionARN: invokedFunctionARN,
LogGroupName: logGroupName,
LogStreamName: "newrelic-lambda-extension:1.0.0",
LogStreamName: "newrelic-lambda-extension:1.0.1",
}
data := RequestData{Context: context, Entry: string(entry)}

Expand Down

0 comments on commit 4db8dd9

Please sign in to comment.