-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for grpc propagation (#67)
* Fix path to flask app * Add support for gRPC propagation * Add test for gRPC propagation
- Loading branch information
1 parent
5ab766b
commit ea9994d
Showing
17 changed files
with
302 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM grpc/python:1.13-onbuild | ||
ENTRYPOINT ["python", "-u"] | ||
CMD ["app.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// install grpcio-tools | ||
// | ||
// python3 -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. app.proto | ||
|
||
syntax = "proto3"; | ||
|
||
service App { | ||
rpc CheckTraceHeader(Empty) returns (Empty); | ||
} | ||
|
||
message Empty { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from concurrent import futures | ||
import sys | ||
import signal | ||
import time | ||
import grpc | ||
import app_pb2 as app_messages | ||
import app_pb2_grpc as app_service | ||
|
||
_ONE_DAY_IN_SECONDS = 60 * 60 * 24 | ||
|
||
class AppService(app_service.AppServicer): | ||
def CheckTraceHeader(self, request, context): | ||
metadata = dict(context.invocation_metadata()) | ||
if 'x-ot-span-context' not in metadata: | ||
context.set_code(grpc.StatusCode.INTERNAL) | ||
context.set_details("Metadatum x-ot-span-context not found") | ||
return app_messages.Empty() | ||
|
||
def serve(): | ||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) | ||
app_service.add_AppServicer_to_server(AppService(), server) | ||
server.add_insecure_port('0.0.0.0:50051') | ||
server.start() | ||
signal.signal(signal.SIGTERM, signal.getsignal(signal.SIGINT)) | ||
try: | ||
while True: | ||
time.sleep(_ONE_DAY_IN_SECONDS) | ||
except KeyboardInterrupt: | ||
server.stop(0) | ||
|
||
if __name__ == '__main__': | ||
serve() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! | ||
import grpc | ||
|
||
import app_pb2 as app__pb2 | ||
|
||
|
||
class AppStub(object): | ||
# missing associated documentation comment in .proto file | ||
pass | ||
|
||
def __init__(self, channel): | ||
"""Constructor. | ||
Args: | ||
channel: A grpc.Channel. | ||
""" | ||
self.CheckTraceHeader = channel.unary_unary( | ||
'/App/CheckTraceHeader', | ||
request_serializer=app__pb2.Empty.SerializeToString, | ||
response_deserializer=app__pb2.Empty.FromString, | ||
) | ||
|
||
|
||
class AppServicer(object): | ||
# missing associated documentation comment in .proto file | ||
pass | ||
|
||
def CheckTraceHeader(self, request, context): | ||
# missing associated documentation comment in .proto file | ||
pass | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) | ||
context.set_details('Method not implemented!') | ||
raise NotImplementedError('Method not implemented!') | ||
|
||
|
||
def add_AppServicer_to_server(servicer, server): | ||
rpc_method_handlers = { | ||
'CheckTraceHeader': grpc.unary_unary_rpc_method_handler( | ||
servicer.CheckTraceHeader, | ||
request_deserializer=app__pb2.Empty.FromString, | ||
response_serializer=app__pb2.Empty.SerializeToString, | ||
), | ||
} | ||
generic_handler = grpc.method_handlers_generic_handler( | ||
'App', rpc_method_handlers) | ||
server.add_generic_rpc_handlers((generic_handler,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#grpcio-tools |
Oops, something went wrong.