-
Notifications
You must be signed in to change notification settings - Fork 308
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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="Prometheus 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): | ||||||||||||||
""" | ||||||||||||||
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") | ||||||||||||||
|
||||||||||||||
|
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 @@ | ||
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 | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider validating the
prometheus_port
parameter to ensure it doesn't conflict with the mainport
parameter and is within valid port range (0-65535). A similar issue was also found in flytekit/clis/sdk_in_container/serve.py (line 83).Code suggestion
Code Review Run #9cfb00
Is this a valid issue, or was it incorrectly flagged by the Agent?