Skip to content

python specific app setting logs added #1353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# For all file changes, github would automatically
# include the following people in the PRs.

* @vrdmr @gavin-aguiar @YunchuWang @pdthummar
* @vrdmr @gavin-aguiar @YunchuWang @pdthummar @hallvictoria
43 changes: 43 additions & 0 deletions azure_functions_worker/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import os
import sys

# Capabilities
Expand Down Expand Up @@ -53,3 +54,45 @@

# Paths
CUSTOMER_PACKAGES_PATH = "/home/site/wwwroot/.python_packages/lib/site-packages"


def get_python_appsetting_state():
app_settings = {
"PYTHON_ROLLBACK_CWD_PATH":
get_statement(PYTHON_ROLLBACK_CWD_PATH,
""),
"PYTHON_THREADPOOL_THREAD_COUNT":
get_statement(PYTHON_THREADPOOL_THREAD_COUNT,
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT),
"PYTHON_ISOLATE_WORKER_DEPENDENCIES":
get_statement(PYTHON_ISOLATE_WORKER_DEPENDENCIES,
PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT),
"PYTHON_ENABLE_WORKER_EXTENSIONS":
get_statement(PYTHON_ENABLE_WORKER_EXTENSIONS,
PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT),
"PYTHON_ENABLE_DEBUG_LOGGING":
get_statement(PYTHON_ENABLE_DEBUG_LOGGING,
"0"),
"FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED":
get_statement(FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED,
"0")
}

# convert to string
app_settings_string = ""
for item in app_settings:
app_settings_string += item + ": " + app_settings[item] + " "

return app_settings_string


def get_statement(app_setting, default_value):
app_setting_state = os.getenv(app_setting)

if app_setting_state is None:
app_setting_state = str(default_value)

if app_setting in os.environ:
return "set to " + app_setting_state + " by customer"
else:
return "set to " + app_setting_state + " by default"
20 changes: 14 additions & 6 deletions azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

from . import bindings, constants, functions, loader, protos
from .bindings.shared_memory_data_transfer import SharedMemoryManager
from .constants import (PYTHON_THREADPOOL_THREAD_COUNT,
from .constants import (PYTHON_ROLLBACK_CWD_PATH,
PYTHON_THREADPOOL_THREAD_COUNT,
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT,
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37,
PYTHON_THREADPOOL_THREAD_COUNT_MIN,
PYTHON_ENABLE_DEBUG_LOGGING, SCRIPT_FILE_NAME,
PYTHON_LANGUAGE_RUNTIME, CUSTOMER_PACKAGES_PATH)
PYTHON_ENABLE_DEBUG_LOGGING,
SCRIPT_FILE_NAME,
PYTHON_LANGUAGE_RUNTIME, CUSTOMER_PACKAGES_PATH,
get_python_appsetting_state)
from .extension import ExtensionManager
from .logging import disable_console_logging, enable_console_logging
from .logging import (logger, error_logger, is_system_log_category,
Expand Down Expand Up @@ -265,11 +268,14 @@ async def _handle__worker_init_request(self, request):
'python version %s, '
'worker version %s, '
'request ID %s.'
'App Settings state: %s.'
' To enable debug level logging, please refer to '
'https://aka.ms/python-enable-debug-logging',
sys.version,
VERSION,
self.request_id)
self.request_id,
get_python_appsetting_state()
)

worker_init_request = request.worker_init_request
host_capabilities = worker_init_request.capabilities
Expand Down Expand Up @@ -546,9 +552,11 @@ async def _handle__function_environment_reload_request(self, request):
try:
logger.info('Received FunctionEnvironmentReloadRequest, '
'request ID: %s,'
'App Settings state: %s.',
' To enable debug level logging, please refer to '
'https://aka.ms/python-enable-debug-logging',
self.request_id)
self.request_id,
get_python_appsetting_state())

func_env_reload_request = \
request.function_environment_reload_request
Expand Down Expand Up @@ -689,7 +697,7 @@ def _get_context(invoc_request: protos.InvocationRequest, name: str,
name, directory, invoc_request.invocation_id,
_invocation_id_local, trace_context, retry_context)

@disable_feature_by(constants.PYTHON_ROLLBACK_CWD_PATH)
@disable_feature_by(PYTHON_ROLLBACK_CWD_PATH)
def _change_cwd(self, new_cwd: str):
if os.path.exists(new_cwd):
os.chdir(new_cwd)
Expand Down