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

[Serve] add RAY_SERVE_LOG_ENCODING env to set the global logging behavior for Serve #42781

Merged

Conversation

GeneDer
Copy link
Contributor

@GeneDer GeneDer commented Jan 29, 2024

Why are these changes needed?

We want a way to be able to use environment variables to setup Serve's structured json logging on the platform. Add RAY_SERVE_LOG_ENCODING_ENV env to set the global logging behavior for Serve.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Gene Su <e870252314@gmail.com>
@GeneDer GeneDer self-assigned this Jan 29, 2024
@GeneDer GeneDer marked this pull request as ready for review January 29, 2024 17:03
…r for Serve

Signed-off-by: Gene Su <e870252314@gmail.com>
Signed-off-by: Gene Su <e870252314@gmail.com>
@GeneDer GeneDer changed the title [Serve] drop RAY_SERVE_ENABLE_JSON_LOGGING deprecated message [Serve] add RAY_SERVE_LOG_ENCODING_ENV env to set the global logging behavior for Serve Jan 29, 2024
Signed-off-by: Gene Su <e870252314@gmail.com>
Signed-off-by: Gene Su <e870252314@gmail.com>
Signed-off-by: Gene Su <e870252314@gmail.com>
Signed-off-by: Gene Su <e870252314@gmail.com>
["FOOBAR", "TEXT"],
],
)
def test_configure_component_logger_with_log_encoding_env(monkeypatch, log_encoding):
Copy link
Contributor

Choose a reason for hiding this comment

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

please also test the override behavior if users specify the encoding in their logging_config. I assume that env var is lowest precedence

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, but this kinda requires us to default to an encoding that's neither text nor json in the logging_config so we know if user has explicitly set it. Let me take a stab

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now just use None to represent the encoding not being set in the logging config. But open to adding new enum of NOT_SET or other ideas :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch, this actually won't work. The protobuf doesn't like None😅 Gonna just add a NOT_SET enum

python/ray/serve/_private/logging_utils.py Outdated Show resolved Hide resolved
python/ray/serve/_private/logging_utils.py Outdated Show resolved Hide resolved
Signed-off-by: Gene Su <e870252314@gmail.com>
Signed-off-by: Gene Su <e870252314@gmail.com>
Signed-off-by: Gene Su <e870252314@gmail.com>
Signed-off-by: Gene Su <e870252314@gmail.com>
Signed-off-by: Gene Su <e870252314@gmail.com>
Signed-off-by: Gene Su <e870252314@gmail.com>
Signed-off-by: Gene Su <e870252314@gmail.com>
@edoakes edoakes changed the title [Serve] add RAY_SERVE_LOG_ENCODING_ENV env to set the global logging behavior for Serve [Serve] add RAY_SERVE_LOG_ENCODING env to set the global logging behavior for Serve Jan 31, 2024
Comment on lines 168 to 169
# Jsonify the log messages
RAY_SERVE_ENABLE_JSON_LOGGING = os.environ.get("RAY_SERVE_ENABLE_JSON_LOGGING") == "1"
Copy link
Contributor

Choose a reason for hiding this comment

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

note here that this one is deprecated and getting removed

Copy link
Contributor

@edoakes edoakes left a comment

Choose a reason for hiding this comment

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

Just small comments

@@ -130,10 +135,11 @@ class Config:
extra = Extra.forbid

encoding: Union[str, EncodingType] = Field(
default="TEXT",
default_factory=_ray_serve_log_encoding,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
default_factory=_ray_serve_log_encoding,
default_factory=lambda: RAY_SERVE_LOG_ENCODING,

A little easier to read IMO :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can actually just be RAY_SERVE_LOG_ENCODING, no need for the factory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I tried default= RAY_SERVE_LOG_ENCODING initially, but patching and reloading modules correctly in pytest is almost impossible 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it 👍

description=(
"Encoding type for the serve logs. Default to 'TEXT'. 'JSON' is also "
"supported to format all serve logs into json structure."
"Encoding type for the serve logs. Default to 'TEXT'. The default can be "
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Encoding type for the serve logs. Default to 'TEXT'. The default can be "
"Encoding type for the serve logs. Defaults to 'TEXT'. The default can be "

"supported to format all serve logs into json structure."
"Encoding type for the serve logs. Default to 'TEXT'. The default can be "
"overwritten using the `RAY_SERVE_LOG_ENCODING` environment variable. "
"'JSON' is also supported to format all serve logs into json structure."
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"'JSON' is also supported to format all serve logs into json structure."
"'JSON' is also supported for structured logging."

Signed-off-by: Gene Su <e870252314@gmail.com>
@GeneDer
Copy link
Contributor Author

GeneDer commented Feb 1, 2024

@edoakes this is ready for merge

@edoakes edoakes merged commit 55a4ee4 into ray-project:master Feb 1, 2024
9 checks passed
@GeneDer GeneDer deleted the drop-json-logging-deprecation-message branch March 13, 2024 17:42
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.

2 participants