From 38ac168e1112379fef7022a97fd78a644e3072f3 Mon Sep 17 00:00:00 2001 From: Dmitri Gekhtman <62982571+DmitriGekhtman@users.noreply.github.com> Date: Wed, 14 Sep 2022 16:11:48 -0400 Subject: [PATCH] [Telemetry] Inject env identifying KubeRay. #562 Signed-off-by: Dmitri Gekhtman This change has the KubeRay operator inject an env var identifying a Ray container as having been deployed using KubeRay. The purpose is to refine Ray usage stats collected by Ray's telemetry service (https://docs.ray.io/en/latest/cluster/usage-stats.html). See ray-project/ray#28490 --- ray-operator/controllers/ray/common/constant.go | 1 + ray-operator/controllers/ray/common/pod.go | 4 ++++ ray-operator/controllers/ray/common/pod_test.go | 2 ++ 3 files changed, 7 insertions(+) diff --git a/ray-operator/controllers/ray/common/constant.go b/ray-operator/controllers/ray/common/constant.go index 340726a29e..1ff054ba54 100644 --- a/ray-operator/controllers/ray/common/constant.go +++ b/ray-operator/controllers/ray/common/constant.go @@ -74,6 +74,7 @@ const ( RAY_SERVE_KV_TIMEOUT_S = "RAY_SERVE_KV_TIMEOUT_S" SERVE_DEPLOYMENT_HANDLE_IS_SYNC = "SERVE_DEPLOYMENT_HANDLE_IS_SYNC" SERVE_CONTROLLER_PIN_ON_NODE = "RAY_INTERNAL_SERVE_CONTROLLER_PIN_ON_NODE" + RAY_USAGE_STATS_KUBERAY_IN_USE = "RAY_USAGE_STATS_KUBERAY_IN_USE" // Ray core default configurations DefaultRedisPassword = "5241590000000000" diff --git a/ray-operator/controllers/ray/common/pod.go b/ray-operator/controllers/ray/common/pod.go index 4e928f626e..7cc6b4ebb8 100644 --- a/ray-operator/controllers/ray/common/pod.go +++ b/ray-operator/controllers/ray/common/pod.go @@ -588,6 +588,10 @@ func setContainerEnvVars(pod *v1.Pod, rayContainerIndex int, rayNodeType rayiov1 addressEnv := v1.EnvVar{Name: RAY_ADDRESS, Value: rayAddress} container.Env = append(container.Env, addressEnv) } + if !envVarExists(RAY_USAGE_STATS_KUBERAY_IN_USE, container.Env) { + usageEnv := v1.EnvVar{Name: RAY_USAGE_STATS_KUBERAY_IN_USE, Value: "1"} + container.Env = append(container.Env, usageEnv) + } if !envVarExists(REDIS_PASSWORD, container.Env) { // setting the REDIS_PASSWORD env var from the params port := v1.EnvVar{Name: REDIS_PASSWORD} diff --git a/ray-operator/controllers/ray/common/pod_test.go b/ray-operator/controllers/ray/common/pod_test.go index 5805c4d36c..fa1a470c71 100644 --- a/ray-operator/controllers/ray/common/pod_test.go +++ b/ray-operator/controllers/ray/common/pod_test.go @@ -311,6 +311,8 @@ func TestBuildPod(t *testing.T) { // Check RAY_ADDRESS env. checkPodEnv(t, pod, RAY_ADDRESS, "127.0.0.1:6379") + // Check usage stats env. + checkPodEnv(t, pod, RAY_USAGE_STATS_KUBERAY_IN_USE, "1") // Check labels. actualResult := pod.Labels[RayClusterLabelKey]