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

Function test_usage_report_e2e

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

Test usage report works e2e with env vars.

(
    monkeypatch,
    ray_start_cluster,
    tmp_path,
    start_usage_stats_server,
    reset_usage_stats,
    gcs_storage_type,
)

Source from the content-addressed store, hash-verified

1113
1114
1115def test_usage_report_e2e(
1116 monkeypatch,
1117 ray_start_cluster,
1118 tmp_path,
1119 start_usage_stats_server,
1120 reset_usage_stats,
1121 gcs_storage_type,
1122):
1123 """
1124 Test usage report works e2e with env vars.
1125 """
1126 cluster_config_file_path = tmp_path / "ray_bootstrap_config.yaml"
1127 cluster_config_file_path.write_text(
1128 """
1129cluster_name: minimal
1130max_workers: 1
1131provider:
1132 type: aws
1133 region: us-west-2
1134 availability_zone: us-west-2a
1135"""
1136 )
1137 with patch.object(
1138 ray._private.utils, "get_current_node_cpu_model_name", return_value="TestCPU"
1139 ), monkeypatch.context() as m:
1140 m.setenv("HOME", str(tmp_path))
1141 m.setenv("RAY_USAGE_STATS_ENABLED", "1")
1142 m.setenv("RAY_USAGE_STATS_REPORT_URL", "http://127.0.0.1:8000")
1143 m.setenv("RAY_USAGE_STATS_REPORT_INTERVAL_S", "1")
1144 m.setenv("RAY_USAGE_STATS_EXTRA_TAGS", "extra_k1=extra_v1")
1145
1146 usage_stats_server = start_usage_stats_server
1147
1148 cluster = ray_start_cluster
1149 node = cluster.add_node(num_cpus=3)
1150
1151 ray_usage_lib.record_extra_usage_tag(ray_usage_lib.TagKey._TEST1, "extra_v2")
1152
1153 ray.init(address=cluster.address)
1154
1155 @ray.remote
1156 def f():
1157 pass
1158
1159 ray.get(f.remote())
1160
1161 ray_usage_lib.record_extra_usage_tag(ray_usage_lib.TagKey._TEST2, "extra_v3")
1162
1163 """
1164 Verify the usage stats are reported to the server.
1165 """
1166 print("Verifying usage stats report.")
1167 # Since the interval is 1 second, there must have been
1168 # more than 5 requests sent within 30 seconds.
1169 try:
1170 wait_for_condition(lambda: usage_stats_server.num_reports > 5, timeout=30)
1171 except Exception:
1172 print_dashboard_log()

Callers

nothing calls this directly

Calls 12

wait_for_conditionFunction · 0.90
printFunction · 0.85
print_dashboard_logFunction · 0.85
read_fileFunction · 0.85
get_session_dir_pathMethod · 0.80
file_existsFunction · 0.70
getMethod · 0.65
contextMethod · 0.45
add_nodeMethod · 0.45
initMethod · 0.45
remoteMethod · 0.45
hexMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…