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

Function check_library_usage_telemetry

python/ray/_common/test_utils.py:225–268  ·  view source on GitHub ↗

Helper for writing tests to validate library usage telemetry. `use_lib_fn` is a callable that will be called from the provided callsite. After calling it, the telemetry data to export will be validated against expected_library_usages and expected_extra_usage_tags.

(
    use_lib_fn: Callable[[], None],
    *,
    callsite: TelemetryCallsite,
    expected_library_usages: List[Set[str]],
    expected_extra_usage_tags: Optional[Dict[str, str]] = None,
)

Source from the content-addressed store, hash-verified

223
224
225def check_library_usage_telemetry(
226 use_lib_fn: Callable[[], None],
227 *,
228 callsite: TelemetryCallsite,
229 expected_library_usages: List[Set[str]],
230 expected_extra_usage_tags: Optional[Dict[str, str]] = None,
231):
232 """Helper for writing tests to validate library usage telemetry.
233
234 `use_lib_fn` is a callable that will be called from the provided callsite.
235 After calling it, the telemetry data to export will be validated against
236 expected_library_usages and expected_extra_usage_tags.
237 """
238 assert len(_get_library_usages()) == 0, _get_library_usages()
239
240 if callsite == TelemetryCallsite.DRIVER:
241 use_lib_fn()
242 elif callsite == TelemetryCallsite.ACTOR:
243
244 @ray.remote
245 class A:
246 def __init__(self):
247 use_lib_fn()
248
249 a = A.remote()
250 ray.get(a.__ray_ready__.remote())
251 elif callsite == TelemetryCallsite.TASK:
252
253 @ray.remote
254 def f():
255 use_lib_fn()
256
257 ray.get(f.remote())
258 else:
259 assert False, f"Unrecognized callsite: {callsite}"
260
261 library_usages = _get_library_usages()
262 extra_usage_tags = _get_extra_usage_tags()
263
264 assert library_usages in expected_library_usages, library_usages
265 if expected_extra_usage_tags:
266 assert all(
267 [extra_usage_tags[k] == v for k, v in expected_extra_usage_tags.items()]
268 ), extra_usage_tags
269
270
271class FakeTimer:

Callers 13

test_not_used_on_importFunction · 0.90
test_used_on_serve_startFunction · 0.90
test_used_on_serve_runFunction · 0.90
test_not_used_on_importFunction · 0.90
test_used_on_data_rangeFunction · 0.90
test_not_used_on_importFunction · 0.90
test_used_on_tuner_fitFunction · 0.90
test_not_used_on_importFunction · 0.90
test_used_on_trainer_fitFunction · 0.90
test_not_used_on_importFunction · 0.90
test_used_on_train_fitFunction · 0.90
test_not_used_on_importFunction · 0.90

Calls 5

_get_library_usagesFunction · 0.85
_get_extra_usage_tagsFunction · 0.85
getMethod · 0.65
remoteMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…