Don't show usage stats prompt in dashboard if prompt is disabled (#24700) (#24735)

This commit is contained in:
Jiajun Yao 2022-05-13 09:36:10 -07:00 committed by GitHub
parent 677b5c33db
commit 930ecfaf1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 30 deletions

View file

@ -37,7 +37,8 @@ export type RayConfigResponse = {
export const getRayConfig = () => get<RayConfigResponse>("/api/ray_config", {});
export type UsageStatsEnabledResponse = {
enabled: boolean;
usageStatsEnabled: boolean;
usageStatsPromptEnabled: boolean;
};
export const getUsageStatsEnabled = () =>

View file

@ -105,14 +105,12 @@ const Dashboard: React.FC = () => {
}
const SelectedComponent = tabs[tab].component;
const [usageStatsPromptEnabled, setUsageStatsPromptEnabled] = useState(false);
const [usageStatsEnabled, setUsageStatsEnabled] = useState(false);
useEffect(() => {
getUsageStatsEnabled().then((res) => {
if (res.enabled) {
setUsageStatsEnabled(true);
} else {
setUsageStatsEnabled(false);
}
setUsageStatsPromptEnabled(res.usageStatsPromptEnabled);
setUsageStatsEnabled(res.usageStatsEnabled);
});
}, []);
return (
@ -139,26 +137,28 @@ const Dashboard: React.FC = () => {
))}
</Tabs>
<SelectedComponent />
<Alert style={{ marginTop: 30 }} severity="info">
{usageStatsEnabled ? (
<span>
Usage stats collection is enabled. To disable this, add
`--disable-usage-stats` to the command that starts the cluster, or
run the following command: `ray disable-usage-stats` before starting
the cluster. See{" "}
<a
href="https://docs.ray.io/en/master/cluster/usage-stats.html"
target="_blank"
rel="noreferrer"
>
https://docs.ray.io/en/master/cluster/usage-stats.html
</a>{" "}
for more details.
</span>
) : (
<span>Usage stats collection is disabled.</span>
)}
</Alert>
{usageStatsPromptEnabled ? (
<Alert style={{ marginTop: 30 }} severity="info">
{usageStatsEnabled ? (
<span>
Usage stats collection is enabled. To disable this, add
`--disable-usage-stats` to the command that starts the cluster, or
run the following command: `ray disable-usage-stats` before
starting the cluster. See{" "}
<a
href="https://docs.ray.io/en/master/cluster/usage-stats.html"
target="_blank"
rel="noreferrer"
>
https://docs.ray.io/en/master/cluster/usage-stats.html
</a>{" "}
for more details.
</span>
) : (
<span>Usage stats collection is disabled.</span>
)}
</Alert>
) : null}
<LastUpdated />
</div>
);

View file

@ -18,6 +18,7 @@ class UsageStatsHead(dashboard_utils.DashboardHeadModule):
def __init__(self, dashboard_head):
super().__init__(dashboard_head)
self.usage_stats_enabled = ray_usage_lib.usage_stats_enabled()
self.usage_stats_prompt_enabled = ray_usage_lib.usage_stats_prompt_enabled()
self.cluster_metadata = ray_usage_lib.get_cluster_metadata(
ray.experimental.internal_kv.internal_kv_get_gcs_client(),
num_retries=20,
@ -44,7 +45,8 @@ class UsageStatsHead(dashboard_utils.DashboardHeadModule):
return ray.dashboard.optional_utils.rest_response(
success=True,
message="Fetched usage stats enabled",
enabled=self.usage_stats_enabled,
usage_stats_enabled=self.usage_stats_enabled,
usage_stats_prompt_enabled=self.usage_stats_prompt_enabled,
)
def _report_usage_sync(self):

View file

@ -258,7 +258,7 @@ def usage_stats_enabled() -> bool:
return _usage_stats_enabledness() is not UsageStatsEnabledness.DISABLED_EXPLICITLY
def _usage_stats_prompt_enabled():
def usage_stats_prompt_enabled():
return int(os.getenv("RAY_USAGE_STATS_PROMPT_ENABLED", "1")) == 1
@ -287,7 +287,7 @@ def _generate_cluster_metadata():
def show_usage_stats_prompt() -> None:
if not _usage_stats_prompt_enabled():
if not usage_stats_prompt_enabled():
return
from ray.autoscaler._private.cli_logger import cli_logger

View file

@ -16,7 +16,11 @@ from ray._private.usage.usage_lib import ClusterConfigToReport
from ray._private.usage.usage_lib import UsageStatsEnabledness
from ray.autoscaler._private.cli_logger import cli_logger
from ray._private.test_utils import wait_for_condition
from ray._private.test_utils import (
format_web_url,
wait_for_condition,
wait_until_server_available,
)
schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
@ -285,6 +289,30 @@ def test_usage_lib_cluster_metadata_generation(monkeypatch, ray_start_cluster):
)
def test_usage_stats_enabled_endpoint(monkeypatch, ray_start_cluster):
if os.environ.get("RAY_MINIMAL") == "1":
# Doesn't work with minimal installation
# since we need http server.
return
import requests
with monkeypatch.context() as m:
m.setenv("RAY_USAGE_STATS_ENABLED", "0")
m.setenv("RAY_USAGE_STATS_PROMPT_ENABLED", "0")
cluster = ray_start_cluster
cluster.add_node(num_cpus=0)
context = ray.init(address=cluster.address)
webui_url = context["webui_url"]
assert wait_until_server_available(webui_url)
webui_url = format_web_url(webui_url)
response = requests.get(f"{webui_url}/usage_stats_enabled")
assert response.status_code == 200
assert response.json()["result"] is True
assert response.json()["data"]["usageStatsEnabled"] is False
assert response.json()["data"]["usageStatsPromptEnabled"] is False
def test_library_usages():
if os.environ.get("RAY_MINIMAL") == "1":
# Doesn't work with minimal installation