Skip to content

Commit 0b68e47

Browse files
authored
Update proto and add custom build steps (#601)
1 parent a164a09 commit 0b68e47

File tree

4 files changed

+84
-41
lines changed

4 files changed

+84
-41
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: 53 additions & 36 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,71 @@ 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

8484
if os.path.exists(build_dir):
8585
shutil.rmtree(build_dir)
8686

87-
if os.path.exists(built_protos_dir):
88-
shutil.rmtree(built_protos_dir)
87+
shutil.copytree(proto_src_dir, staging_dir)
8988

90-
proto_files = glob.glob(str(proto_src_dir / '**' / '*.proto'),
91-
recursive=True)
92-
93-
os.makedirs(build_dir)
94-
for proto_file in proto_files:
95-
shutil.copy(proto_file, build_dir)
89+
os.makedirs(built_protos_dir)
9690

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

99-
full_protos = []
10097
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:
98+
subprocess.run([
99+
sys.executable, '-m', 'grpc_tools.protoc',
100+
'-I', os.sep.join(('azure_functions_worker', 'protos')),
101+
'--python_out', str(built_protos_dir),
102+
'--grpc_python_out', str(built_protos_dir),
103+
os.sep.join(('azure_functions_worker', 'protos', proto)),
104+
], check=True, stdout=sys.stdout, stderr=sys.stderr,
105+
cwd=staging_root_dir)
106+
107+
compiled_files = glob.glob(
108+
str(built_protos_dir / '**' / '*.py'),
109+
recursive=True)
110+
111+
if not compiled_files:
120112
print('grpc_tools.protoc produced no Python files',
121113
file=sys.stderr)
122114
sys.exit(1)
123115

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

127144

128145
class build(build.build, BuildGRPC):

0 commit comments

Comments
 (0)