Skip to content

Enable debug logging add recommendation #948

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 7 commits into from
Feb 1, 2022
Merged
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
9 changes: 6 additions & 3 deletions azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@
from . import functions
from . import loader
from . import protos
from .bindings.shared_memory_data_transfer import SharedMemoryManager
from .constants import (PYTHON_THREADPOOL_THREAD_COUNT,
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT,
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37,
PYTHON_THREADPOOL_THREAD_COUNT_MIN,
PYTHON_ENABLE_DEBUG_LOGGING)
from .extension import ExtensionManager
from .logging import disable_console_logging, enable_console_logging
from .logging import enable_debug_logging_recommendation
from .logging import (logger, error_logger, is_system_log_category,
CONSOLE_LOG_PREFIX)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we merge these three imports into one?

from .extension import ExtensionManager
from .utils.common import get_app_setting, is_envvar_true
from .utils.tracing import marshall_exception_trace
from .utils.dependency import DependencyManager
from .utils.tracing import marshall_exception_trace
from .utils.wrappers import disable_feature_by
from .bindings.shared_memory_data_transfer import SharedMemoryManager

_TRUE = "true"

Expand Down Expand Up @@ -262,6 +263,7 @@ async def _handle__worker_init_request(self, req):
logger.info('Received WorkerInitRequest, '
'python version %s, worker version %s, request ID %s',
sys.version, __version__, self.request_id)
enable_debug_logging_recommendation()

worker_init_request = req.worker_init_request
host_capabilities = worker_init_request.capabilities
Expand Down Expand Up @@ -459,6 +461,7 @@ async def _handle__function_environment_reload_request(self, req):
try:
logger.info('Received FunctionEnvironmentReloadRequest, '
'request ID: %s', self.request_id)
enable_debug_logging_recommendation()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vrdmr Should we pass this along with the above 'Received FunctionEnvironmentReloadRequest' log, so we have only one grpc call here? Same with the worker init request

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the init, it won't matter much as grpc overhead for only one call is very low. It is when that call is repeated multiple times, then it'll start hampering us.

Also, as this is something that we are expecting customers to observe and take action if necessary, I think we shouldn't mix it with the other logs.

I would recommend keeping as it is.


func_env_reload_request = req.function_environment_reload_request

Expand Down
5 changes: 5 additions & 0 deletions azure_functions_worker/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def enable_console_logging() -> None:
logger.addHandler(handler)


def enable_debug_logging_recommendation():
logging.info("To enable debug level logging, please refer to "
"https://aka.ms/python-enable-debug-logging")


def is_system_log_category(ctg: str) -> bool:
"""Check if the logging namespace belongs to system logs. Category starts
with the following name will be treated as system logs.
Expand Down
30 changes: 30 additions & 0 deletions tests/unittests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,36 @@ async def test_dispatcher_initialize_worker_logging(self):
1
)

self.assertEqual(
len([l for l in r.logs if l.message.startswith(
'To enable debug level logging'
)]),
1
)

async def test_dispatcher_environment_reload_logging(self):
"""Test if the sync threadpool will pick up app setting in placeholder
mode (Linux Consumption)
"""
async with self._ctrl as host:
await self._check_if_function_is_ok(host)

# Reload environment variable on specialization
r = await host.reload_environment(environment={})
self.assertEqual(
len([l for l in r.logs if l.message.startswith(
'Received FunctionEnvironmentReloadRequest'
)]),
1
)

self.assertEqual(
len([l for l in r.logs if l.message.startswith(
'To enable debug level logging'
)]),
1
)

async def test_dispatcher_send_worker_request(self):
"""Test if the worker status response will be sent correctly when
a worker status request is received
Expand Down