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

Adds in the ability for the client to get a remote_id from the server #15849

Merged
merged 16 commits into from
Oct 29, 2024

Conversation

sam-phinizy
Copy link
Contributor

@sam-phinizy sam-phinizy commented Oct 29, 2024

Add in the optional ability for a worker to get it's ID from the server using the heartbeat mechanism. This should only be enabled if PREFECT_EXPERIMENTAL_WORKER_LOGGING_API_ENABLED is set. This PR doesn't do any logging atm, just set the ground work for future PRs.

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

Copy link

codspeed-hq bot commented Oct 29, 2024

CodSpeed Performance Report

Merging #15849 will not alter performance

Comparing sam-p/get-worker-id-from-server (229f0a2) with main (7903f46)

Summary

✅ 3 untouched benchmarks

@sam-phinizy sam-phinizy reopened this Oct 29, 2024
@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 19:11
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 19:11
@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 19:42
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 19:42
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

This is looking good! Just a few minor comments from me

if (
get_current_settings().experiments.worker_logging_to_api_enabled
and (
"api.prefect.cloud" in get_current_settings().api.url
Copy link
Member

Choose a reason for hiding this comment

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

You can check with the current client if it's connected to Cloud like this:

self._client.server_type == ServerType.CLOUD

Comment on lines 2607 to 2633

if get_worker_id:
return_dict = {"return_id": get_worker_id}
else:
return_dict = {}

resp = await self._client.post(
f"/work_pools/{work_pool_name}/workers/heartbeat",
json={
"name": worker_name,
"heartbeat_interval_seconds": heartbeat_interval_seconds,
},
}
| return_dict,
)

if get_worker_id and resp.status_code == 200:
return UUID(resp.text)
else:
return None
Copy link
Member

Choose a reason for hiding this comment

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

I think we might want to include a check for whether the client is connected to Cloud in this method. If someone is using this method directly with an self-hosted server, it'd cause problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default /heartbeat should only send 204s not 200s but I agree it's probably better to be safe then sorry!

@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 19:48
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 19:48
@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 19:54
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 19:54
@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 20:09
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 20:09
@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 20:13
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 20:13
@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 20:15
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 20:16
@sam-phinizy sam-phinizy force-pushed the sam-p/get-worker-id-from-server branch from 4e8cb41 to 52d747f Compare October 29, 2024 20:16
@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 20:21
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 20:21
@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 20:22
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 20:22
@github-actions github-actions bot added the docs label Oct 29, 2024
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

One small comment on the client method docstring, but the rest LGTM!

src/prefect/client/orchestration.py Outdated Show resolved Hide resolved
Co-authored-by: Alexander Streed <desertaxle@users.noreply.github.com>
@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 21:11
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 21:11
@sam-phinizy sam-phinizy marked this pull request as draft October 29, 2024 21:56
@sam-phinizy sam-phinizy marked this pull request as ready for review October 29, 2024 21:56
@sam-phinizy sam-phinizy merged commit 2c9b857 into main Oct 29, 2024
37 checks passed
@sam-phinizy sam-phinizy deleted the sam-p/get-worker-id-from-server branch October 29, 2024 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants