Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit04aa2bc

Browse files
authored
LDM as provisioner of debug-enabled containers (#12851)
1 parent3a47a8f commit04aa2bc

File tree

19 files changed

+670
-541
lines changed

19 files changed

+670
-541
lines changed

‎localstack-core/localstack/services/lambda_/event_source_mapping/esm_worker_factory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
SqsPoller,
3838
)
3939
fromlocalstack.services.lambda_.event_source_mapping.senders.lambda_senderimportLambdaSender
40-
fromlocalstack.utils.aws.arnsimportparse_arn
41-
fromlocalstack.utils.aws.client_typesimportServicePrincipal
42-
fromlocalstack.utils.lambda_debug_mode.lambda_debug_modeimport (
40+
fromlocalstack.services.lambda_.lambda_debug_mode.ldmimport (
4341
DEFAULT_LAMBDA_DEBUG_MODE_TIMEOUT_SECONDS,
44-
is_lambda_debug_mode,
42+
LDM,
4543
)
44+
fromlocalstack.utils.aws.arnsimportparse_arn
45+
fromlocalstack.utils.aws.client_typesimportServicePrincipal
4646

4747

4848
classPollerHolder:
@@ -65,7 +65,7 @@ def get_esm_worker(self) -> EsmWorker:
6565
# Sender (always Lambda)
6666
function_arn=self.esm_config["FunctionArn"]
6767

68-
ifis_lambda_debug_mode():
68+
ifLDM.is_enabled():
6969
timeout_seconds=DEFAULT_LAMBDA_DEBUG_MODE_TIMEOUT_SECONDS
7070
else:
7171
# 900s is the maximum amount of time a Lambda can run for.

‎localstack-core/localstack/services/lambda_/invocation/assignment.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
InitializationType,
1616
OtherServiceEndpoint,
1717
)
18-
fromlocalstack.utils.lambda_debug_mode.lambda_debug_modeimport (
19-
is_lambda_debug_enabled_for,
20-
is_lambda_debug_timeout_enabled_for,
21-
)
2218

2319
LOG=logging.getLogger(__name__)
2420

@@ -79,10 +75,7 @@ def get_environment(
7975

8076
try:
8177
yieldexecution_environment
82-
ifis_lambda_debug_timeout_enabled_for(lambda_arn=function_version.qualified_arn):
83-
self.stop_environment(execution_environment)
84-
else:
85-
execution_environment.release()
78+
execution_environment.release()
8679
exceptInvalidStatusExceptionasinvalid_e:
8780
LOG.error("InvalidStatusException: %s",invalid_e)
8881
exceptExceptionase:
@@ -143,21 +136,6 @@ def scale_provisioned_concurrency(
143136
function_version:FunctionVersion,
144137
target_provisioned_environments:int,
145138
)->list[Future[None]]:
146-
# Enforce a single environment per lambda version if this is a target
147-
# of an active Lambda Debug Mode.
148-
qualified_lambda_version_arn=function_version.qualified_arn
149-
if (
150-
is_lambda_debug_enabled_for(qualified_lambda_version_arn)
151-
andtarget_provisioned_environments>0
152-
):
153-
LOG.warning(
154-
"Environments for '%s' enforced to '1' by Lambda Debug Mode, "
155-
"configurations will continue to report the set value '%s'",
156-
qualified_lambda_version_arn,
157-
target_provisioned_environments,
158-
)
159-
target_provisioned_environments=1
160-
161139
current_provisioned_environments= [
162140
e
163141
foreinself.environments[version_manager_id].values()

‎localstack-core/localstack/services/lambda_/invocation/counting_service.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
InitializationType,
1212
)
1313
fromlocalstack.services.lambda_.invocation.modelsimportlambda_stores
14-
fromlocalstack.utils.lambda_debug_mode.lambda_debug_modeimport (
15-
is_lambda_debug_enabled_for,
16-
)
1714

1815
LOG=logging.getLogger(__name__)
1916

@@ -130,24 +127,6 @@ def get_invocation_lease(
130127
unqualified_function_arn=function_version.id.unqualified_arn()
131128
qualified_arn=function_version.id.qualified_arn()
132129

133-
# Enforce one lease per ARN if the global flag is set
134-
ifis_lambda_debug_enabled_for(qualified_arn):
135-
withprovisioned_tracker.lock,on_demand_tracker.lock:
136-
on_demand_executions:int=on_demand_tracker.concurrent_executions[
137-
unqualified_function_arn
138-
]
139-
provisioned_executions=provisioned_tracker.concurrent_executions[qualified_arn]
140-
ifon_demand_executionsorprovisioned_executions:
141-
LOG.warning(
142-
"Concurrent lambda invocations disabled for '%s' by Lambda Debug Mode",
143-
qualified_arn,
144-
)
145-
raiseTooManyRequestsException(
146-
"Rate Exceeded.",
147-
Reason="SingleLeaseEnforcement",
148-
Type="User",
149-
)
150-
151130
lease_type=None
152131
# HACK: skip reserved and provisioned concurrency if function not available (e.g., in Lambda@Edge)
153132
iffunctionisnotNone:

‎localstack-core/localstack/services/lambda_/invocation/docker_runtime_executor.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
LambdaRuntimeException,
2424
RuntimeExecutor,
2525
)
26+
fromlocalstack.services.lambda_.lambda_debug_mode.ldmimportLDM_ENV_VAR_DEBUG_PORT
2627
fromlocalstack.services.lambda_.lambda_utilsimportHINT_LOG
2728
fromlocalstack.services.lambda_.networkingimport (
2829
get_all_container_networks_for_lambda,
@@ -43,7 +44,6 @@
4344
)
4445
fromlocalstack.utils.docker_utilsimportDOCKER_CLIENTasCONTAINER_CLIENT
4546
fromlocalstack.utils.filesimportchmod_r,rm_rf
46-
fromlocalstack.utils.lambda_debug_mode.lambda_debug_modeimportlambda_debug_port_for
4747
fromlocalstack.utils.netimportget_free_tcp_port
4848
fromlocalstack.utils.stringsimportshort_uid,truncate
4949

@@ -321,9 +321,6 @@ def start(self, env_vars: dict[str, str]) -> None:
321321
platform=docker_platform(self.function_version.config.architectures[0]),
322322
additional_flags=config.LAMBDA_DOCKER_FLAGS,
323323
)
324-
debug_port=lambda_debug_port_for(self.function_version.qualified_arn)
325-
ifdebug_portisnotNone:
326-
container_config.ports.add(debug_port,debug_port)
327324

328325
ifself.function_version.config.package_type==PackageType.Zip:
329326
ifself.function_version.config.code.is_hot_reloading():
@@ -379,6 +376,10 @@ def start(self, env_vars: dict[str, str]) -> None:
379376
container_config.ports=PortMappings()
380377
container_config.ports.add(config.LAMBDA_INIT_DELVE_PORT,config.LAMBDA_INIT_DELVE_PORT)
381378

379+
ifldm_debug_port:=env_vars.get(LDM_ENV_VAR_DEBUG_PORT):
380+
ldm_debug_port=int(ldm_debug_port)
381+
container_config.ports.add(ldm_debug_port,ldm_debug_port)
382+
382383
if (
383384
self.function_version.config.layers
384385
andnotconfig.LAMBDA_PREBUILD_IMAGES

‎localstack-core/localstack/services/lambda_/invocation/execution_environment.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
RuntimeExecutor,
2121
get_runtime_executor,
2222
)
23-
fromlocalstack.utils.lambda_debug_mode.lambda_debug_modeimport (
24-
DEFAULT_LAMBDA_DEBUG_MODE_TIMEOUT_SECONDS,
25-
is_lambda_debug_timeout_enabled_for,
26-
)
2723
fromlocalstack.utils.stringsimportto_str
2824
fromlocalstack.utils.xray.trace_headerimportTraceHeader
2925

@@ -139,7 +135,7 @@ def get_environment_variables(self) -> Dict[str, str]:
139135
# AWS_LAMBDA_DOTNET_PREJIT
140136
"TZ":":UTC",
141137
# 2) Public AWS RIE interface: https://github.com/aws/aws-lambda-runtime-interface-emulator
142-
"AWS_LAMBDA_FUNCTION_TIMEOUT":self._get_execution_timeout_seconds(),
138+
"AWS_LAMBDA_FUNCTION_TIMEOUT":self.function_version.config.timeout,
143139
# 3) Public LocalStack endpoint
144140
"LOCALSTACK_HOSTNAME":self.runtime_executor.get_endpoint_from_executor(),
145141
"EDGE_PORT":str(config.GATEWAY_LISTEN[0].port),
@@ -388,18 +384,5 @@ def get_credentials(self) -> Credentials:
388384
DurationSeconds=43200,
389385
)["Credentials"]
390386

391-
def_get_execution_timeout_seconds(self)->int:
392-
# Returns the timeout value in seconds to be enforced during the execution of the
393-
# lambda function. This is the configured value or the DEBUG MODE default if this
394-
# is enabled.
395-
ifis_lambda_debug_timeout_enabled_for(self.function_version.qualified_arn):
396-
returnDEFAULT_LAMBDA_DEBUG_MODE_TIMEOUT_SECONDS
397-
returnself.function_version.config.timeout
398-
399387
def_get_startup_timeout_seconds(self)->int:
400-
# Returns the timeout value in seconds to be enforced during lambda container startups.
401-
# This is the value defined through LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT or the LAMBDA
402-
# DEBUG MODE default if this is enabled.
403-
ifis_lambda_debug_timeout_enabled_for(self.function_version.qualified_arn):
404-
returnDEFAULT_LAMBDA_DEBUG_MODE_TIMEOUT_SECONDS
405388
returnSTARTUP_TIMEOUT_SEC

‎localstack-core/localstack/services/lambda_/invocation/executor_endpoint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
fromlocalstack.httpimportResponse,route
1212
fromlocalstack.services.edgeimportROUTER
1313
fromlocalstack.services.lambda_.invocation.lambda_modelsimportInvocationResult
14-
fromlocalstack.utils.backoffimportExponentialBackoff
15-
fromlocalstack.utils.lambda_debug_mode.lambda_debug_modeimport (
14+
fromlocalstack.services.lambda_.lambda_debug_mode.ldmimport (
1615
DEFAULT_LAMBDA_DEBUG_MODE_TIMEOUT_SECONDS,
17-
is_lambda_debug_mode,
16+
LDM,
1817
)
18+
fromlocalstack.utils.backoffimportExponentialBackoff
1919
fromlocalstack.utils.objectsimportsingleton_factory
2020
fromlocalstack.utils.stringsimportto_str
2121

@@ -209,7 +209,7 @@ def invoke(self, payload: Dict[str, str]) -> InvocationResult:
209209
# Note that if timeouts are enforced for the lambda function invoked at this endpoint
210210
# (this is needs to be configured in the Lambda Debug Mode Config file), the lambda
211211
# function will continue to enforce the expected timeouts.
212-
ifis_lambda_debug_mode():
212+
ifLDM.is_enabled():
213213
# The value is set to a default high value to ensure eventual termination.
214214
timeout_seconds=DEFAULT_LAMBDA_DEBUG_MODE_TIMEOUT_SECONDS
215215
else:

‎localstack-core/localstack/services/lambda_/invocation/lambda_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Invocation:
6666
# = invocation_id
6767
request_id:str
6868
trace_context:dict
69+
user_agent:Optional[str]=None
6970

7071

7172
InitializationType=Literal["on-demand","provisioned-concurrency"]

‎localstack-core/localstack/services/lambda_/invocation/lambda_service.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def invoke(
230230
request_id:str,
231231
payload:bytes|None,
232232
trace_context:dict|None=None,
233+
user_agent:Optional[str]=None,
233234
)->InvocationResult|None:
234235
"""
235236
Invokes a specific version of a lambda
@@ -352,6 +353,7 @@ def invoke(
352353
invoke_time=datetime.now(),
353354
request_id=request_id,
354355
trace_context=trace_context,
356+
user_agent=user_agent,
355357
)
356358
)
357359

@@ -364,6 +366,7 @@ def invoke(
364366
invoke_time=datetime.now(),
365367
request_id=request_id,
366368
trace_context=trace_context,
369+
user_agent=user_agent,
367370
)
368371
)
369372
status= (

‎localstack-core/localstack/services/lambda_/invocation/version_manager.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
record_cw_metric_invocation,
3030
)
3131
fromlocalstack.services.lambda_.invocation.runtime_executorimportget_runtime_executor
32+
fromlocalstack.services.lambda_.lambda_debug_mode.ldmimportLDM
3233
fromlocalstack.utils.stringsimportlong_uid,truncate
3334
fromlocalstack.utils.threadsimportFuncThread,start_thread
3435

@@ -191,6 +192,30 @@ def invoke(self, *, invocation: Invocation) -> InvocationResult:
191192
LOG.warning(message)
192193
raiseServiceException(message)
193194

195+
# If the environment has debugging enabled, route the invocation there;
196+
# debug environments bypass Lambda service quotas.
197+
ifdebug_execution_environment:=LDM.get_execution_environment(
198+
qualified_lambda_arn=self.function_version.qualified_arn,
199+
user_agent=invocation.user_agent,
200+
):
201+
try:
202+
invocation_result=debug_execution_environment.invoke(invocation)
203+
invocation_result.executed_version=self.function_version.id.qualifier
204+
self.store_logs(
205+
invocation_result=invocation_result,execution_env=debug_execution_environment
206+
)
207+
exceptStatusErrorExceptionase:
208+
invocation_result=InvocationResult(
209+
request_id="",
210+
payload=e.payload,
211+
is_error=True,
212+
logs="",
213+
executed_version=self.function_version.id.qualifier,
214+
)
215+
finally:
216+
debug_execution_environment.release()
217+
returninvocation_result
218+
194219
withself.counting_service.get_invocation_lease(
195220
self.function,self.function_version
196221
)asprovisioning_type:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp