From bb097ec327aef8936a34a7b1838672c6b9e0d245 Mon Sep 17 00:00:00 2001 From: Cagri Yonca Date: Mon, 11 Nov 2024 10:22:24 +0100 Subject: [PATCH 1/2] fix: removed protobuf from requirements list Signed-off-by: Cagri Yonca --- pyproject.toml | 1 - tests/apps/grpc_server/README.md | 2 +- tests/requirements.txt | 7 ------- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8572ce31c..1f12cb6e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,6 @@ classifiers = [ dependencies = [ "autowrapt>=1.0", "fysom>=2.1.2", - "protobuf<5.0.0", "requests>=2.6.0", "six>=1.12.0", "urllib3>=1.26.5", diff --git a/tests/apps/grpc_server/README.md b/tests/apps/grpc_server/README.md index a02cdf3fe..b09faf326 100644 --- a/tests/apps/grpc_server/README.md +++ b/tests/apps/grpc_server/README.md @@ -1,7 +1,7 @@ To regenerate from the proto file: ```bash -pip install grpcio grpcio-tools +pip install grpcio grpcio-tools protobuf python -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. ./stan.proto ``` diff --git a/tests/requirements.txt b/tests/requirements.txt index 570be7cd3..236ed5539 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -20,13 +20,6 @@ mysqlclient>=2.0.3 PyMySQL[rsa]>=1.0.2 psycopg2-binary>=2.8.6 pika>=1.2.0 -# protobuf is pulled in and also `basictracer`, a core instana dependency -# and also by google-cloud-storage -# but also directly needed by tests/apps/grpc_server/stan_pb2.py -# On 4.0.0 we currently get: -# AttributeError: module 'google._upb._message' has no attribute 'Message' -# TODO: Remove this when support for 4.0.0 is done -protobuf<4.0.0 pymongo>=3.11.4 pyramid>=2.0.1 pytest>=6.2.4 From 893cf4b15496208315c86d8b1750968809eea3e2 Mon Sep 17 00:00:00 2001 From: Cagri Yonca Date: Mon, 11 Nov 2024 10:22:39 +0100 Subject: [PATCH 2/2] updated stan files to support newer version of protobuf Signed-off-by: Cagri Yonca --- tests/apps/grpc_server/stan_pb2.py | 195 +++---------------- tests/apps/grpc_server/stan_pb2_grpc.py | 248 +++++++++++++----------- 2 files changed, 159 insertions(+), 284 deletions(-) diff --git a/tests/apps/grpc_server/stan_pb2.py b/tests/apps/grpc_server/stan_pb2.py index cd2e63f91..564bdfee7 100644 --- a/tests/apps/grpc_server/stan_pb2.py +++ b/tests/apps/grpc_server/stan_pb2.py @@ -1,187 +1,40 @@ # (c) Copyright IBM Corp. 2021 # (c) Copyright Instana Inc. 2019 +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE # source: stan.proto +# Protobuf Python Version: 5.27.2 +"""Generated protocol buffer code.""" -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version from google.protobuf import symbol_database as _symbol_database -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - +from google.protobuf.internal import builder as _builder - -DESCRIPTOR = _descriptor.FileDescriptor( - name='stan.proto', - package='stan', - syntax='proto3', - serialized_options=None, - serialized_pb=_b('\n\nstan.proto\x12\x04stan\"#\n\x0fQuestionRequest\x12\x10\n\x08question\x18\x01 \x01(\t\"8\n\x10QuestionResponse\x12\x0e\n\x06\x61nswer\x18\x01 \x01(\t\x12\x14\n\x0cwas_answered\x18\x02 \x01(\x08\x32\xe3\x03\n\x04Stan\x12I\n\x16OneQuestionOneResponse\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse\"\x00\x12M\n\x18ManyQuestionsOneResponse\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse\"\x00(\x01\x12M\n\x18OneQuestionManyResponses\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse\"\x00\x30\x01\x12P\n\x19ManyQuestionsManyReponses\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse\"\x00(\x01\x30\x01\x12N\n\x1bOneQuestionOneErrorResponse\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse\"\x00\x12P\n\x1dOneErroredQuestionOneResponse\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse\"\x00\x62\x06proto3') +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, 5, 27, 2, "", "stan.proto" ) +# @@protoc_insertion_point(imports) +_sym_db = _symbol_database.Default() - -_QUESTIONREQUEST = _descriptor.Descriptor( - name='QuestionRequest', - full_name='stan.QuestionRequest', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='question', full_name='stan.QuestionRequest.question', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=20, - serialized_end=55, -) - - -_QUESTIONRESPONSE = _descriptor.Descriptor( - name='QuestionResponse', - full_name='stan.QuestionResponse', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='answer', full_name='stan.QuestionResponse.answer', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='was_answered', full_name='stan.QuestionResponse.was_answered', index=1, - number=2, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=57, - serialized_end=113, +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( + b'\n\nstan.proto\x12\x04stan"#\n\x0fQuestionRequest\x12\x10\n\x08question\x18\x01 \x01(\t"8\n\x10QuestionResponse\x12\x0e\n\x06\x61nswer\x18\x01 \x01(\t\x12\x14\n\x0cwas_answered\x18\x02 \x01(\x08\x32\xe3\x03\n\x04Stan\x12I\n\x16OneQuestionOneResponse\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse"\x00\x12M\n\x18ManyQuestionsOneResponse\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse"\x00(\x01\x12M\n\x18OneQuestionManyResponses\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse"\x00\x30\x01\x12P\n\x19ManyQuestionsManyReponses\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse"\x00(\x01\x30\x01\x12N\n\x1bOneQuestionOneErrorResponse\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse"\x00\x12P\n\x1dOneErroredQuestionOneResponse\x12\x15.stan.QuestionRequest\x1a\x16.stan.QuestionResponse"\x00\x62\x06proto3' ) -DESCRIPTOR.message_types_by_name['QuestionRequest'] = _QUESTIONREQUEST -DESCRIPTOR.message_types_by_name['QuestionResponse'] = _QUESTIONRESPONSE -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -QuestionRequest = _reflection.GeneratedProtocolMessageType('QuestionRequest', (_message.Message,), dict( - DESCRIPTOR = _QUESTIONREQUEST, - __module__ = 'stan_pb2' - # @@protoc_insertion_point(class_scope:stan.QuestionRequest) - )) -_sym_db.RegisterMessage(QuestionRequest) - -QuestionResponse = _reflection.GeneratedProtocolMessageType('QuestionResponse', (_message.Message,), dict( - DESCRIPTOR = _QUESTIONRESPONSE, - __module__ = 'stan_pb2' - # @@protoc_insertion_point(class_scope:stan.QuestionResponse) - )) -_sym_db.RegisterMessage(QuestionResponse) - - - -_STAN = _descriptor.ServiceDescriptor( - name='Stan', - full_name='stan.Stan', - file=DESCRIPTOR, - index=0, - serialized_options=None, - serialized_start=116, - serialized_end=599, - methods=[ - _descriptor.MethodDescriptor( - name='OneQuestionOneResponse', - full_name='stan.Stan.OneQuestionOneResponse', - index=0, - containing_service=None, - input_type=_QUESTIONREQUEST, - output_type=_QUESTIONRESPONSE, - serialized_options=None, - ), - _descriptor.MethodDescriptor( - name='ManyQuestionsOneResponse', - full_name='stan.Stan.ManyQuestionsOneResponse', - index=1, - containing_service=None, - input_type=_QUESTIONREQUEST, - output_type=_QUESTIONRESPONSE, - serialized_options=None, - ), - _descriptor.MethodDescriptor( - name='OneQuestionManyResponses', - full_name='stan.Stan.OneQuestionManyResponses', - index=2, - containing_service=None, - input_type=_QUESTIONREQUEST, - output_type=_QUESTIONRESPONSE, - serialized_options=None, - ), - _descriptor.MethodDescriptor( - name='ManyQuestionsManyReponses', - full_name='stan.Stan.ManyQuestionsManyReponses', - index=3, - containing_service=None, - input_type=_QUESTIONREQUEST, - output_type=_QUESTIONRESPONSE, - serialized_options=None, - ), - _descriptor.MethodDescriptor( - name='OneQuestionOneErrorResponse', - full_name='stan.Stan.OneQuestionOneErrorResponse', - index=4, - containing_service=None, - input_type=_QUESTIONREQUEST, - output_type=_QUESTIONRESPONSE, - serialized_options=None, - ), - _descriptor.MethodDescriptor( - name='OneErroredQuestionOneResponse', - full_name='stan.Stan.OneErroredQuestionOneResponse', - index=5, - containing_service=None, - input_type=_QUESTIONREQUEST, - output_type=_QUESTIONRESPONSE, - serialized_options=None, - ), -]) -_sym_db.RegisterServiceDescriptor(_STAN) - -DESCRIPTOR.services_by_name['Stan'] = _STAN - +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "stan_pb2", _globals) +if not _descriptor._USE_C_DESCRIPTORS: + DESCRIPTOR._loaded_options = None + _globals["_QUESTIONREQUEST"]._serialized_start = 20 + _globals["_QUESTIONREQUEST"]._serialized_end = 55 + _globals["_QUESTIONRESPONSE"]._serialized_start = 57 + _globals["_QUESTIONRESPONSE"]._serialized_end = 113 + _globals["_STAN"]._serialized_start = 116 + _globals["_STAN"]._serialized_end = 599 # @@protoc_insertion_point(module_scope) diff --git a/tests/apps/grpc_server/stan_pb2_grpc.py b/tests/apps/grpc_server/stan_pb2_grpc.py index 5d0b49a58..b2a8c66a0 100644 --- a/tests/apps/grpc_server/stan_pb2_grpc.py +++ b/tests/apps/grpc_server/stan_pb2_grpc.py @@ -1,134 +1,156 @@ # (c) Copyright IBM Corp. 2021 # (c) Copyright Instana Inc. 2019 - # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" + import grpc import tests.apps.grpc_server.stan_pb2 as stan__pb2 +GRPC_GENERATED_VERSION = "1.67.1" +GRPC_VERSION = grpc.__version__ +_version_not_supported = False + +try: + from grpc._utilities import first_version_is_lower + + _version_not_supported = first_version_is_lower( + GRPC_VERSION, GRPC_GENERATED_VERSION + ) +except ImportError: + _version_not_supported = True + +if _version_not_supported: + raise RuntimeError( + f"The grpc package installed is at version {GRPC_VERSION}," + + " but the generated code in stan_pb2_grpc.py depends on" + + f" grpcio>={GRPC_GENERATED_VERSION}." + + f" Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}" + + f" or downgrade your generated code using grpcio-tools<={GRPC_VERSION}." + ) + class StanStub(object): - # missing associated documentation comment in .proto file - pass - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.OneQuestionOneResponse = channel.unary_unary( - '/stan.Stan/OneQuestionOneResponse', - request_serializer=stan__pb2.QuestionRequest.SerializeToString, - response_deserializer=stan__pb2.QuestionResponse.FromString, + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.OneQuestionOneResponse = channel.unary_unary( + "/stan.Stan/OneQuestionOneResponse", + request_serializer=stan__pb2.QuestionRequest.SerializeToString, + response_deserializer=stan__pb2.QuestionResponse.FromString, + _registered_method=True, ) - self.ManyQuestionsOneResponse = channel.stream_unary( - '/stan.Stan/ManyQuestionsOneResponse', - request_serializer=stan__pb2.QuestionRequest.SerializeToString, - response_deserializer=stan__pb2.QuestionResponse.FromString, + self.ManyQuestionsOneResponse = channel.stream_unary( + "/stan.Stan/ManyQuestionsOneResponse", + request_serializer=stan__pb2.QuestionRequest.SerializeToString, + response_deserializer=stan__pb2.QuestionResponse.FromString, + _registered_method=True, ) - self.OneQuestionManyResponses = channel.unary_stream( - '/stan.Stan/OneQuestionManyResponses', - request_serializer=stan__pb2.QuestionRequest.SerializeToString, - response_deserializer=stan__pb2.QuestionResponse.FromString, + self.OneQuestionManyResponses = channel.unary_stream( + "/stan.Stan/OneQuestionManyResponses", + request_serializer=stan__pb2.QuestionRequest.SerializeToString, + response_deserializer=stan__pb2.QuestionResponse.FromString, + _registered_method=True, ) - self.ManyQuestionsManyReponses = channel.stream_stream( - '/stan.Stan/ManyQuestionsManyReponses', - request_serializer=stan__pb2.QuestionRequest.SerializeToString, - response_deserializer=stan__pb2.QuestionResponse.FromString, + self.ManyQuestionsManyReponses = channel.stream_stream( + "/stan.Stan/ManyQuestionsManyReponses", + request_serializer=stan__pb2.QuestionRequest.SerializeToString, + response_deserializer=stan__pb2.QuestionResponse.FromString, + _registered_method=True, ) - self.OneQuestionOneErrorResponse = channel.unary_unary( - '/stan.Stan/OneQuestionOneErrorResponse', - request_serializer=stan__pb2.QuestionRequest.SerializeToString, - response_deserializer=stan__pb2.QuestionResponse.FromString, + self.OneQuestionOneErrorResponse = channel.unary_unary( + "/stan.Stan/OneQuestionOneErrorResponse", + request_serializer=stan__pb2.QuestionRequest.SerializeToString, + response_deserializer=stan__pb2.QuestionResponse.FromString, + _registered_method=True, ) - self.OneErroredQuestionOneResponse = channel.unary_unary( - '/stan.Stan/OneErroredQuestionOneResponse', - request_serializer=stan__pb2.QuestionRequest.SerializeToString, - response_deserializer=stan__pb2.QuestionResponse.FromString, + self.OneErroredQuestionOneResponse = channel.unary_unary( + "/stan.Stan/OneErroredQuestionOneResponse", + request_serializer=stan__pb2.QuestionRequest.SerializeToString, + response_deserializer=stan__pb2.QuestionResponse.FromString, + _registered_method=True, ) class StanServicer(object): - # missing associated documentation comment in .proto file - pass - - def OneQuestionOneResponse(self, request, context): - """Unary - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def ManyQuestionsOneResponse(self, request_iterator, context): - """Streaming - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def OneQuestionManyResponses(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 ManyQuestionsManyReponses(self, request_iterator, 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 OneQuestionOneErrorResponse(self, request, context): - """Error Testing - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def OneErroredQuestionOneResponse(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!') + """Missing associated documentation comment in .proto file.""" + + def OneQuestionOneResponse(self, request, context): + """Unary""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + def ManyQuestionsOneResponse(self, request_iterator, context): + """Streaming""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + def OneQuestionManyResponses(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + def ManyQuestionsManyReponses(self, request_iterator, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + def OneQuestionOneErrorResponse(self, request, context): + """Error Testing""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + def OneErroredQuestionOneResponse(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") def add_StanServicer_to_server(servicer, server): - rpc_method_handlers = { - 'OneQuestionOneResponse': grpc.unary_unary_rpc_method_handler( - servicer.OneQuestionOneResponse, - request_deserializer=stan__pb2.QuestionRequest.FromString, - response_serializer=stan__pb2.QuestionResponse.SerializeToString, - ), - 'ManyQuestionsOneResponse': grpc.stream_unary_rpc_method_handler( - servicer.ManyQuestionsOneResponse, - request_deserializer=stan__pb2.QuestionRequest.FromString, - response_serializer=stan__pb2.QuestionResponse.SerializeToString, - ), - 'OneQuestionManyResponses': grpc.unary_stream_rpc_method_handler( - servicer.OneQuestionManyResponses, - request_deserializer=stan__pb2.QuestionRequest.FromString, - response_serializer=stan__pb2.QuestionResponse.SerializeToString, - ), - 'ManyQuestionsManyReponses': grpc.stream_stream_rpc_method_handler( - servicer.ManyQuestionsManyReponses, - request_deserializer=stan__pb2.QuestionRequest.FromString, - response_serializer=stan__pb2.QuestionResponse.SerializeToString, - ), - 'OneQuestionOneErrorResponse': grpc.unary_unary_rpc_method_handler( - servicer.OneQuestionOneErrorResponse, - request_deserializer=stan__pb2.QuestionRequest.FromString, - response_serializer=stan__pb2.QuestionResponse.SerializeToString, - ), - 'OneErroredQuestionOneResponse': grpc.unary_unary_rpc_method_handler( - servicer.OneErroredQuestionOneResponse, - request_deserializer=stan__pb2.QuestionRequest.FromString, - response_serializer=stan__pb2.QuestionResponse.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'stan.Stan', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) + rpc_method_handlers = { + "OneQuestionOneResponse": grpc.unary_unary_rpc_method_handler( + servicer.OneQuestionOneResponse, + request_deserializer=stan__pb2.QuestionRequest.FromString, + response_serializer=stan__pb2.QuestionResponse.SerializeToString, + ), + "ManyQuestionsOneResponse": grpc.stream_unary_rpc_method_handler( + servicer.ManyQuestionsOneResponse, + request_deserializer=stan__pb2.QuestionRequest.FromString, + response_serializer=stan__pb2.QuestionResponse.SerializeToString, + ), + "OneQuestionManyResponses": grpc.unary_stream_rpc_method_handler( + servicer.OneQuestionManyResponses, + request_deserializer=stan__pb2.QuestionRequest.FromString, + response_serializer=stan__pb2.QuestionResponse.SerializeToString, + ), + "ManyQuestionsManyReponses": grpc.stream_stream_rpc_method_handler( + servicer.ManyQuestionsManyReponses, + request_deserializer=stan__pb2.QuestionRequest.FromString, + response_serializer=stan__pb2.QuestionResponse.SerializeToString, + ), + "OneQuestionOneErrorResponse": grpc.unary_unary_rpc_method_handler( + servicer.OneQuestionOneErrorResponse, + request_deserializer=stan__pb2.QuestionRequest.FromString, + response_serializer=stan__pb2.QuestionResponse.SerializeToString, + ), + "OneErroredQuestionOneResponse": grpc.unary_unary_rpc_method_handler( + servicer.OneErroredQuestionOneResponse, + request_deserializer=stan__pb2.QuestionRequest.FromString, + response_serializer=stan__pb2.QuestionResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + "stan.Stan", rpc_method_handlers + ) + server.add_generic_rpc_handlers((generic_handler,))