Skip to content

[core|serve] Migrate serve imports from ray._private to ray._common#61363

Merged
edoakes merged 26 commits intoray-project:masterfrom
MkDev11:migrate-serve-from-private-to-common
Mar 12, 2026
Merged

[core|serve] Migrate serve imports from ray._private to ray._common#61363
edoakes merged 26 commits intoray-project:masterfrom
MkDev11:migrate-serve-from-private-to-common

Conversation

@MkDev11
Copy link
Contributor

@MkDev11 MkDev11 commented Feb 26, 2026

Description

This PR continues the migration from ray._private to ray._common so that Ray Serve (and other libraries) do not depend on internal private APIs. It migrates tls_utils and logging constants out of _private into _common, and updates all consumers (Serve, dashboard, client server) to import from the new locations.

Changes:

  1. ray._common.tls_utils

    • Moved generate_self_signed_tls_certs() from _private.tls_utils into _common.tls_utils (it only depended on _common.network_utils).
    • _private.tls_utils re-exports it for backward compatibility.
    • Serve: serve/tests/test_https_proxy.py now imports from ray._common.tls_utils.
    • Other consumers: _private/grpc_utils.py, _private/test_utils.py, dashboard/agent.py, util/client/server/proxier.py, util/client/server/server.py updated.
  2. ray._common.logging_constants

    • New module containing LOGRECORD_STANDARD_ATTRS (frozenset), LOGGER_FLATTEN_KEYS, and LogKey enum — all moved from _private.ray_logging.constants.
    • _private.ray_logging.constants is deleted; _private.ray_logging.logging_config now imports from _common.
    • Serve: serve/schema.py now imports LOGRECORD_STANDARD_ATTRS from ray._common.logging_constants.
  3. ray._common.filters / ray._common.formatters

    • Updated internal imports to use ray._common.logging_constants instead of ray._private.ray_logging.constants.

Tests:

  • New ray/_common/tests/test_logging_constants.py — tests the full LOGRECORD_STANDARD_ATTRS frozenset, all LogKey enum members, and LOGGER_FLATTEN_KEYS.
  • New ray/_common/tests/test_tls_utils.py — tests generate_self_signed_tls_certs.
  • Lint: ruff check and format pass on all changed files.

Related issues

Fixes #53478 (partial: migrates Serve-side imports for tls_utils and logging constants; remaining items like runtime_env_uri and worker_compat can be done in follow-up PRs).

Additional information

@MkDev11 MkDev11 requested review from a team, MengjinYan, edoakes and israbbani as code owners February 26, 2026 19:15
@MkDev11 MkDev11 force-pushed the migrate-serve-from-private-to-common branch from db77238 to 330e601 Compare February 26, 2026 19:16
@MkDev11
Copy link
Contributor Author

MkDev11 commented Feb 26, 2026

@abrarsheikh please review the PR and let me know your feedback

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively continues the migration of Serve imports from ray._private to ray._common, which is a great step towards a cleaner architecture and reducing dependencies on internal APIs. The changes are well-structured, moving utilities to _common and updating Serve's codebase to use them, while maintaining backward compatibility with re-exports. The addition of new tests and a verification script is also a solid contribution to ensure the migration is correct and prevent future regressions.

I have a few minor suggestions in the new test files to improve test specificity and code style, but overall this is a high-quality contribution.

@abrarsheikh abrarsheikh added the go add ONLY when ready to merge, run all tests label Feb 26, 2026
- Add ray._common.tls_utils with generate_self_signed_tls_certs (moved from
  _private; _private re-exports for backward compatibility).
- Add ray._common.logging_constants with LOGRECORD_STANDARD_ATTRS; update
  _private.ray_logging.constants to import from _common.
- Add ray._common.runtime_env_uri re-exporting parse_uri and Protocol from
  _private.runtime_env for use by Serve schema.
- Add ray._common.worker_compat with set_blocking_get_inside_async_warned
  so Serve can mute the async warning without importing _private.worker.

Serve now imports only from ray._common for these utilities:
- serve/schema.py: LOGRECORD_STANDARD_ATTRS, parse_uri
- serve/tests/test_https_proxy.py: generate_self_signed_tls_certs
- serve/__init__.py: set_blocking_get_inside_async_warned

Includes tests for tls_utils, logging_constants, and runtime_env_uri, plus
a verification script for serve having no direct ray._private imports.

Ref: ray-project#53478
Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
… error messages

- test_logging_constants: assert exact count (23) instead of >= 20
- test_runtime_env_uri: use package_name, assert exact parse_uri output
- test_tls_utils: single with + two temp files, no manual cleanup
- schema.py, logging_config.py: format LOGRECORD_STANDARD_ATTRS as set() in error messages for readable output

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
…rify script

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
@MkDev11 MkDev11 force-pushed the migrate-serve-from-private-to-common branch from e680d30 to a966037 Compare February 26, 2026 21:22
Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
@ray-gardener ray-gardener bot added the community-contribution Contributed by the community label Feb 27, 2026

from typing import Any, Optional, Tuple

from ray._private import worker
Copy link
Contributor

Choose a reason for hiding this comment

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

if common depends on _private, i dont think that is any better than directly accessing _private. defer to @edoakes for recommendations on what we want to do here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree with it. I reverted the worker_compat migration in this PR and deferred this direction pending @edoakes guidance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@edoakes also here

Rollback worker_compat/runtime_env_uri moves pending maintainer direction, remove redundant test module docstrings, and switch TLS cert helper callsites to ray._common without _private re-export.

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
@MkDev11
Copy link
Contributor Author

MkDev11 commented Feb 27, 2026

@abrarsheikh just pushed the changes, please review again

MkDev11 and others added 5 commits February 27, 2026 11:22
Re-export generate_self_signed_tls_certs from ray._private.tls_utils to preserve backward compatibility for existing import paths.

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
Revert assistant-applied commits from this chat session and restore branch contents to the pre-session baseline.

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
This reverts commit 85cf7d9.

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
Create an empty signed commit to retrigger premerge checks.

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
Remove python/ray/_private/tls_utils.py and
python/ray/_private/ray_logging/constants.py since all call sites
now import directly from ray._common.

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
@MkDev11
Copy link
Contributor Author

MkDev11 commented Mar 2, 2026

@abrarsheikh can you please review the changes again?

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Wrap LOGRECORD_STANDARD_ATTRS with set() in serve/schema.py error
message to display {...} instead of frozenset({...}).

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
@MkDev11 MkDev11 requested a review from abrarsheikh March 3, 2026 11:04
@abrarsheikh
Copy link
Contributor

please fix the premerge

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
@MkDev11
Copy link
Contributor Author

MkDev11 commented Mar 3, 2026

fixed

@MkDev11
Copy link
Contributor Author

MkDev11 commented Mar 4, 2026

how ya doing? @abrarsheikh
can we merge this PR now?

@abrarsheikh
Copy link
Contributor

Needs to be signed off from ray-core team members before merging. Someone will get to it soon :)

…ate-serve-from-private-to-common

# Conflicts:
#	python/ray/serve/schema.py
@MkDev11
Copy link
Contributor Author

MkDev11 commented Mar 10, 2026

@abrarsheikh it's been 5 days since you approved the PR. can you please help me mege this PR asap?

@abrarsheikh
Copy link
Contributor

premerge is failing. that's needs to be green before we can merge

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
@MkDev11
Copy link
Contributor Author

MkDev11 commented Mar 11, 2026

premerge is failing. that's needs to be green before we can merge

all checks passed, can we merge it?

@abrarsheikh
Copy link
Contributor

@edoakes for core review.

@MkDev11
Copy link
Contributor Author

MkDev11 commented Mar 12, 2026

hi @kouroshHakha can you please merge this PR?

@MkDev11
Copy link
Contributor Author

MkDev11 commented Mar 12, 2026

seems like that @edoakes is offline several days

Copy link
Contributor

@MengjinYan MengjinYan left a comment

Choose a reason for hiding this comment

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

Looks good overall! Added nit comments.

Also, looks like the changes in the PR doesn't quite match the PR description. Can we update the PR description?



def test_logrecord_standard_attrs_contains_standard_names():
expected = {"message", "levelname", "name", "pathname", "lineno", "exc_info"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: I'm wondering if we should test the whole set?

from enum import Enum

assert issubclass(LogKey, Enum)
assert LogKey.JOB_ID.value == "job_id"
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar as above, wondering if we should test the full set of keys?

Test the complete LOGRECORD_STANDARD_ATTRS frozenset and all LogKey enum
members instead of just a subset, as requested by MengjinYan.

Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
@MkDev11 MkDev11 requested a review from MengjinYan March 12, 2026 02:39
@MkDev11
Copy link
Contributor Author

MkDev11 commented Mar 12, 2026

@MengjinYan thanks for your feedback, I implemented your comments and update the pr description again. can you please review again?

MkDev11 and others added 3 commits March 12, 2026 15:10
Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
Signed-off-by: mkdev11 <MkDev11@users.noreply.github.com>
@edoakes edoakes merged commit 51e923d into ray-project:master Mar 12, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[core|serve] Migrate shared utilities from ray._private to ray._common

4 participants