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 const getRayConfig = () => get<RayConfigResponse>("/api/ray_config", {});
export type UsageStatsEnabledResponse = { export type UsageStatsEnabledResponse = {
enabled: boolean; usageStatsEnabled: boolean;
usageStatsPromptEnabled: boolean;
}; };
export const getUsageStatsEnabled = () => export const getUsageStatsEnabled = () =>

View file

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

View file

@ -18,6 +18,7 @@ class UsageStatsHead(dashboard_utils.DashboardHeadModule):
def __init__(self, dashboard_head): def __init__(self, dashboard_head):
super().__init__(dashboard_head) super().__init__(dashboard_head)
self.usage_stats_enabled = ray_usage_lib.usage_stats_enabled() 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( self.cluster_metadata = ray_usage_lib.get_cluster_metadata(
ray.experimental.internal_kv.internal_kv_get_gcs_client(), ray.experimental.internal_kv.internal_kv_get_gcs_client(),
num_retries=20, num_retries=20,
@ -44,7 +45,8 @@ class UsageStatsHead(dashboard_utils.DashboardHeadModule):
return ray.dashboard.optional_utils.rest_response( return ray.dashboard.optional_utils.rest_response(
success=True, success=True,
message="Fetched usage stats enabled", 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): 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 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 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: def show_usage_stats_prompt() -> None:
if not _usage_stats_prompt_enabled(): if not usage_stats_prompt_enabled():
return return
from ray.autoscaler._private.cli_logger import cli_logger 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._private.usage.usage_lib import UsageStatsEnabledness
from ray.autoscaler._private.cli_logger import cli_logger 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 = {
"$schema": "http://json-schema.org/draft-07/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(): def test_library_usages():
if os.environ.get("RAY_MINIMAL") == "1": if os.environ.get("RAY_MINIMAL") == "1":
# Doesn't work with minimal installation # Doesn't work with minimal installation