You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add additional_log_standard_attrs to serve logging config (#51144)
### Changes Introduced
1. **Consistent Logging Configuration**
- Added `additional_log_standard_attrs` to Serve's `LoggingConfig`,
aligning it with Ray's logging configuration.
2. **Refactored `ServeFormatter`**
- `ServeFormatter` now inherits from Ray’s `TextFormatter`.
3. **Fixed Potential Bug in `_proto_to_dict`**
- Previously, `_proto_to_dict` retained the data type for repeated
fields as
`google.protobuf.internal.containers.RepeatedScalarFieldContainer`
instead of converting it to a Python `list`.
- This caused validation failures in Pydantic.
- The issue did not surface earlier because
`DeploymentConfig.user_configured_option_names` (the only prior repeated
attribute user) explicitly disabled data type validation.
4. schema change to `src/ray/protobuf/serve.proto`
### Discussion & Feedback Needed
- If we don’t modify `_proto_to_dict`, alternative approaches include:
1. Disabling type checking for Serve’s `LoggingConfig`.
2. Performing type casting in `from_proto`.
- Seeking input from reviewers on the preferred approach.
### How do i know this works
1. updated unit tests
2. Manual test
sample code
```python
import logging
from ray import serve
import requests
import starlette
logger = logging.getLogger("ray.serve")
logging_config = {
"additional_log_standard_attrs": ["name"],
}
@serve.deployment(logging_config=logging_config)
class Model:
def __call__(self, req: starlette.requests.Request):
logger.info("This is a test log")
return 1
serve.run(Model.bind())
resp = requests.get("http://127.0.0.1:8000/")
assert resp.status_code == 200
resp = resp.json()
```
results from changes in this PR
```zsh
(myenv) ➜ serve_apps python app1.py
2025-03-07 15:07:18,712 INFO worker.py:1839 -- Started a local Ray instance. View the dashboard at 127.0.0.1:8265
(ProxyActor pid=85544) INFO 2025-03-07 15:07:20,223 proxy 127.0.0.1 -- Proxy starting on node 799527b99924c6f2084364a36726a6874d28bfba171c5a06d619bdb2 (HTTP port: 8000).
INFO 2025-03-07 15:07:20,301 serve 85513 -- Started Serve in namespace "serve".
(ProxyActor pid=85544) INFO 2025-03-07 15:07:20,252 proxy 127.0.0.1 -- Got updated endpoints: {}.
(ServeController pid=85545) INFO 2025-03-07 15:07:20,403 controller 85545 -- Deploying new version of Deployment(name='Model', app='default') (initial target replicas: 1).
(ProxyActor pid=85544) INFO 2025-03-07 15:07:20,405 proxy 127.0.0.1 -- Got updated endpoints: {Deployment(name='Model', app='default'): EndpointInfo(route='/', app_is_cross_language=False)}.
(ProxyActor pid=85544) INFO 2025-03-07 15:07:20,408 proxy 127.0.0.1 -- Started <ray.serve._private.router.SharedRouterLongPollClient object at 0x12c068b80>.
(ServeController pid=85545) INFO 2025-03-07 15:07:20,505 controller 85545 -- Adding 1 replica to Deployment(name='Model', app='default').
INFO 2025-03-07 15:07:21,417 serve 85513 -- Application 'default' is ready at http://127.0.0.1:8000/.
(ServeReplica:default:Model pid=85549) /Users/abrar/pg/ray/python/ray/serve/_private/replica.py:1320: UserWarning: Calling sync method '__call__' directly on the asyncio loop. In a future version, sync methods will be run in a threadpool by default. Ensure your sync methods are thread safe or keep the existing behavior by making them `async def`. Opt into the new behavior by setting RAY_SERVE_RUN_SYNC_IN_THREADPOOL=1.
(ServeReplica:default:Model pid=85549) warnings.warn(
(ServeReplica:default:Model pid=85549) INFO 2025-03-07 15:07:21,434 default_Model pd962afl 4e386730-546d-4693-abb4-72e107cfe87f ray.serve -- This is a test log
(ServeReplica:default:Model pid=85549) INFO 2025-03-07 15:07:21,435 default_Model pd962afl 4e386730-546d-4693-abb4-72e107cfe87f ray.serve -- GET / 200 4.1ms
```
results from code from master
```zsh
(myenv) ➜ serve_apps python app1.py
2025-03-07 10:01:31,875 INFO worker.py:1839 -- Started a local Ray instance. View the dashboard at 127.0.0.1:8265
(ProxyActor pid=41050) INFO 2025-03-07 10:01:33,414 proxy 127.0.0.1 -- Proxy starting on node 2194f00eb1063128758f6d7e6d5a56f7425845ac6492ca35cf04ab15 (HTTP port: 8000).
(ProxyActor pid=41050) INFO 2025-03-07 10:01:33,442 proxy 127.0.0.1 -- Got updated endpoints: {}.
INFO 2025-03-07 10:01:33,461 serve 41018 -- Started Serve in namespace "serve".
(ServeController pid=41052) INFO 2025-03-07 10:01:33,472 controller 41052 -- Deploying new version of Deployment(name='Model', app='default') (initial target replicas: 1).
(ProxyActor pid=41050) INFO 2025-03-07 10:01:33,474 proxy 127.0.0.1 -- Got updated endpoints: {Deployment(name='Model', app='default'): EndpointInfo(route='/', app_is_cross_language=False)}.
(ProxyActor pid=41050) INFO 2025-03-07 10:01:33,478 proxy 127.0.0.1 -- Started <ray.serve._private.router.SharedRouterLongPollClient object at 0x1289f14f0>.
(ServeController pid=41052) INFO 2025-03-07 10:01:33,575 controller 41052 -- Adding 1 replica to Deployment(name='Model', app='default').
INFO 2025-03-07 10:01:34,574 serve 41018 -- Application 'default' is ready at http://127.0.0.1:8000/.
(ServeReplica:default:Model pid=41056) /Users/abrar/pg/ray/python/ray/serve/_private/replica.py:1320: UserWarning: Calling sync method '__call__' directly on the asyncio loop. In a future version, sync methods will be run in a threadpool by default. Ensure your sync methods are thread safe or keep the existing behavior by making them `async def`. Opt into the new behavior by setting RAY_SERVE_RUN_SYNC_IN_THREADPOOL=1.
(ServeReplica:default:Model pid=41056) warnings.warn(
(ServeReplica:default:Model pid=41056) INFO 2025-03-07 10:01:34,582 default_Model 8e8rohb4 72547bda-8287-4767-910a-0763dbabf96b -- This is a test log
(ServeReplica:default:Model pid=41056) INFO 2025-03-07 10:01:34,582 default_Model 8e8rohb4 72547bda-8287-4767-910a-0763dbabf96b -- GET / 200 3.0ms
```
---------
Signed-off-by: Abrar Sheikh <[email protected]>
0 commit comments