MCPcopy
hub / github.com/ray-project/ray / test_usage_report_disabled

Function test_usage_report_disabled

python/ray/_common/tests/test_usage_stats.py:1313–1363  ·  view source on GitHub ↗

Make sure usage report module is disabled when the env var is not set. It also verifies that the failure message is not printed (note that the invalid report url is given as an env var).

(
    monkeypatch, ray_start_cluster, start_usage_stats_server, reset_usage_stats
)

Source from the content-addressed store, hash-verified

1311
1312
1313def test_usage_report_disabled(
1314 monkeypatch, ray_start_cluster, start_usage_stats_server, reset_usage_stats
1315):
1316 """
1317 Make sure usage report module is disabled when the env var is not set.
1318 It also verifies that the failure message is not printed (note that
1319 the invalid report url is given as an env var).
1320 """
1321 with monkeypatch.context() as m:
1322 m.setenv("RAY_USAGE_STATS_ENABLED", "0")
1323 m.setenv("RAY_USAGE_STATS_REPORT_URL", "http://127.0.0.1:8000")
1324 m.setenv("RAY_USAGE_STATS_REPORT_INTERVAL_S", "1")
1325 m.delenv("RAY_USAGE_STATS_RAY_INIT_CLUSTER", raising=False)
1326
1327 usage_stats_server = start_usage_stats_server
1328
1329 cluster = ray_start_cluster
1330 cluster.add_node(num_cpus=0)
1331 ray.init(address=cluster.address)
1332
1333 """
1334 Verify the disabled usage stat is reported to the server.
1335 """
1336 wait_for_condition(lambda: usage_stats_server.num_reports == 1)
1337 # We should have one and only one report to the server.
1338 time.sleep(5)
1339 assert usage_stats_server.num_reports == 1
1340 payload = usage_stats_server.report_payload
1341 assert payload["schema_version"] == "0.1"
1342 assert payload["source"] == "OSS"
1343 assert payload["collect_timestamp_ms"] > 0
1344 assert len({k: v for k, v in payload.items() if v is not None}) == 3
1345
1346 """
1347 Verify the correct logs are printed.
1348 """
1349 session_dir = ray._private.worker.global_worker.node.address_info["session_dir"]
1350 session_path = Path(session_dir)
1351 log_dir_path = session_path / "logs"
1352
1353 paths = list(log_dir_path.iterdir())
1354
1355 contents = None
1356 for path in paths:
1357 if "dashboard.log" in str(path):
1358 with open(str(path), "r") as f:
1359 contents = f.readlines()
1360 break
1361 assert contents is not None
1362 assert any(["Usage reporting is disabled" in c for c in contents])
1363 assert all(["Usage report request failed" not in c for c in contents])
1364
1365
1366def test_usage_file_error_message(monkeypatch, ray_start_cluster, reset_usage_stats):

Callers

nothing calls this directly

Calls 8

wait_for_conditionFunction · 0.90
listFunction · 0.85
openFunction · 0.85
contextMethod · 0.45
add_nodeMethod · 0.45
initMethod · 0.45
sleepMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…