Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Future-Outlier
Copy link
Member

@Future-Outlier Future-Outlier commented Jan 16, 2025

Tracking issue

flyteorg/flyte#3936

Why are the changes needed?

we want to make Prometheus port configurable so that we can have more flexibility.

What changes were proposed in this pull request?

add a

How was this patch tested?

  • Added a --prometheus_port option to the serve agent command, enabling users to define a custom port for the Prometheus metrics server.
  • Updated the _start_grpc_server function to utilize the configurable Prometheus port instead of the default value.

Setup process

 pyflyte serve agent  --prometheus_port 9100

Screenshots

image

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Summary by Bito

This PR implements configurable Prometheus metrics port functionality in the Flyte agent service, introducing a '--prometheus_port' CLI option (default: 9090) with validation checks. The changes include updated CLI help text to clearly distinguish between Prometheus metrics and GRPC ports, improving service configurability and user experience.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 1

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 16, 2025

Code Review Agent Run #9cfb00

Actionable Suggestions - 2
  • flytekit/clis/sdk_in_container/serve.py - 2
    • Consider adding port validation checks · Line 55-55
    • Consider adding error handling for port · Line 68-68
Review Details
  • Files reviewed - 2 · Commit Range: 264f40d..264f40d
    • flytekit/clis/sdk_in_container/serve.py
    • tests/flytekit/clis/sdk_in_container/test_serve.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

Signed-off-by: Future-Outlier <[email protected]>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 16, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Configurable Prometheus Port for Flyte Agent

serve.py - Added prometheus_port configuration option and updated server initialization

test_serve.py - Added test cases for prometheus port configuration

@@ -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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding port validation checks

Consider validating the prometheus_port parameter to ensure it doesn't conflict with the main port 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
Check the AI-generated fix before applying
 @@ -55,2 +55,6 @@
  def agent(_: click.Context, port, prometheus_port, worker, timeout):
 +    if not 0 <= prometheus_port <= 65535:
 +        raise ValueError(f'prometheus_port {prometheus_port} is not in valid range (0-65535)')
 +    if prometheus_port == port:
 +        raise ValueError(f'prometheus_port {prometheus_port} conflicts with main service port {port}')
      """

Code Review Run #9cfb00


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

from flytekit.extend.backend.agent_service import AgentMetadataService, AsyncAgentService, SyncAgentService

click.secho("🚀 Starting the agent service...")
_start_http_server()
_start_http_server(prometheus_port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling for port

Consider adding error handling around _start_http_server(prometheus_port) call to gracefully handle port binding failures.

Code suggestion
Check the AI-generated fix before applying
Suggested change
_start_http_server(prometheus_port)
try:
_start_http_server(prometheus_port)
except OSError as e:
click.secho(f"Failed to start prometheus server on port {prometheus_port}: {e}", fg="red")
raise

Code Review Run #9cfb00


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Copy link

codecov bot commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.79%. Comparing base (e20b541) to head (d0e6b56).
Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #3064       +/-   ##
===========================================
+ Coverage   51.36%   82.79%   +31.43%     
===========================================
  Files         202        3      -199     
  Lines       21367      186    -21181     
  Branches     2746        0     -2746     
===========================================
- Hits        10975      154    -10821     
+ Misses       9792       32     -9760     
+ Partials      600        0      -600     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 16, 2025

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - We encountered technical difficulties while attempting to generate code feedback. Please try again or contact [email protected].

default="9090",
is_flag=False,
type=int,
help="Grpc port for the agent service",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!!

Signed-off-by: Future-Outlier <[email protected]>
Co-authored-by: Eduardo Apolinario  <[email protected]>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 17, 2025

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - We encountered technical difficulties while attempting to generate code feedback. Please try again or contact [email protected].

Signed-off-by: Future-Outlier <[email protected]>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 17, 2025

Code Review Agent Run #6c3b01

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 264f40d..d0e6b56
    • flytekit/clis/sdk_in_container/serve.py
    • tests/flytekit/clis/sdk_in_container/test_serve.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants