Skip to content

fix: Update function directory in load request to use /home/site/wwwroot #1480

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 9 commits into from
Apr 18, 2024
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
3 changes: 3 additions & 0 deletions azure_functions_worker/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@

# Base extension supported Python minor version
BASE_EXT_SUPPORTED_PY_MINOR_VERSION = 8

PYTHON_ENABLE_OPENTELEMETRY = "PYTHON_ENABLE_OPENTELEMETRY"
PYTHON_ENABLE_OPENTELEMETRY_DEFAULT = True
37 changes: 25 additions & 12 deletions azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
PYTHON_SCRIPT_FILE_NAME,
PYTHON_SCRIPT_FILE_NAME_DEFAULT,
PYTHON_LANGUAGE_RUNTIME, PYTHON_ENABLE_INIT_INDEXING,
METADATA_PROPERTIES_WORKER_INDEXED)
METADATA_PROPERTIES_WORKER_INDEXED,
PYTHON_ENABLE_OPENTELEMETRY,
PYTHON_ENABLE_OPENTELEMETRY_DEFAULT)
from .extension import ExtensionManager
from .http_v2 import http_coordinator, initialize_http_server, HttpV2Registry, \
sync_http_request, HttpServerInitError
Expand Down Expand Up @@ -318,10 +320,12 @@ async def _handle__worker_init_request(self, request):
constants.SHARED_MEMORY_DATA_TRANSFER: _TRUE,
}

self.update_opentelemetry_status()
if get_app_setting(setting=PYTHON_ENABLE_OPENTELEMETRY,
default_value=PYTHON_ENABLE_OPENTELEMETRY_DEFAULT):
self.update_opentelemetry_status()

if self._otel_libs_available:
capabilities[constants.WORKER_OPEN_TELEMETRY_ENABLED] = _TRUE
if self._otel_libs_available:
capabilities[constants.WORKER_OPEN_TELEMETRY_ENABLED] = _TRUE

if DependencyManager.should_load_cx_dependencies():
DependencyManager.prioritize_customer_dependencies()
Expand Down Expand Up @@ -383,8 +387,10 @@ def load_function_metadata(self, function_app_directory, caller_info):
function_path = os.path.join(function_app_directory,
script_file_name)

# For V1, the function path will not exist and
# return None.
self._function_metadata_result = (
self.index_functions(function_path)) \
self.index_functions(function_path, function_app_directory)) \
if os.path.exists(function_path) else None

async def _handle__functions_metadata_request(self, request):
Expand Down Expand Up @@ -439,8 +445,9 @@ async def _handle__function_load_request(self, request):

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

programming_model = "V2"
try:
Expand Down Expand Up @@ -705,9 +712,14 @@ async def _handle__function_environment_reload_request(self, request):
bindings.load_binding_registry()

capabilities = {}
self.update_opentelemetry_status()
if self._otel_libs_available:
capabilities[constants.WORKER_OPEN_TELEMETRY_ENABLED] = _TRUE
if get_app_setting(
setting=PYTHON_ENABLE_OPENTELEMETRY,
default_value=PYTHON_ENABLE_OPENTELEMETRY_DEFAULT):
self.update_opentelemetry_status()

if self._otel_libs_available:
capabilities[constants.WORKER_OPEN_TELEMETRY_ENABLED] = (
_TRUE)

if is_envvar_true(PYTHON_ENABLE_INIT_INDEXING):
try:
Expand Down Expand Up @@ -749,7 +761,7 @@ async def _handle__function_environment_reload_request(self, request):
request_id=self.request_id,
function_environment_reload_response=failure_response)

def index_functions(self, function_path: str):
def index_functions(self, function_path: str, function_dir: str):
indexed_functions = loader.index_function_app(function_path)
logger.info(
"Indexed function app and found %s functions",
Expand All @@ -760,7 +772,8 @@ def index_functions(self, function_path: str):
fx_metadata_results, fx_bindings_logs = (
loader.process_indexed_function(
self._functions,
indexed_functions))
indexed_functions,
function_dir))

indexed_function_logs: List[str] = []
indexed_function_bindings_logs = []
Expand Down
4 changes: 2 additions & 2 deletions azure_functions_worker/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def build_variable_interval_retry(retry, max_retry_count, retry_strategy):


def process_indexed_function(functions_registry: functions.Registry,
indexed_functions):
indexed_functions, function_dir):
"""
fx_metadata_results is a list of the RpcFunctionMetadata for
all the functions in the particular app.
Expand Down Expand Up @@ -150,7 +150,7 @@ def process_indexed_function(functions_registry: functions.Registry,
name=function_info.name,
function_id=function_info.function_id,
managed_dependency_enabled=False, # only enabled for PowerShell
directory=function_info.directory,
directory=function_dir,
script_file=indexed_function.function_script_file,
entry_point=function_info.name,
is_proxy=False, # not supported in V4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import time
from datetime import datetime

import azure.functions as func

Expand Down Expand Up @@ -29,3 +31,11 @@ def default_template(req: func.HttpRequest) -> func.HttpResponse:
" personalized response.",
status_code=200
)


@bp.route(route="http_func")
def http_func(req: func.HttpRequest) -> func.HttpResponse:
time.sleep(1)

current_time = datetime.now().strftime("%H:%M:%S")
return func.HttpResponse(f"{current_time}")
8 changes: 8 additions & 0 deletions tests/endtoend/test_worker_process_count_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,11 @@ class TestWorkerProcessCountStein(TestWorkerProcessCount):
def get_script_dir(cls):
return testutils.E2E_TESTS_FOLDER / 'http_functions' /\
'http_functions_stein'


class TestWorkerProcessCountWithBlueprintStein(TestWorkerProcessCount):

@classmethod
def get_script_dir(cls):
return testutils.E2E_TESTS_FOLDER / 'blueprint_functions' /\
'functions_in_blueprint_only'
1 change: 0 additions & 1 deletion tests/unittests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from tests.utils import testutils
from tests.utils.testutils import UNIT_TESTS_ROOT


SysVersionInfo = col.namedtuple("VersionInfo", ["major", "minor", "micro",
"releaselevel", "serial"])
DISPATCHER_FUNCTIONS_DIR = testutils.UNIT_TESTS_FOLDER / 'dispatcher_functions'
Expand Down
Loading