Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/validate-branch-into-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check source branch
env:
SOURCE_BRANCH: ${{ github.head_ref }}
run: |
SOURCE_BRANCH="${{ github.head_ref }}"
if [[ "$SOURCE_BRANCH" != "develop" ]]; then
echo "Error: Only pull requests from develop branch are allowed into main"
echo "Current source branch ($SOURCE_BRANCH)."
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tags
.idea
.DS_Store
.venv
build.log
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestApp_ServeHTTP(t *testing.T) {
defer mockApp.AssertExpectations(t)
mockApp.On("Init", mock.Anything, mock.Anything, mock.Anything).Return(tt.initResponse)
if tt.initResponse == nil {
mockApp.On("Invoke", mock.Anything, mock.Anything, mock.Anything).Return(tt.invokeErr, tt.responseSent)
mockApp.On("Invoke", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tt.invokeErr, tt.responseSent, false)
}

initMsg := intmodel.InitRequestMessage{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type rieInvokeRequest struct {
cognitoIdentityPoolId string
clientContext string
responseMode string
internalInvocationID string

functionVersionID string
}
Expand Down Expand Up @@ -98,6 +99,7 @@ func NewRieInvokeRequest(request *http.Request, writer http.ResponseWriter) (*ri
cognitoIdentityPoolId: cognitoIdentityPoolId,
clientContext: clientContext,
responseMode: request.Header.Get(invoke.ResponseModeHeader),
internalInvocationID: uuid.New().String(),
}

return req, nil
Expand Down Expand Up @@ -184,3 +186,7 @@ func (r *rieInvokeRequest) UpdateFromInitData(initData interop.InitStaticDataPro
func (r *rieInvokeRequest) FunctionVersionID() string {
return r.functionVersionID
}

func (r *rieInvokeRequest) InternalInvocationID() string {
return r.internalInvocationID
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func TestNewRieInvokeRequest(t *testing.T) {
if tt.want.invokeID == "" {
tt.want.invokeID = got.invokeID
}
tt.want.internalInvocationID = got.internalInvocationID

assert.Equal(t, tt.want, got)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func Run(supv supvmodel.ProcessSupervisor, args []string, fileUtil utils.FileUti
}

rieApp := NewHTTPHandler(raptorApp, initMsg)
s, err := raptor.StartServer(raptorApp, rieApp, &raptor.TCPAddress{AddrPort: rieAddr})
s, err := raptor.StartServer(raptorApp, rieApp, &raptor.TCPAddress{AddrPort: rieAddr}, false)
if err != nil {
return nil, nil, nil, fmt.Errorf("could not start RIE server: %w", err)
}
Expand Down

This file was deleted.

12 changes: 0 additions & 12 deletions internal/lambda-managed-instances/aws-lambda-rie/main.go

This file was deleted.

17 changes: 17 additions & 0 deletions internal/lambda-managed-instances/interop/mock_invoke_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@ func (_m *MockInvokeRequest) FunctionVersionID() string {
return r0
}

func (_m *MockInvokeRequest) InternalInvocationID() string {
ret := _m.Called()

if len(ret) == 0 {
panic("no return value specified for InternalInvocationID")
}

var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}

return r0
}

func (_m *MockInvokeRequest) InvokeID() string {
ret := _m.Called()

Expand Down
3 changes: 3 additions & 0 deletions internal/lambda-managed-instances/interop/sandbox_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ type EEStaticData struct {
XRayTracingMode intmodel.XrayTracingMode
ArtefactType intmodel.ArtefactType
RuntimeVersion string
RuntimeRelease string
AmiId string
AvailabilityZoneId string
}
Expand Down Expand Up @@ -301,6 +302,8 @@ type InvokeRequest interface {

UpdateFromInitData(InitStaticDataProvider) model.AppError
FunctionVersionID() string

InternalInvocationID() string
}

type InitStaticDataProvider interface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const (
ShutdownWaitAllProcessesDuration = "WaitCustomerProcessesExitDuration"
ShutdownRuntimeServerDuration = "StopRuntimeServerDuration"

RuntimeNextCountMetric = "RuntimeNextCount"

RuntimeWorkerCountMetric = "RuntimeWorkerCount"

ClientErrorMetric = "ClientError"
ClientErrorReasonTemplate = "ClientErrorReason-%s"
CustomerErrorMetric = "CustomerError"
Expand Down
2 changes: 2 additions & 0 deletions internal/lambda-managed-instances/invoke/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const (
FunctionErrorBodyTrailer = "lambda-runtime-function-error-body"
ResponseModeHeader = "invoke-response-mode"
TraceIdHeader = "x-amzn-trace-id"

RuntimeInvocationIdHeader = "lambda-runtime-invocation-id"
)

type InvokeBodyResponseStatus string
Expand Down
10 changes: 10 additions & 0 deletions internal/lambda-managed-instances/invoke/invoke_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type RuntimeResponseRequest interface {
BodyReader() io.Reader

TrailerError() ErrorForInvoker

InvocationID() string
}

type RuntimeErrorRequest interface {
Expand All @@ -47,6 +49,8 @@ type RuntimeErrorRequest interface {
ReturnCode() int
ErrorDetails() string
GetXrayErrorCause() json.RawMessage

InvocationID() string
}

type runningInvoke interface {
Expand Down Expand Up @@ -195,6 +199,12 @@ func (ir *InvokeRouter) GetRuntimePoolCounts() RuntimePoolCounts {
func (ir *InvokeRouter) ReserveIdleRuntime(ctx context.Context, invokeID interop.InvokeID, timeout time.Duration) (interop.ReserveIdleRuntimeResponse, model.AppError) {
logging.Debug(ctx, "InvokeRouter: reserving idle runtime")

if _, exists := ir.runningInvokes.Get(invokeID); exists {
logging.Warn(ctx, "InvokeRouter: reservation collides with in-flight invoke")
return interop.ReserveIdleRuntimeFailureResponse{ErrorType: model.ErrorDuplicatedInvokeId},
model.NewClientError(ErrInvokeIdAlreadyExists, model.ErrorSeverityError, model.ErrorDuplicatedInvokeId)
}

err := ir.runtimePool.Reserve(invokeID, timeout, func() {
if ir.runtimePool.ExpireReservation(invokeID) {
logging.Info(ctx, "InvokeRouter: reservation expired")
Expand Down
23 changes: 23 additions & 0 deletions internal/lambda-managed-instances/invoke/invoke_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,29 @@ func TestReserveIdleRuntime_DuplicateInvokeID(t *testing.T) {
assert.Equal(t, model.ErrorDuplicatedInvokeId, appErr.ErrorType())
}

func TestReserveIdleRuntime_DuplicateAgainstRunningInvoke(t *testing.T) {
t.Parallel()

mocks, router := createMocksAndInitRouter()

_, err := router.RuntimeNext(mocks.ctx, mocks.runtimeNextRequest)
require.NoError(t, err)

const inFlightID = "reserve-vs-running"
router.runningInvokes.Set(inFlightID, &mocks.runnningInvoke)

resp, appErr := router.ReserveIdleRuntime(mocks.ctx, inFlightID, 100*time.Millisecond)

require.NotNil(t, appErr)
failResp, ok := resp.(interop.ReserveIdleRuntimeFailureResponse)
assert.True(t, ok, "expected ReserveIdleRuntimeFailureResponse")
assert.Equal(t, model.ErrorDuplicatedInvokeId, failResp.ErrorType)
assert.Equal(t, model.ErrorDuplicatedInvokeId, appErr.ErrorType())

assert.Equal(t, 0, router.runtimePool.ReservedCount(), "no reservation should have been recorded")
assert.Equal(t, 1, router.GetRuntimePoolCounts().Idle, "idle runtime should still be available")
}

func TestReserveIdleRuntime_Expiration(t *testing.T) {
t.Parallel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ func (_m *MockRuntimeErrorRequest) ReturnCode() int {
return r0
}

func (_m *MockRuntimeErrorRequest) InvocationID() string {
ret := _m.Called()

if len(ret) == 0 {
panic("no return value specified for InvocationID")
}

var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}

return r0
}

func NewMockRuntimeErrorRequest(t interface {
mock.TestingT
Cleanup(func())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ func (_m *MockRuntimeResponseRequest) TrailerError() ErrorForInvoker {
return r0
}

func (_m *MockRuntimeResponseRequest) InvocationID() string {
ret := _m.Called()

if len(ret) == 0 {
panic("no return value specified for InvocationID")
}

var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}

return r0
}

func NewMockRuntimeResponseRequest(t interface {
mock.TestingT
Cleanup(func())
Expand Down
13 changes: 10 additions & 3 deletions internal/lambda-managed-instances/invoke/reservation_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import (
)

const (
ReserveSuccessMetric = "ReserveSuccess"
ReserveFailedMetric = "ReserveFailed"
ReserveSuccessMetric = "ReserveSuccess"
ReserveFailedMetric = "ReserveFailed"
ReserveParseDurationMetric = "ReserveParseDuration"
ReserveLogicDurationMetric = "ReserveLogicDuration"
)

func ReserveServiceLog(logger servicelogs.Logger, opStart time.Time, invokeID string, appErr model.AppError) {
func ReserveServiceLog(logger servicelogs.Logger, opStart time.Time, invokeID string, appErr model.AppError, parseDuration, reserveDuration time.Duration) {
props := []servicelogs.Property{
{Name: "invoke_id", Value: invokeID},
}
Expand All @@ -43,6 +45,11 @@ func ReserveServiceLog(logger servicelogs.Logger, opStart time.Time, invokeID st
servicelogs.Counter(ReserveFailedMetric, failed),
servicelogs.Counter(interop.ClientErrorMetric, clientErrCnt),
servicelogs.Counter(interop.NonCustomerErrorMetric, nonCustomerErrCnt),
servicelogs.Timer(ReserveParseDurationMetric, parseDuration),
}

if reserveDuration > 0 {
metrics = append(metrics, servicelogs.Timer(ReserveLogicDurationMetric, reserveDuration))
}

if appErr != nil {
Expand Down
Loading