Skip to content
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

Improve indexing related logs #1112

Merged
merged 8 commits into from
Oct 6, 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
22 changes: 16 additions & 6 deletions azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ async def _handle__functions_metadata_request(self, request):
directory = metadata_request.function_app_directory
function_path = os.path.join(directory, SCRIPT_FILE_NAME)

logger.info(
'Received WorkerMetadataRequest, request ID %s, directory: %s',
self.request_id, directory)

if not os.path.exists(function_path):
# Fallback to legacy model
logger.info(f"{SCRIPT_FILE_NAME} does not exist. "
Expand All @@ -310,13 +314,15 @@ async def _handle__functions_metadata_request(self, request):
try:
fx_metadata_results = []
indexed_functions = loader.index_function_app(function_path)
logger.info('Indexed function app and found {} functions',
len(indexed_functions))
if indexed_functions:
indexed_function_logs: List[str] = []
for func in indexed_functions:
function_log = \
f"Function Name: {func.get_function_name()} " \
"Function Binding: " \
f"{[binding.name for binding in func.get_bindings()]}"
function_log = "Function Name: {}, Function Binding: {}" \
.format(func.get_function_name(),
[(binding.type, binding.name) for binding in
func.get_bindings()])
indexed_function_logs.append(function_log)

logger.info(
gavin-aguiar marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -327,8 +333,8 @@ async def _handle__functions_metadata_request(self, request):
self._functions,
indexed_functions)
else:
logger.warning("No functions indexed. Please refer to the "
"documentation.")
logger.warning("No functions indexed. Please refer to "
"aka.ms/pythonprogrammingmodel for more info.")

return protos.StreamingMessage(
request_id=request.request_id,
Expand All @@ -350,6 +356,10 @@ async def _handle__function_load_request(self, request):
function_id = func_request.function_id
function_name = func_request.metadata.name

logger.info(
'Received WorkerLoadRequest, request ID %s, function_id: %s,'
'function_name: %s,', self.request_id, function_id, function_name)

try:
if not self._functions.get_function(function_id):
func = loader.load_function(
Expand Down
17 changes: 13 additions & 4 deletions azure_functions_worker/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
_DEFAULT_SCRIPT_FILENAME = '__init__.py'
_DEFAULT_ENTRY_POINT = 'main'

PKGS_PATH = pathlib.Path("site/wwwroot/.python_packages")
home = pathlib.Path.home()
pkgs_path = os.path.join(home, PKGS_PATH)


_submodule_dirs = []


Expand Down Expand Up @@ -88,8 +93,10 @@ def process_indexed_function(functions_registry: functions.Registry,
expt_type=ImportError,
message=f'Please check the requirements.txt file for the missing module. '
f'For more info, please refer the troubleshooting'
f' guide: {MODULE_NOT_FOUND_TS_URL} '
)
f' guide: {MODULE_NOT_FOUND_TS_URL} ',
debug_logs='Error in load_function. '
f'Sys Path: {sys.path}, Sys Module: {sys.modules},'
f'python-packages Path exists: {os.path.exists(pkgs_path)}')
def load_function(name: str, directory: str, script_file: str,
entry_point: Optional[str]):
dir_path = pathlib.Path(directory)
Expand Down Expand Up @@ -137,8 +144,10 @@ def load_function(name: str, directory: str, script_file: str,

@attach_message_to_exception(
expt_type=ImportError,
message=f'Troubleshooting Guide: {MODULE_NOT_FOUND_TS_URL}'
)
message=f'Troubleshooting Guide: {MODULE_NOT_FOUND_TS_URL}',
debug_logs='Error in index_function_app. '
f'Sys Path: {sys.path}, Sys Module: {sys.modules},'
f'python-packages Path exists: {os.path.exists(pkgs_path)}')
def index_function_app(function_path: str):
module_name = pathlib.Path(function_path).stem
imported_module = importlib.import_module(module_name)
Expand Down
10 changes: 8 additions & 2 deletions azure_functions_worker/utils/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from typing import Callable, Any

from .common import is_envvar_true, is_envvar_false
from .tracing import extend_exception_message
from typing import Callable, Any
from ..logging import logger


def enable_feature_by(flag: str,
Expand Down Expand Up @@ -33,12 +36,15 @@ def call(*args, **kwargs):
return decorate


def attach_message_to_exception(expt_type: Exception, message: str) -> Callable:
def attach_message_to_exception(expt_type: Exception, message: str,
debug_logs=None) -> Callable:
def decorate(func):
def call(*args, **kwargs):
try:
return func(*args, **kwargs)
except expt_type as e:
if debug_logs is not None:
logger.error(debug_logs)
gavin-aguiar marked this conversation as resolved.
Show resolved Hide resolved
raise extend_exception_message(e, message)
return call
return decorate
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"azure-eventhub~=5.7.0", # Used for EventHub E2E tests
"azure-functions-durable", # Used for Durable E2E tests
"flask",
"fastapi",
"fastapi~=0.85.0", # Used for ASGIMiddleware test
"pydantic",
"pycryptodome~=3.10.1",
"flake8~=4.0.1",
Expand Down
2 changes: 2 additions & 0 deletions tests/endtoend/test_sql_functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import json
from unittest import skip

from azure_functions_worker import testutils


@skip("Unskip when azure functions with SQL is released.")
class TestSqlFunctions(testutils.WebHostTestCase):

@classmethod
Expand Down