Skip to content

Commit e35d9e2

Browse files
committed
Update proto and add custom build steps
1 parent a164a09 commit e35d9e2

File tree

4 files changed

+85
-39
lines changed

4 files changed

+85
-39
lines changed

azure_functions_worker/protos/_src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Azure Functions Languge Worker Protobuf
22

3-
This repository contains the protobuf definition file which defines the gRPC service which is used between the Azure WebJobs Script host and the Azure Functions language workers. This repo is shared across many repos in many languages (for each worker) by using git commands.
3+
This repository contains the protobuf definition file which defines the gRPC service which is used between the [Azure Functions Host](https://github.com/Azure/azure-functions-host) and the Azure Functions language workers. This repo is shared across many repos in many languages (for each worker) by using git commands.
44

55
To use this repo in Azure Functions language workers, follow steps below to add this repo as a subtree (*Adding This Repo*). If this repo is already embedded in a language worker repo, follow the steps to update the consumed file (*Pulling Updates*).
66

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ option go_package ="github.com/Azure/azure-functions-go-worker/internal/rpc";
1010
package AzureFunctionsRpcMessages;
1111

1212
import "google/protobuf/duration.proto";
13-
import "azure_functions_worker/protos/ClaimsIdentityRpc.proto";
14-
import "azure_functions_worker/protos/NullableTypes.proto";
13+
import "identity/ClaimsIdentityRpc.proto";
14+
import "shared/NullableTypes.proto";
1515

1616
// Interface exported by the server.
1717
service FunctionRpc {
@@ -189,6 +189,8 @@ message WorkerStatusResponse {
189189
message FunctionEnvironmentReloadRequest {
190190
// Environment variables from the current process
191191
map<string, string> environment_variables = 1;
192+
// Current directory of function app
193+
string function_app_directory = 2;
192194
}
193195

194196
message FunctionEnvironmentReloadResponse {
@@ -255,6 +257,21 @@ message InvocationRequest {
255257

256258
// binding metadata from trigger
257259
map<string, TypedData> trigger_metadata = 4;
260+
261+
// Populates activityId, tracestate and tags from host
262+
RpcTraceContext trace_context = 5;
263+
}
264+
265+
// Host sends ActivityId, traceStateString and Tags from host
266+
message RpcTraceContext {
267+
// This corresponds to Activity.Current?.Id
268+
string trace_parent = 1;
269+
270+
// This corresponds to Activity.Current?.TraceStateString
271+
string trace_state = 2;
272+
273+
// This corresponds to Activity.Current?.Tags
274+
map<string, string> attributes = 3;
258275
}
259276

260277
// Host requests worker to cancel invocation
@@ -368,6 +385,12 @@ message RpcLog {
368385
None = 6;
369386
}
370387

388+
// Category of the log. Defaults to User if not specified.
389+
enum RpcLogCategory {
390+
User = 0;
391+
System = 1;
392+
}
393+
371394
// Unique id for invocation (if exists)
372395
string invocation_id = 1;
373396

@@ -389,6 +412,9 @@ message RpcLog {
389412

390413
// json serialized property bag, or could use a type scheme like map<string, TypedData>
391414
string properties = 7;
415+
416+
// Category of the log. Either user(default) or system.
417+
RpcLogCategory log_category = 8;
392418
}
393419

394420
// Encapsulates an Exception
@@ -399,7 +425,7 @@ message RpcException {
399425
// Stack trace for the exception
400426
string stack_trace = 1;
401427

402-
// Textual message describing hte exception
428+
// Textual message describing the exception
403429
string message = 2;
404430
}
405431

azure_functions_worker/protos/_src/src/proto/identity/ClaimsIdentityRpc.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ syntax = "proto3";
33

44
option java_package = "com.microsoft.azure.functions.rpc.messages";
55

6-
import "azure_functions_worker/protos/NullableTypes.proto";
6+
import "shared/NullableTypes.proto";
77

88
// Light-weight representation of a .NET System.Security.Claims.ClaimsIdentity object.
99
// This is the same serialization as found in EasyAuth, and needs to be kept in sync with

setup.py

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import tempfile
99
import urllib.request
1010
import zipfile
11+
import re
12+
from distutils import dir_util
1113
from distutils.command import build
1214

1315
from setuptools import setup
@@ -73,56 +75,74 @@ def _gen_grpc(self):
7375

7476
proto_root_dir = root / 'azure_functions_worker' / 'protos'
7577
proto_src_dir = proto_root_dir / '_src' / 'src' / 'proto'
76-
staging_root_dir = root / 'build' / 'protos'
78+
build_dir = root / 'build'
79+
staging_root_dir = build_dir / 'protos'
7780
staging_dir = (staging_root_dir
7881
/ 'azure_functions_worker' / 'protos')
79-
build_dir = staging_dir / 'azure_functions_worker' / 'protos'
80-
built_protos_dir = root / 'build' / 'built_protos'
81-
built_proto_files_dir = (built_protos_dir
82-
/ 'azure_functions_worker' / 'protos')
82+
built_protos_dir = build_dir / 'built_protos'
8383

84-
if os.path.exists(build_dir):
84+
if os.path.exists(staging_root_dir):
8585
shutil.rmtree(build_dir)
8686

8787
if os.path.exists(built_protos_dir):
8888
shutil.rmtree(built_protos_dir)
8989

90-
proto_files = glob.glob(str(proto_src_dir / '**' / '*.proto'),
91-
recursive=True)
90+
shutil.copytree(proto_src_dir, staging_dir)
9291

93-
os.makedirs(build_dir)
94-
for proto_file in proto_files:
95-
shutil.copy(proto_file, build_dir)
92+
os.makedirs(built_protos_dir)
9693

97-
protos = [os.path.basename(proto_file) for proto_file in proto_files]
94+
protos = [
95+
os.sep.join(('shared', 'NullableTypes.proto')),
96+
os.sep.join(('identity', 'ClaimsIdentityRpc.proto')),
97+
'FunctionRpc.proto'
98+
]
9899

99-
full_protos = []
100100
for proto in protos:
101-
full_proto = os.sep.join(
102-
('azure_functions_worker', 'protos',
103-
'azure_functions_worker', 'protos', proto)
104-
)
105-
full_protos.append(full_proto)
106-
107-
os.makedirs(built_protos_dir)
108-
subprocess.run([
109-
sys.executable, '-m', 'grpc_tools.protoc',
110-
'-I', os.sep.join(('azure_functions_worker', 'protos')),
111-
'--python_out', str(built_protos_dir),
112-
'--grpc_python_out', str(built_protos_dir),
113-
*full_protos
114-
], check=True, stdout=sys.stdout, stderr=sys.stderr,
115-
cwd=staging_root_dir)
116-
117-
compiled = glob.glob(str(built_proto_files_dir / '*.py'))
118-
119-
if not compiled:
101+
subprocess.run([
102+
sys.executable, '-m', 'grpc_tools.protoc',
103+
'-I', os.sep.join(('azure_functions_worker', 'protos')),
104+
'--python_out', str(built_protos_dir),
105+
'--grpc_python_out', str(built_protos_dir),
106+
os.sep.join(('azure_functions_worker', 'protos', proto)),
107+
], check=True, stdout=sys.stdout, stderr=sys.stderr,
108+
cwd=staging_root_dir)
109+
110+
compiled_files = glob.glob(
111+
str(built_protos_dir / '**' / '*.py'),
112+
recursive=True)
113+
114+
if not compiled_files:
120115
print('grpc_tools.protoc produced no Python files',
121116
file=sys.stderr)
122117
sys.exit(1)
123118

124-
for f in compiled:
125-
shutil.copy(f, proto_root_dir)
119+
# Needed to support absolute imports in files. See
120+
# https://github.com/protocolbuffers/protobuf/issues/1491
121+
self.make_absolute_imports(compiled_files)
122+
123+
dir_util.copy_tree(built_protos_dir, str(proto_root_dir))
124+
125+
def make_absolute_imports(self, compiled_files):
126+
for compiled in compiled_files:
127+
with open(compiled, 'r+') as f:
128+
content = f.read()
129+
f.seek(0)
130+
# Convert lines of the form:
131+
# import xxx_pb2 as xxx__pb2 to
132+
# from azure_functions_worker.protos import xxx_pb2 as..
133+
p1 = re.sub(
134+
r'\nimport (.*?_pb2)',
135+
r'\nfrom azure_functions_worker.protos import \g<1>',
136+
content)
137+
# Convert lines of the form:
138+
# from identity import xxx_pb2 as.. to
139+
# from azure_functions_worker.protos.identity import xxx_pb2..
140+
p2 = re.sub(
141+
r'from ([a-z]*) (import.*_pb2)',
142+
r'from azure_functions_worker.protos.\g<1> \g<2>',
143+
p1)
144+
f.write(p2)
145+
f.truncate()
126146

127147

128148
class build(build.build, BuildGRPC):

0 commit comments

Comments
 (0)