Skip to content

Commit

Permalink
add config parameter grpc.port to make the gRPC server port configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto-bortolan committed Nov 24, 2024
1 parent 1394391 commit 988b0e5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ backup_grace_period_in_days = 10
; Set to true when running in grpc server mode.
; Allows to propagate the exceptions instead of exiting the program.
;enabled = False
;port = <grpc port the server listens to. Defaults to port 50051.>
[kubernetes]
; The following settings are only intended to be configured if Medusa is running in containers, preferably in Kubernetes.
Expand Down
4 changes: 3 additions & 1 deletion medusa/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

GrpcConfig = collections.namedtuple(
'GrpcConfig',
['enabled', 'max_send_message_length', 'max_receive_message_length']
['enabled', 'max_send_message_length', 'max_receive_message_length', 'port']
)

KubernetesConfig = collections.namedtuple(
Expand All @@ -93,6 +93,7 @@
}

DEFAULT_CONFIGURATION_PATH = pathlib.Path('/etc/medusa/medusa.ini')
DEFAULT_GRPC_PORT = 50051


def _build_default_config():
Expand Down Expand Up @@ -167,6 +168,7 @@ def _build_default_config():
'enabled': 'False',
'max_send_message_length': '536870912',
'max_receive_message_length': '134217728',
'port': f'{DEFAULT_GRPC_PORT}'
}

config['kubernetes'] = {
Expand Down
5 changes: 3 additions & 2 deletions medusa/service/grpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ async def serve(self):
medusa_pb2_grpc.add_MedusaServicer_to_server(MedusaService(config), self.grpc_server)
health_pb2_grpc.add_HealthServicer_to_server(grpc_health.v1.health.HealthServicer(), self.grpc_server)

logging.info('Starting server. Listening on port 50051.')
self.grpc_server.add_insecure_port('[::]:50051')
grpc_port = int(self.medusa_config.grpc.port)
logging.info(f"Starting server. Listening on port {grpc_port}.")
self.grpc_server.add_insecure_port(f"[::]:{grpc_port}")
await self.grpc_server.start()

if not self.testing:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/features/steps/integration_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def i_am_using_storage_provider_with_grpc_server(context, storage_provider, clie
context.client_encryption = client_encryption
context.grpc_server = GRPCServer(config)
context.grpc_client = medusa.service.grpc.client.Client(
"127.0.0.1:50051",
f"127.0.0.1:{config['grpc']['port']}",
channel_options=[('grpc.enable_retries', 0)]
)

Expand Down Expand Up @@ -496,7 +496,7 @@ def i_am_using_storage_provider_with_grpc_server_and_mgmt_api(context, storage_p
context.client_encryption = client_encryption
context.grpc_server = GRPCServer(config)
context.grpc_client = medusa.service.grpc.client.Client(
"127.0.0.1:50051",
f"127.0.0.1:{config['grpc']['port']}",
channel_options=[('grpc.enable_retries', 0)]
)

Expand Down

0 comments on commit 988b0e5

Please sign in to comment.