Skip to content

Commit 1217794

Browse files
committed
Resolving conflicts
2 parents f74f010 + e4ac00f commit 1217794

File tree

12 files changed

+172
-57
lines changed

12 files changed

+172
-57
lines changed

.ci/perf_tests/dockerfiles/perf_tests.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG PYTHON_VERSION=3.8
22

3-
FROM mcr.microsoft.com/azure-functions/python:3.0.15418-python$PYTHON_VERSION
3+
FROM mcr.microsoft.com/azure-functions/python:4-python$PYTHON_VERSION
44

55
# Mounting local machines azure-functions-python-worker and azure-functions-python-library onto it
66
RUN rm -rf /azure-functions-host/workers/python/${PYTHON_VERSION}/LINUX/X64/azure_functions_worker

.github/workflows/codeql-analysis.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ dev, *dev, main*, release* ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ dev ]
20+
schedule:
21+
- cron: '25 11 * * 5'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'javascript', 'python' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v3
42+
43+
# Initializes the CodeQL tools for scanning.
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@v2
46+
with:
47+
languages: ${{ matrix.language }}
48+
# If you wish to specify custom queries, you can do so here or in a config file.
49+
# By default, queries listed here will override any specified in a config file.
50+
# Prefix the list here with "+" to use these queries and those in the config file.
51+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
52+
53+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54+
# If this step fails, then you should remove it and run the build manually (see below)
55+
- name: Autobuild
56+
uses: github/codeql-action/autobuild@v2
57+
58+
# ℹ️ Command-line programs to run using the OS shell.
59+
# 📚 https://git.io/JvXDl
60+
61+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62+
# and modify them (or add more) to build your code if your project
63+
# uses a compiled language
64+
65+
#- run: |
66+
# make bootstrap
67+
# make release
68+
69+
- name: Perform CodeQL Analysis
70+
uses: github/codeql-action/analyze@v2

.github/workflows/perf-testing-setup.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
test_to_run: [ SyncHttpTriggerHelloWorld, SyncHttpTriggerWithSyncRequests, AsyncHttpTriggerWithAsyncRequest, SyncHttpTriggerCPUIntensive ] #, SyncPutBlobAsBytesReturnHttpResponse, SyncGetBlobAsBytesReturnHttpResponse ]
19+
test_to_run: [ SyncHttpTriggerHelloWorld ]
2020
steps:
2121
- uses: actions/checkout@v2
2222
- name: Set up Python ${{ env.PYTHON_VERSION }}
@@ -27,6 +27,14 @@ jobs:
2727
uses: actions/setup-dotnet@v1
2828
with:
2929
dotnet-version: '3.1.405'
30+
- name: Set up Dotnet 5.0.x
31+
uses: actions/setup-dotnet@v1
32+
with:
33+
dotnet-version: '5.0.x'
34+
- name: Set up Dotnet 6.x
35+
uses: actions/setup-dotnet@v1
36+
with:
37+
dotnet-version: '6.x'
3038
- name: Setup k6 for throughput testing
3139
run: |
3240
cd $GITHUB_WORKSPACE

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
# For all file changes, github would automatically
1111
# include the following people in the PRs.
1212

13-
* @vrdmr @gavin-aguiar @YunchuWang
13+
* @vrdmr @gavin-aguiar @YunchuWang @pdthummar

azure_functions_worker/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37 = 32
4545

4646
PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT = False
47-
PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_310 = True
47+
PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_310 = False
4848
PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT = False
4949
PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT_39 = True
5050

azure_functions_worker/loader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def uninstall() -> None:
4646

4747
@attach_message_to_exception(
4848
expt_type=ImportError,
49-
message=f'Troubleshooting Guide: {MODULE_NOT_FOUND_TS_URL}'
49+
message=f'Please check the requirements.txt file for the missing module. '
50+
f'For more info, please refer the troubleshooting'
51+
f' guide: {MODULE_NOT_FOUND_TS_URL} '
5052
)
5153
def load_function(name: str, directory: str, script_file: str,
5254
entry_point: typing.Optional[str]):

azure_functions_worker/testutils_lc.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3-
4-
from typing import Dict
5-
63
import base64
74
import json
85
import os
96
import re
7+
import shutil
108
import subprocess
119
import sys
10+
import tempfile
1211
import time
1312
import uuid
13+
from io import BytesIO
14+
from typing import Dict
15+
from urllib.request import urlopen
16+
from zipfile import ZipFile
1417

18+
import requests
1519
from Crypto.Cipher import AES
1620
from Crypto.Hash.SHA256 import SHA256Hash
1721
from Crypto.Util.Padding import pad
18-
import requests
1922

2023
# Linux Consumption Testing Constants
2124
_DOCKER_PATH = "DOCKER_PATH"
2225
_DOCKER_DEFAULT_PATH = "docker"
2326
_MESH_IMAGE_URL = "https://mcr.microsoft.com/v2/azure-functions/mesh/tags/list"
2427
_MESH_IMAGE_REPO = "mcr.microsoft.com/azure-functions/mesh"
2528
_DUMMY_CONT_KEY = "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY="
29+
_FUNC_GITHUB_ZIP = "https://github.com/Azure/azure-functions-python-library" \
30+
"/archive/refs/heads/dev.zip"
31+
_FUNC_FILE_NAME = "azure-functions-python-library-dev"
2632

2733

2834
class LinuxConsumptionWebHostController:
@@ -80,9 +86,9 @@ def assign_container(self, env: Dict[str, str] = {}):
8086
f' stdout: {stdout}')
8187

8288
def send_request(
83-
self,
84-
req: requests.Request,
85-
ses: requests.Session = None
89+
self,
90+
req: requests.Request,
91+
ses: requests.Session = None
8692
) -> requests.Response:
8793
"""Send a request with authorization token. Return a Response object"""
8894
session = ses
@@ -129,6 +135,12 @@ def _find_latest_mesh_image(cls,
129135
cls._mesh_images[host_major] = image_tag
130136
return image_tag
131137

138+
@staticmethod
139+
def _download_azure_functions() -> str:
140+
with urlopen(_FUNC_GITHUB_ZIP) as zipresp:
141+
with ZipFile(BytesIO(zipresp.read())) as zfile:
142+
zfile.extractall(tempfile.gettempdir())
143+
132144
def spawn_container(self,
133145
image: str,
134146
env: Dict[str, str] = {}) -> int:
@@ -137,10 +149,18 @@ def spawn_container(self,
137149
"""
138150
# Construct environment variables and start the docker container
139151
worker_path = os.path.dirname(__file__)
152+
library_path = os.path.join(tempfile.gettempdir(), _FUNC_FILE_NAME,
153+
'azure', 'functions')
154+
self._download_azure_functions()
155+
140156
container_worker_path = (
141157
f"/azure-functions-host/workers/python/{self._py_version}/"
142158
"LINUX/X64/azure_functions_worker"
143159
)
160+
container_library_path = (
161+
f"/azure-functions-host/workers/python/{self._py_version}/"
162+
"LINUX/X64/azure/functions"
163+
)
144164

145165
run_cmd = []
146166
run_cmd.extend([self._docker_cmd, "run", "-p", "0:80", "-d"])
@@ -150,7 +170,9 @@ def spawn_container(self,
150170
run_cmd.extend(["-e", f"CONTAINER_NAME={self._uuid}"])
151171
run_cmd.extend(["-e", f"CONTAINER_ENCRYPTION_KEY={_DUMMY_CONT_KEY}"])
152172
run_cmd.extend(["-e", "WEBSITE_PLACEHOLDER_MODE=1"])
173+
run_cmd.extend(["-e", "PYTHON_ISOLATE_WORKER_DEPENDENCIES=1"])
153174
run_cmd.extend(["-v", f'{worker_path}:{container_worker_path}'])
175+
run_cmd.extend(["-v", f'{library_path}:{container_library_path}'])
154176

155177
for key, value in env.items():
156178
run_cmd.extend(["-e", f"{key}={value}"])
@@ -181,7 +203,7 @@ def spawn_container(self,
181203
self._ports[self._uuid] = port_number
182204

183205
# Wait for three seconds for the container to be in ready state
184-
time.sleep(3)
206+
time.sleep(6)
185207
return port_number
186208

187209
def get_container_logs(self) -> str:
@@ -259,6 +281,7 @@ def __enter__(self):
259281
def __exit__(self, exc_type, exc_value, traceback):
260282
logs = self.get_container_logs()
261283
self.safe_kill_container()
284+
shutil.rmtree(os.path.join(tempfile.gettempdir(), _FUNC_FILE_NAME))
262285

263286
if traceback:
264287
print(f'Test failed with container logs: {logs}',

tests/endtoend/test_linux_consumption.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3-
from unittest import TestCase, skipIf
4-
53
import os
64
import sys
7-
from requests import Request
5+
from unittest import TestCase, skipIf
86

97
from azure_functions_worker.testutils_lc import (
108
LinuxConsumptionWebHostController
119
)
1210
from azure_functions_worker.utils.common import is_python_version
11+
from requests import Request
12+
13+
_DEFAULT_HOST_VERSION = "3"
1314

1415

1516
@skipIf(is_python_version('3.10'),
@@ -42,7 +43,8 @@ def test_placeholder_mode_root_returns_ok(self):
4243
"""In any circumstances, a placeholder container should returns 200
4344
even when it is not specialized.
4445
"""
45-
with LinuxConsumptionWebHostController("3", self._py_version) as ctrl:
46+
with LinuxConsumptionWebHostController(_DEFAULT_HOST_VERSION,
47+
self._py_version) as ctrl:
4648
req = Request('GET', ctrl.url)
4749
resp = ctrl.send_request(req)
4850
self.assertTrue(resp.ok)
@@ -51,7 +53,8 @@ def test_http_no_auth(self):
5153
"""An HttpTrigger function app with 'azure-functions' library
5254
should return 200.
5355
"""
54-
with LinuxConsumptionWebHostController("3", self._py_version) as ctrl:
56+
with LinuxConsumptionWebHostController(_DEFAULT_HOST_VERSION,
57+
self._py_version) as ctrl:
5558
ctrl.assign_container(env={
5659
"AzureWebJobsStorage": self._storage,
5760
"SCM_RUN_FROM_PACKAGE": self._get_blob_url("HttpNoAuth")
@@ -60,6 +63,8 @@ def test_http_no_auth(self):
6063
resp = ctrl.send_request(req)
6164
self.assertEqual(resp.status_code, 200)
6265

66+
@skipIf(is_python_version('3.7'),
67+
"Skip the tests for Python 3.7.")
6368
def test_common_libraries(self):
6469
"""A function app with the following requirements.txt:
6570
@@ -73,7 +78,8 @@ def test_common_libraries(self):
7378
7479
should return 200 after importing all libraries.
7580
"""
76-
with LinuxConsumptionWebHostController("3", self._py_version) as ctrl:
81+
with LinuxConsumptionWebHostController(_DEFAULT_HOST_VERSION,
82+
self._py_version) as ctrl:
7783
ctrl.assign_container(env={
7884
"AzureWebJobsStorage": self._storage,
7985
"SCM_RUN_FROM_PACKAGE": self._get_blob_url("CommonLibraries")
@@ -98,7 +104,8 @@ def test_new_protobuf(self):
98104
99105
should return 200 after importing all libraries.
100106
"""
101-
with LinuxConsumptionWebHostController("3", self._py_version) as ctrl:
107+
with LinuxConsumptionWebHostController(_DEFAULT_HOST_VERSION,
108+
self._py_version) as ctrl:
102109
ctrl.assign_container(env={
103110
"AzureWebJobsStorage": self._storage,
104111
"SCM_RUN_FROM_PACKAGE": self._get_blob_url("NewProtobuf")
@@ -123,10 +130,11 @@ def test_old_protobuf(self):
123130
124131
should return 200 after importing all libraries.
125132
"""
126-
with LinuxConsumptionWebHostController("3", self._py_version) as ctrl:
133+
with LinuxConsumptionWebHostController(_DEFAULT_HOST_VERSION,
134+
self._py_version) as ctrl:
127135
ctrl.assign_container(env={
128136
"AzureWebJobsStorage": self._storage,
129-
"SCM_RUN_FROM_PACKAGE": self._get_blob_url("NewProtobuf")
137+
"SCM_RUN_FROM_PACKAGE": self._get_blob_url("OldProtobuf")
130138
})
131139
req = Request('GET', f'{ctrl.url}/api/HttpTrigger')
132140
resp = ctrl.send_request(req)
@@ -144,7 +152,8 @@ def test_debug_logging_disabled(self):
144152
should return 200 and by default customer debug logging should be
145153
disabled.
146154
"""
147-
with LinuxConsumptionWebHostController("3", self._py_version) as ctrl:
155+
with LinuxConsumptionWebHostController(_DEFAULT_HOST_VERSION,
156+
self._py_version) as ctrl:
148157
ctrl.assign_container(env={
149158
"AzureWebJobsStorage": self._storage,
150159
"SCM_RUN_FROM_PACKAGE": self._get_blob_url("EnableDebugLogging")
@@ -170,7 +179,8 @@ def test_debug_logging_enabled(self):
170179
should return 200 and with customer debug logging enabled, debug logs
171180
should be written to container logs.
172181
"""
173-
with LinuxConsumptionWebHostController("3", self._py_version) as ctrl:
182+
with LinuxConsumptionWebHostController(_DEFAULT_HOST_VERSION,
183+
self._py_version) as ctrl:
174184
ctrl.assign_container(env={
175185
"AzureWebJobsStorage": self._storage,
176186
"SCM_RUN_FROM_PACKAGE": self._get_blob_url(

0 commit comments

Comments
 (0)