Skip to content

Commit 2f702a3

Browse files
committed
[KYUUBI #6884][FOLLOWUP] Fix internal kyuubi instance ping failure
### Why are the changes needed? To fix failure: ``` :2025-12-07 13:40:40.747 ERROR [KyuubiRestFrontendService-134] org.apache.kyuubi.server.api.v1.InternalRestClient: (Ping to internal Kyuubi instance:{} failed,kyuubistaging-1.kyuubistaginghl.kyuubi-prod.svc.166.tess.io:10011,java.lang.IllegalArgumentException: requirement failed: The auth user shall be not null) ``` In this PR, it will use the authUser and client ipAddress for internal ping. ### How was this patch tested? Integration testing. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #7264 from turboFei/ping_able. Closes #6884 198dc61 [Wang, Fei] debug Authored-by: Wang, Fei <fwang12@ebay.com> Signed-off-by: Wang, Fei <fwang12@ebay.com>
1 parent 572cef8 commit 2f702a3

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/BaseRestApi.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.kyuubi.client;
1919

20+
import java.util.Collections;
21+
import java.util.Map;
2022
import org.apache.kyuubi.client.api.v1.dto.VersionInfo;
2123
import org.slf4j.Logger;
2224
import org.slf4j.LoggerFactory;
@@ -32,7 +34,11 @@ public BaseRestApi(KyuubiRestClient client) {
3234
}
3335

3436
public String ping() {
35-
return this.getClient().get("ping", null, client.getAuthHeader());
37+
return ping(Collections.emptyMap());
38+
}
39+
40+
public String ping(Map<String, String> headers) {
41+
return this.getClient().get("ping", null, client.getAuthHeader(), headers);
3642
}
3743

3844
public VersionInfo getVersionInfo() {

kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/BatchesResource.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ private[v1] class BatchesResource extends ApiRequestContext with Logging {
598598
throw new IllegalStateException(s"KyuubiInstance is alive: $kyuubiInstance")
599599
}
600600
val internalRestClient = getInternalRestClient(kyuubiInstance)
601-
if (!Utils.isTesting && internalRestClient.pingAble()) {
601+
if (!Utils.isTesting && internalRestClient.pingAble(userName, ipAddress)) {
602602
throw new IllegalStateException(s"KyuubiInstance is alive: $kyuubiInstance")
603603
}
604604
try {

kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/InternalRestClient.scala

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ package org.apache.kyuubi.server.api.v1
2020
import java.util.Base64
2121

2222
import scala.collection.JavaConverters._
23-
import scala.util.Try
23+
import scala.util.{Failure, Success, Try}
2424

25+
import org.apache.kyuubi.Logging
2526
import org.apache.kyuubi.client.{BaseRestApi, BatchRestApi, KyuubiRestClient}
2627
import org.apache.kyuubi.client.api.v1.dto.{Batch, CloseBatchResponse, OperationLog}
2728
import org.apache.kyuubi.client.auth.AuthHeaderGenerator
@@ -46,7 +47,7 @@ class InternalRestClient(
4647
connectTimeout: Int,
4748
securityEnabled: Boolean,
4849
requestMaxAttempts: Int,
49-
requestAttemptWait: Int) {
50+
requestAttemptWait: Int) extends Logging {
5051
if (securityEnabled) {
5152
require(
5253
InternalSecurityAccessor.get() != null,
@@ -56,7 +57,16 @@ class InternalRestClient(
5657
private val internalBatchRestApi = new BatchRestApi(initKyuubiRestClient())
5758
private val internalBaseRestApi = new BaseRestApi(initKyuubiRestClient())
5859

59-
def pingAble(): Boolean = Try(internalBaseRestApi.ping()).isSuccess
60+
def pingAble(user: String, clientIp: String): Boolean = withAuthUser(user) {
61+
Try {
62+
internalBaseRestApi.ping(Map(proxyClientIpHeader -> clientIp).asJava)
63+
} match {
64+
case Success(_) => true
65+
case Failure(e) =>
66+
error(s"Ping to Kyuubi instance $kyuubiInstance failed", e)
67+
false
68+
}
69+
}
6070

6171
def getBatch(user: String, clientIp: String, batchId: String): Batch = {
6272
withAuthUser(user) {

0 commit comments

Comments
 (0)