-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flyteagent][CLI] Make agent prometheus port configurable #3064
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,6 +29,13 @@ def serve(ctx: click.Context): | |||||||||||||
type=int, | ||||||||||||||
help="Grpc port for the agent service", | ||||||||||||||
) | ||||||||||||||
@click.option( | ||||||||||||||
"--prometheus_port", | ||||||||||||||
default="9090", | ||||||||||||||
is_flag=False, | ||||||||||||||
type=int, | ||||||||||||||
help="Grpc port for the agent service", | ||||||||||||||
) | ||||||||||||||
@click.option( | ||||||||||||||
"--worker", | ||||||||||||||
default="10", | ||||||||||||||
|
@@ -45,20 +52,20 @@ def serve(ctx: click.Context): | |||||||||||||
"for testing.", | ||||||||||||||
) | ||||||||||||||
@click.pass_context | ||||||||||||||
def agent(_: click.Context, port, worker, timeout): | ||||||||||||||
def agent(_: click.Context, port, prometheus_port, worker, timeout): | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding port validation checks
Consider validating the Code suggestionCheck the AI-generated fix before applying
Code Review Run #9cfb00 Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||||||||||||||
""" | ||||||||||||||
Start a grpc server for the agent service. | ||||||||||||||
""" | ||||||||||||||
import asyncio | ||||||||||||||
|
||||||||||||||
asyncio.run(_start_grpc_server(port, worker, timeout)) | ||||||||||||||
asyncio.run(_start_grpc_server(port, prometheus_port, worker, timeout)) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
async def _start_grpc_server(port: int, worker: int, timeout: int): | ||||||||||||||
async def _start_grpc_server(port: int, prometheus_port: int, worker: int, timeout: int): | ||||||||||||||
from flytekit.extend.backend.agent_service import AgentMetadataService, AsyncAgentService, SyncAgentService | ||||||||||||||
|
||||||||||||||
click.secho("🚀 Starting the agent service...") | ||||||||||||||
_start_http_server() | ||||||||||||||
_start_http_server(prometheus_port) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling for port
Consider adding error handling around Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #9cfb00 Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||||||||||||||
print_agents_metadata() | ||||||||||||||
|
||||||||||||||
server = grpc.aio.server(futures.ThreadPoolExecutor(max_workers=worker)) | ||||||||||||||
|
@@ -73,12 +80,12 @@ async def _start_grpc_server(port: int, worker: int, timeout: int): | |||||||||||||
await server.wait_for_termination(timeout) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def _start_http_server(): | ||||||||||||||
def _start_http_server(prometheus_port: int): | ||||||||||||||
try: | ||||||||||||||
from prometheus_client import start_http_server | ||||||||||||||
|
||||||||||||||
click.secho("Starting up the server to expose the prometheus metrics...") | ||||||||||||||
start_http_server(9090) | ||||||||||||||
start_http_server(prometheus_port) | ||||||||||||||
except ImportError as e: | ||||||||||||||
click.secho(f"Failed to start the prometheus server with error {e}", fg="red") | ||||||||||||||
|
||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
from click.testing import CliRunner | ||
from unittest.mock import patch | ||
|
||
from flytekit.clis.sdk_in_container.serve import serve | ||
|
||
def test_agent_prometheus_port(): | ||
runner = CliRunner() | ||
test_port = 9100 | ||
test_prometheus_port = 9200 | ||
test_worker = 5 | ||
test_timeout = 30 | ||
|
||
with patch('flytekit.clis.sdk_in_container.serve._start_grpc_server') as mock_start_grpc: | ||
result = runner.invoke( | ||
serve, | ||
[ | ||
'agent', | ||
'--port', str(test_port), | ||
'--prometheus_port', str(test_prometheus_port), | ||
'--worker', str(test_worker), | ||
'--timeout', str(test_timeout) | ||
] | ||
) | ||
|
||
assert result.exit_code == 0, f"Command failed with output: {result.output}" | ||
mock_start_grpc.assert_called_once_with( | ||
test_port, | ||
test_prometheus_port, | ||
test_worker, | ||
test_timeout | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!!