Skip to content

Commit 62b11cf

Browse files
gavin-aguiarGavin Aguiar
andauthored
Added worker metadata to init and reload response (#1166)
* Added worker metadata to init and reload response * Added more asserts to tests --------- Co-authored-by: Gavin Aguiar <gavin@GavinPC>
1 parent d7e5c84 commit 62b11cf

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

azure_functions_worker/dispatcher.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import concurrent.futures
1010
import logging
1111
import os
12+
import platform
1213
import queue
1314
import sys
1415
import threading
@@ -24,7 +25,8 @@
2425
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT,
2526
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37,
2627
PYTHON_THREADPOOL_THREAD_COUNT_MIN,
27-
PYTHON_ENABLE_DEBUG_LOGGING, SCRIPT_FILE_NAME)
28+
PYTHON_ENABLE_DEBUG_LOGGING, SCRIPT_FILE_NAME,
29+
PYTHON_LANGUAGE_RUNTIME)
2830
from .extension import ExtensionManager
2931
from .logging import disable_console_logging, enable_console_logging
3032
from .logging import enable_debug_logging_recommendation
@@ -93,6 +95,16 @@ def __init__(self, loop: BaseEventLoop, host: str, port: int,
9395
self._grpc_thread: threading.Thread = threading.Thread(
9496
name='grpc-thread', target=self.__poll_grpc)
9597

98+
@staticmethod
99+
def get_worker_metadata():
100+
return protos.WorkerMetadata(
101+
runtime_name=PYTHON_LANGUAGE_RUNTIME,
102+
runtime_version=f"{sys.version_info.major}."
103+
f"{sys.version_info.minor}",
104+
worker_version=VERSION,
105+
worker_bitness=platform.machine(),
106+
custom_properties={})
107+
96108
def get_sync_tp_workers_set(self):
97109
"""We don't know the exact value of the threadcount set for the Python
98110
3.9 scenarios (as we'll start passing only None by default), and we
@@ -280,6 +292,7 @@ async def _handle__worker_init_request(self, request):
280292
request_id=self.request_id,
281293
worker_init_response=protos.WorkerInitResponse(
282294
capabilities=capabilities,
295+
worker_metadata=self.get_worker_metadata(),
283296
result=protos.StatusResult(
284297
status=protos.StatusResult.Success)))
285298

@@ -552,6 +565,8 @@ async def _handle__function_environment_reload_request(self, request):
552565
func_env_reload_request.function_app_directory)
553566

554567
success_response = protos.FunctionEnvironmentReloadResponse(
568+
capabilities={},
569+
worker_metadata=self.get_worker_metadata(),
555570
result=protos.StatusResult(
556571
status=protos.StatusResult.Success))
557572

azure_functions_worker/protos/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
CloseSharedMemoryResourcesRequest,
3232
CloseSharedMemoryResourcesResponse,
3333
FunctionsMetadataRequest,
34-
FunctionMetadataResponse)
34+
FunctionMetadataResponse,
35+
WorkerMetadata)
3536

3637
from .shared.NullableTypes_pb2 import (
3738
NullableString,

azure_functions_worker/protos/_src/src/proto/FunctionRpc.proto

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ message FunctionEnvironmentReloadRequest {
238238
}
239239

240240
message FunctionEnvironmentReloadResponse {
241+
// After specialization, worker sends capabilities & metadata.
242+
// Worker metadata captured for telemetry purposes
243+
WorkerMetadata worker_metadata = 1;
244+
245+
// A map of worker supported features/capabilities
246+
map<string, string> capabilities = 2;
247+
241248
// Status of the response
242249
StatusResult result = 3;
243250
}
@@ -431,6 +438,7 @@ message TypedData {
431438
CollectionDouble collection_double = 10;
432439
CollectionSInt64 collection_sint64 = 11;
433440
ModelBindingData model_binding_data = 12;
441+
CollectionModelBindingData collection_model_binding_data = 13;
434442
}
435443
}
436444

@@ -668,4 +676,9 @@ message ModelBindingData
668676

669677
// The binding data content
670678
bytes content = 4;
679+
}
680+
681+
// Used to encapsulate collection model_binding_data
682+
message CollectionModelBindingData {
683+
repeated ModelBindingData model_binding_data = 1;
671684
}

tests/unittests/test_dispatcher.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from unittest.mock import patch
99

1010
from azure_functions_worker import protos
11+
from azure_functions_worker.version import VERSION
1112
from tests.utils import testutils
1213
from azure_functions_worker.constants import PYTHON_THREADPOOL_THREAD_COUNT, \
1314
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT, \
@@ -62,6 +63,27 @@ async def test_dispatcher_initialize_worker(self):
6263
async with self._ctrl as host:
6364
r = await host.init_worker('3.0.12345')
6465
self.assertIsInstance(r.response, protos.WorkerInitResponse)
66+
self.assertIsInstance(r.response.worker_metadata,
67+
protos.WorkerMetadata)
68+
self.assertEquals(r.response.worker_metadata.runtime_name,
69+
"python")
70+
self.assertEquals(r.response.worker_metadata.worker_version,
71+
VERSION)
72+
73+
async def test_dispatcher_environment_reload(self):
74+
"""Test function environment reload response
75+
"""
76+
async with self._ctrl as host:
77+
# Reload environment variable on specialization
78+
r = await host.reload_environment(environment={})
79+
self.assertIsInstance(r.response,
80+
protos.FunctionEnvironmentReloadResponse)
81+
self.assertIsInstance(r.response.worker_metadata,
82+
protos.WorkerMetadata)
83+
self.assertEquals(r.response.worker_metadata.runtime_name,
84+
"python")
85+
self.assertEquals(r.response.worker_metadata.worker_version,
86+
VERSION)
6587

6688
async def test_dispatcher_initialize_worker_logging(self):
6789
"""Test if the dispatcher's log can be flushed out during worker

0 commit comments

Comments
 (0)