-
Notifications
You must be signed in to change notification settings - Fork 107
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
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e810e0f
python specific app setting logs added
hallvictoria 4ec252d
lint
hallvictoria a7045ad
refactor
hallvictoria 90e6e83
Merge branch 'dev' into hallvictoria/appsetting-logs
vrdmr 59b950b
codeowner
hallvictoria a0c3ca8
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria 28150fb
Merge branch 'hallvictoria/appsetting-logs' of https://github.com/Azu…
hallvictoria 6cefbb7
manual convert dict to string
hallvictoria f69616f
moved to utils, more efficient
hallvictoria 768d509
added to old tests, created new
hallvictoria bafb832
addressing comments
hallvictoria a7c672a
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria 9be2936
Merge branch 'dev' into hallvictoria/appsetting-logs
hallvictoria ba11aa8
fixing tests, efficiency
hallvictoria a1402fe
Merge branch 'hallvictoria/appsetting-logs' of https://github.com/Azu…
hallvictoria e894d9c
python worker ext
hallvictoria e19496d
removed comma
hallvictoria 437cefe
FLAKE
hallvictoria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import os | ||
import sys | ||
|
||
from ..constants import (PYTHON_ROLLBACK_CWD_PATH, | ||
PYTHON_THREADPOOL_THREAD_COUNT, | ||
PYTHON_ISOLATE_WORKER_DEPENDENCIES, | ||
PYTHON_ENABLE_WORKER_EXTENSIONS, | ||
PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT, | ||
PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT_39, | ||
PYTHON_ENABLE_DEBUG_LOGGING, | ||
FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED) | ||
|
||
|
||
def get_python_appsetting_state(): | ||
current_vars = os.environ.copy() | ||
python_specific_settings = \ | ||
[PYTHON_ROLLBACK_CWD_PATH, | ||
PYTHON_THREADPOOL_THREAD_COUNT, | ||
PYTHON_ISOLATE_WORKER_DEPENDENCIES, | ||
PYTHON_ENABLE_DEBUG_LOGGING, | ||
PYTHON_ENABLE_WORKER_EXTENSIONS, | ||
FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED] | ||
|
||
app_setting_states = "".join( | ||
f"{app_setting}: {current_vars[app_setting]} " | ||
for app_setting in python_specific_settings | ||
if app_setting in current_vars | ||
) | ||
|
||
# Special case for extensions | ||
if 'PYTHON_ENABLE_WORKER_EXTENSIONS' not in current_vars: | ||
if sys.version_info.minor == 9: | ||
app_setting_states += \ | ||
(f"{PYTHON_ENABLE_WORKER_EXTENSIONS}: " | ||
f"{str(PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT_39)}") | ||
else: | ||
app_setting_states += \ | ||
(f"{PYTHON_ENABLE_WORKER_EXTENSIONS}: " | ||
f"{str(PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT)} ") | ||
|
||
return app_setting_states |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import collections as col | ||
import os | ||
|
||
from unittest.mock import patch | ||
|
||
from tests.utils import testutils | ||
from azure_functions_worker.utils.app_setting_manager import \ | ||
get_python_appsetting_state | ||
from azure_functions_worker.constants import PYTHON_THREADPOOL_THREAD_COUNT, \ | ||
PYTHON_ENABLE_DEBUG_LOGGING | ||
|
||
SysVersionInfo = col.namedtuple("VersionInfo", ["major", "minor", "micro", | ||
"releaselevel", "serial"]) | ||
DISPATCHER_FUNCTIONS_DIR = testutils.UNIT_TESTS_FOLDER / 'dispatcher_functions' | ||
DISPATCHER_STEIN_FUNCTIONS_DIR = testutils.UNIT_TESTS_FOLDER / \ | ||
'dispatcher_functions' / \ | ||
'dispatcher_functions_stein' | ||
DISPATCHER_STEIN_INVALID_FUNCTIONS_DIR = testutils.UNIT_TESTS_FOLDER / \ | ||
'broken_functions' / \ | ||
'invalid_stein' | ||
|
||
|
||
class TestDefaultAppSettingsLogs(testutils.AsyncTestCase): | ||
"""Tests for default app settings logs.""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls._ctrl = testutils.start_mockhost( | ||
script_root=DISPATCHER_FUNCTIONS_DIR) | ||
os_environ = os.environ.copy() | ||
cls._patch_environ = patch.dict('os.environ', os_environ) | ||
cls._patch_environ.start() | ||
super().setUpClass() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
super().tearDownClass() | ||
cls._patch_environ.stop() | ||
|
||
async def test_initialize_worker_logging(self): | ||
"""Test if the dispatcher's log can be flushed out during worker | ||
initialization | ||
""" | ||
async with self._ctrl as host: | ||
r = await host.init_worker('3.0.12345') | ||
self.assertTrue('App Settings state: ' in log for log in r.logs) | ||
self.assertTrue('PYTHON_ENABLE_WORKER_EXTENSIONS: ' | ||
in log for log in r.logs) | ||
|
||
def test_get_python_appsetting_state(self): | ||
app_setting_state = get_python_appsetting_state() | ||
expected_string = "PYTHON_ENABLE_WORKER_EXTENSIONS: " | ||
self.assertIn(expected_string, app_setting_state) | ||
|
||
|
||
class TestNonDefaultAppSettingsLogs(testutils.AsyncTestCase): | ||
"""Tests for non-default app settings logs.""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls._ctrl = testutils.start_mockhost( | ||
script_root=DISPATCHER_FUNCTIONS_DIR) | ||
os_environ = os.environ.copy() | ||
os_environ[PYTHON_THREADPOOL_THREAD_COUNT] = '20' | ||
os_environ[PYTHON_ENABLE_DEBUG_LOGGING] = '1' | ||
cls._patch_environ = patch.dict('os.environ', os_environ) | ||
cls._patch_environ.start() | ||
super().setUpClass() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
super().tearDownClass() | ||
cls._patch_environ.stop() | ||
|
||
async def test_initialize_worker_logging(self): | ||
"""Test if the dispatcher's log can be flushed out during worker | ||
initialization | ||
""" | ||
async with self._ctrl as host: | ||
r = await host.init_worker('3.0.12345') | ||
self.assertTrue('App Settings state: ' in log for log in r.logs) | ||
self.assertTrue('PYTHON_THREADPOOL_THREAD_COUNT: ' | ||
in log for log in r.logs) | ||
self.assertTrue('PYTHON_ENABLE_DEBUG_LOGGING: ' | ||
in log for log in r.logs) | ||
|
||
def test_get_python_appsetting_state(self): | ||
app_setting_state = get_python_appsetting_state() | ||
expected_string = ("PYTHON_THREADPOOL_THREAD_COUNT: 20 " | ||
"PYTHON_ENABLE_DEBUG_LOGGING: 1 " | ||
"PYTHON_ENABLE_WORKER_EXTENSIONS: ") | ||
self.assertIn(expected_string, app_setting_state) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.