Skip to content

Add observability for label-selectors - #53423

Merged
edoakes merged 3 commits into
ray-project:masterfrom
alanwguo:label-obs
Jun 11, 2025
Merged

edoakes merged 3 commits into
ray-project:masterfrom
alanwguo:label-obs

Conversation

@alanwguo

Copy link
Copy Markdown
Contributor

Why are these changes needed?

label-based selection is being added as a feature. tracker here: #51564

As part of the feature, we should allow users to observe labels of nodes and selection rules of tasks and actors.
This PR adds these fields to:

  • state api CLI output
  • state api API responses
  • Ray Dashboard UI

Nodes:
Screenshot 2025-05-29 at 2 26 30 PM
Screenshot 2025-05-29 at 2 26 26 PM

Tasks:
Screenshot 2025-05-29 at 2 26 49 PM
Screenshot 2025-05-29 at 2 26 53 PM

Actors:
Screenshot 2025-05-29 at 3 06 15 PM
Screenshot 2025-05-29 at 3 06 17 PM

Related issue number

Checks

@alanwguo
alanwguo requested review from a team, pcmoritz and raulchen as code owners May 29, 2025 23:07
@alanwguo
alanwguo marked this pull request as draft May 29, 2025 23:07
@alanwguo

Copy link
Copy Markdown
Contributor Author

@nikitavemuri @MengjinYan, this is working except for the export task events. Any ideas what's missing?

@MengjinYan , ptal if this interferes with your new export work.

Signed-off-by: Alan Guo <[email protected]>
@alanwguo

Copy link
Copy Markdown
Contributor Author

Any idea why clang-format is not working? I installed it on my mac with brew install clang-format

@MengjinYan

MengjinYan commented May 30, 2025 •

Copy link
Copy Markdown
Contributor

@nikitavemuri @MengjinYan, this is working except for the export task events. Any ideas what's missing?

I tried with a local setup and I can see the label_selectors in one of the export_task_events:

{
  "event_data": {
    "attempt_number": 0,
    "job_id": "AQAAAA==",
    "state_updates": {
      "node_id": "s2vXu4O2zoSYp7lyenw3SpAshKdrhi0ymstVuA==",
      "state_ts_ns": {
        "1": "1748648100752828000",
        "2": "1748648100752871000",
        "5": "1748648100753810000"
      },
      "worker_id": "MppU4ViQhW4Xqu+E8YMc997YHHVp5cQIKI8trg=="
    },
    "task_id": "yO9FzNARJXH///////////////8BAAAA",
    "task_info": {
      "func_or_class_name": "test_label_success",
      "label_selector": {
        "test-lable-key": "test-lable-value"  // <======== The label selector
      },
      "labels": {},
      "language": "PYTHON",
      "parent_task_id": "//////////////////////////8BAAAA",
      "required_resources": {
        "CPU": 1
      },
      "runtime_env_info": {
        "runtime_env_config": {
          "eager_install": true,
          "log_files": [],
          "setup_timeout_seconds": 600
        },
        "serialized_runtime_env": "{}",
        "uris": {
          "py_modules_uris": [],
          "working_dir_uri": ""
        }
      },
      "task_id": "yO9FzNARJXH///////////////8BAAAA",
      "type": "NORMAL_TASK"
    }
  },
  "event_id": "5b1416805fa99b47c02819115647b9d2b80c",
  "source_type": "EXPORT_TASK",
  "timestamp": 1748648101
}

Is it something you tested or you were looking at something else for the export task event?

@MengjinYan , ptal if this interferes with your new export work.

No. This won't interferes with my work now.

@MengjinYan

Copy link
Copy Markdown
Contributor

Any idea why clang-format is not working? I installed it on my mac with brew install clang-format

I never tried brew install clang-format for the lint installation

Normally I follow https://docs.ray.io/en/latest/ray-contribute/development.html#installing-additional-dependencies-for-development to install the additional dependencies for lint:

pip install -c python/requirements_compiled.txt -r python/requirements/lint-requirements.txt

Probably you can try that to see if it will be helpful.

Signed-off-by: Alan Guo <[email protected]>
@alanwguo
alanwguo marked this pull request as ready for review June 2, 2025 17:15
@alanwguo

alanwguo commented Jun 2, 2025

Copy link
Copy Markdown
Contributor Author

Any idea why clang-format is not working? I installed it on my mac with brew install clang-format

I never tried brew install clang-format for the lint installation

Normally I follow https://docs.ray.io/en/latest/ray-contribute/development.html#installing-additional-dependencies-for-development to install the additional dependencies for lint:

pip install -c python/requirements_compiled.txt -r python/requirements/lint-requirements.txt

Probably you can try that to see if it will be helpful.

yes, this fixed it. Thanks!

@alanwguo alanwguo added the go add ONLY when ready to merge, run all tests label Jun 3, 2025

@ryanaoleary ryanaoleary left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for adding this!

@MengjinYan MengjinYan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for the late review. It looks good. Thanks!

@edoakes
edoakes merged commit 2f93603 into ray-project:master Jun 11, 2025
elliot-barn pushed a commit that referenced this pull request Jun 18, 2025
label-based selection is being added as a feature. tracker here:
#51564

As part of the feature, we should allow users to observe labels of nodes
and selection rules of tasks and actors.
This PR adds these fields to:
- state api CLI output
- state api API responses
- Ray Dashboard UI

Nodes:
![Screenshot 2025-05-29 at 2 26
30 PM](https://github.com/user-attachments/assets/1dcd5faf-bdcf-440b-b03f-0eeeb23a46bb)
![Screenshot 2025-05-29 at 2 26
26 PM](https://github.com/user-attachments/assets/8b37c283-342f-43e6-8d87-19e56e514817)

Tasks:
![Screenshot 2025-05-29 at 2 26
49 PM](https://github.com/user-attachments/assets/15c1fc6f-e540-4030-99ec-ae9124df83eb)
![Screenshot 2025-05-29 at 2 26
53 PM](https://github.com/user-attachments/assets/e078981f-cf46-47a1-b49a-4e37ffa63502)

Actors:
![Screenshot 2025-05-29 at 3 06
15 PM](https://github.com/user-attachments/assets/7de5c507-c44d-412f-828a-6b30a7466e04)
![Screenshot 2025-05-29 at 3 06
17 PM](https://github.com/user-attachments/assets/954b36e0-9042-41e6-a4a9-d88803559975)

---------

Signed-off-by: Alan Guo <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
elliot-barn pushed a commit that referenced this pull request Jul 2, 2025
label-based selection is being added as a feature. tracker here:
#51564

As part of the feature, we should allow users to observe labels of nodes
and selection rules of tasks and actors.
This PR adds these fields to:
- state api CLI output
- state api API responses
- Ray Dashboard UI

Nodes:
![Screenshot 2025-05-29 at 2 26
30 PM](https://github.com/user-attachments/assets/1dcd5faf-bdcf-440b-b03f-0eeeb23a46bb)
![Screenshot 2025-05-29 at 2 26
26 PM](https://github.com/user-attachments/assets/8b37c283-342f-43e6-8d87-19e56e514817)

Tasks:
![Screenshot 2025-05-29 at 2 26
49 PM](https://github.com/user-attachments/assets/15c1fc6f-e540-4030-99ec-ae9124df83eb)
![Screenshot 2025-05-29 at 2 26
53 PM](https://github.com/user-attachments/assets/e078981f-cf46-47a1-b49a-4e37ffa63502)

Actors:
![Screenshot 2025-05-29 at 3 06
15 PM](https://github.com/user-attachments/assets/7de5c507-c44d-412f-828a-6b30a7466e04)
![Screenshot 2025-05-29 at 3 06
17 PM](https://github.com/user-attachments/assets/954b36e0-9042-41e6-a4a9-d88803559975)

---------

Signed-off-by: Alan Guo <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
edoakes pushed a commit that referenced this pull request Jul 9, 2025
ccmao1130 pushed a commit to ccmao1130/ray that referenced this pull request Jul 29, 2025
jugalshah291 pushed a commit to jugalshah291/ray_fork that referenced this pull request Sep 11, 2025
dstrodtman pushed a commit to dstrodtman/ray that referenced this pull request Oct 6, 2025
edoakes pushed a commit that referenced this pull request Mar 12, 2026
…60659)

## Description

Add observability for `fallback_strategy` in State API and GCS.

While Ray currently provides visibility for `label_selector` (#53423),
there is no mechanism to observe the `fallback_strategy` from outside
the system.

This PR exposes `fallback_strategy` in `TaskInfoEntry and
ActorTableData`. The ability to read and record `fallback_strategy` is
essential for our custom autoscaler development. When primary
`label_selector` constraints cannot be met, the autoscaler must access
these recorded `fallback strategies` to prioritize and allocate
alternative devices.

Beyond autoscaling, adding this feature will provide a better debugging
experience by allowing users to transparently track the entire
scheduling intent, including the `fallback_strategy` for both tasks and
actors.

## Related issues

Related to #51564

## Additional information
```py
from ray import serve  
import ray  
from ray.util.scheduling_strategies import NodeLabelSchedulingStrategy, In, Exists  

@serve.deployment(  
    name="soft_docker_deployment",  
    ray_actor_options={  
        "label_selector": {"docker-image": "in(test-image)"},
        "fallback_strategy": [
            {"label_selector": {"docker-image": "in(test-image2)"}},
        ]  
    }
)
class SoftDockerDeployment:  
    def __call__(self, request):  
        node_labels = ray.get_runtime_context().get_node_labels()  
        return {  
            "message": "Hello from soft-docker deployment!",  
            "node_labels": node_labels  
        }  
  
if __name__ == "__main__":  
    serve.start(http_options={"host": "0.0.0.0", "port": 8000})  
    serve.run(SoftDockerDeployment.bind())
```
#### GlobalStateAccessor.get_actor_table
<img width="1224" height="1076" alt="image"
src="https://github.com/user-attachments/assets/5c66a483-9fce-46a1-a4e7-86874f6a8b27"
/>

#### ray list actors --detail
<img width="836" height="724" alt="image"
src="https://github.com/user-attachments/assets/d99c1c6f-b0f7-4d25-9638-4a2fdd805a0d"
/>

---------

Signed-off-by: Dongjun Na <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants