This is an automated email from the ASF dual-hosted git repository.

zaynt4606 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git


The following commit(s) were added to refs/heads/main by this push:
     new 2f6e2d62e5 [CELEBORN-2564] Handle missing dynamic configuration query 
results and parameters
2f6e2d62e5 is described below

commit 2f6e2d62e55d6a72ee95a82f02d7e59667a39c2b
Author: huangxiaoping <[email protected]>
AuthorDate: Fri Nov 20 00:11:46 2026 +0800

    [CELEBORN-2564] Handle missing dynamic configuration query results and 
parameters
    
    ### What changes were proposed in this pull request?
    
    Return empty results when a tenant or tenant-user dynamic configuration is 
absent from the cache, for both the versioned JSON and legacy text endpoints. 
Also handle a missing tenant or name parameter in the versioned tenant-user 
query without throwing a null pointer exception.
    
    ### Why are the changes needed?
    
    For example, `GET /api/v1/conf/dynamic?level=TENANT&tenant=missing` 
currently wraps the null cache lookup result in a list and fails with HTTP 500. 
Likewise, a tenant-user query with only one of `tenant` and `name` can fail 
before it reaches the existing empty-result branch. Both cases return empty 
results after the fix; queries across all levels still return applicable system 
and tenant configurations.
    
    Jira: https://issues.apache.org/jira/browse/CELEBORN-2564
    
    ### Does this PR resolve a correctness bug?
    
    - [x] Yes
    
    ### Does this PR introduce _any_ user-facing change?
    
    - [x] Yes
    
    ### How was this patch tested?
    
    - `DynamicConfigQuerySuite`: real HTTP requests for missing and existing 
tenant/tenant-user configurations and unfiltered lists on both endpoints. The 
missing-entry test reproduced HTTP 500 before the fix.
    - `DynamicConfigIncompleteQuerySuite`: real HTTP requests for incomplete 
tenant-user parameters, across-level queries and complete or unfiltered 
tenant-user queries. The incomplete-parameter tests reproduced HTTP 500 before 
the fix.
    - `mvn -o -pl service -am spotless:check -q`
    
    Closes #3982 from huangxiaopingRD/fix-missing-dynamic-config-query.
    
    Authored-by: huangxiaoping <[email protected]>
    Signed-off-by: zhengtao <[email protected]>
    
    AI-Contributed/Feature: 0/10
    AI-Contributed/UT: 0/286
---
 .../celeborn/server/common/HttpService.scala       |   4 +-
 .../server/common/http/api/v1/ConfResource.scala   |   6 +-
 .../http/DynamicConfigIncompleteQuerySuite.scala   | 143 +++++++++++++++++++++
 .../common/http/DynamicConfigQuerySuite.scala      | 143 +++++++++++++++++++++
 4 files changed, 291 insertions(+), 5 deletions(-)

diff --git 
a/service/src/main/scala/org/apache/celeborn/server/common/HttpService.scala 
b/service/src/main/scala/org/apache/celeborn/server/common/HttpService.scala
index a7fe9fd335..6d1121e965 100644
--- a/service/src/main/scala/org/apache/celeborn/server/common/HttpService.scala
+++ b/service/src/main/scala/org/apache/celeborn/server/common/HttpService.scala
@@ -102,7 +102,7 @@ abstract class HttpService extends Service with Logging {
       if (tenant.isEmpty) {
         configService.listRawTenantConfigsFromCache().asScala
       } else {
-        List(configService.getRawTenantConfigFromCache(tenant))
+        Option(configService.getRawTenantConfigFromCache(tenant)).toSeq
       }
     tenantConfigs.sortBy(_.getTenantId).map { tenantConfig =>
       s"""
@@ -118,7 +118,7 @@ abstract class HttpService extends Service with Logging {
       if (tenant.isEmpty && name.isEmpty) {
         configService.listRawTenantUserConfigsFromCache().asScala
       } else if (tenant.nonEmpty && name.nonEmpty) {
-        List(configService.getRawTenantUserConfigFromCache(tenant, name))
+        Option(configService.getRawTenantUserConfigFromCache(tenant, 
name)).toSeq
       } else {
         List()
       }
diff --git 
a/service/src/main/scala/org/apache/celeborn/server/common/http/api/v1/ConfResource.scala
 
b/service/src/main/scala/org/apache/celeborn/server/common/http/api/v1/ConfResource.scala
index b8615054d6..5a26b2d66b 100644
--- 
a/service/src/main/scala/org/apache/celeborn/server/common/http/api/v1/ConfResource.scala
+++ 
b/service/src/main/scala/org/apache/celeborn/server/common/http/api/v1/ConfResource.scala
@@ -148,7 +148,7 @@ private[api] class ConfResource extends ApiRequestContext {
         if (StringUtils.isEmpty(tenant)) {
           configService.listRawTenantConfigsFromCache().asScala
         } else {
-          List(configService.getRawTenantConfigFromCache(tenant))
+          Option(configService.getRawTenantConfigFromCache(tenant)).toSeq
         }
       tenantConfigs.sortBy(_.getTenantId).map { tenantConfig =>
         new DynamicConfig()
@@ -162,8 +162,8 @@ private[api] class ConfResource extends ApiRequestContext {
       val tenantUserConfigs =
         if (StringUtils.isEmpty(tenant) && StringUtils.isEmpty(name)) {
           configService.listRawTenantUserConfigsFromCache().asScala
-        } else if (tenant.nonEmpty && name.nonEmpty) {
-          List(configService.getRawTenantUserConfigFromCache(tenant, name))
+        } else if (StringUtils.isNotEmpty(tenant) && 
StringUtils.isNotEmpty(name)) {
+          Option(configService.getRawTenantUserConfigFromCache(tenant, 
name)).toSeq
         } else {
           List()
         }
diff --git 
a/service/src/test/scala/org/apache/celeborn/server/common/http/DynamicConfigIncompleteQuerySuite.scala
 
b/service/src/test/scala/org/apache/celeborn/server/common/http/DynamicConfigIncompleteQuerySuite.scala
new file mode 100644
index 0000000000..c925c31318
--- /dev/null
+++ 
b/service/src/test/scala/org/apache/celeborn/server/common/http/DynamicConfigIncompleteQuerySuite.scala
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.celeborn.server.common.http
+
+import java.net.{HttpURLConnection, URL}
+
+import scala.collection.JavaConverters._
+import scala.io.Source
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.mockito.Mockito.{mock, when}
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.funsuite.AnyFunSuite
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.metrics.MetricsSystem
+import org.apache.celeborn.common.util.CelebornExitKind
+import org.apache.celeborn.server.common.HttpService
+import org.apache.celeborn.server.common.http.api.ApiRootResource
+import org.apache.celeborn.server.common.service.config.{ConfigService, 
SystemConfig, TenantConfig}
+
+class DynamicConfigIncompleteQuerySuite extends AnyFunSuite with 
BeforeAndAfterAll {
+  private val configService = mock(classOf[ConfigService])
+  private val httpService = new HttpService {
+    override def serviceName: String = "master"
+    override def conf: CelebornConf = new CelebornConf()
+    override def metricsSystem: MetricsSystem = null
+    override def configService: ConfigService = 
DynamicConfigIncompleteQuerySuite.this.configService
+    override def getWorkerInfo: String = ""
+    override def getShuffleList: String = ""
+    override def getApplicationList: String = ""
+  }
+  private val mapper = new ObjectMapper()
+  private var server: HttpServer = _
+
+  override def beforeAll(): Unit = {
+    super.beforeAll()
+    when(configService.getSystemConfigFromCache).thenReturn(new 
SystemConfig(new CelebornConf()))
+    val tenantConfig = new TenantConfig(
+      configService,
+      "tenantA",
+      null,
+      Map("tenant.key" -> "tenant.value").asJava)
+    val userConfig = new TenantConfig(
+      configService,
+      "tenantA",
+      "alice",
+      Map("user.key" -> "user.value").asJava)
+    
when(configService.getRawTenantConfigFromCache("tenantA")).thenReturn(tenantConfig)
+    when(configService.getRawTenantUserConfigFromCache("tenantA", "alice"))
+      .thenReturn(userConfig)
+    
when(configService.listRawTenantConfigsFromCache()).thenReturn(List(tenantConfig).asJava)
+    
when(configService.listRawTenantUserConfigsFromCache()).thenReturn(List(userConfig).asJava)
+    server = HttpServer(
+      "test",
+      "127.0.0.1",
+      0,
+      16,
+      1000,
+      10000,
+      false,
+      None,
+      None,
+      None,
+      None,
+      Seq.empty,
+      Seq.empty)
+    server.addHandler(ApiRootResource.getServletHandler(httpService))
+    server.start()
+  }
+
+  override def afterAll(): Unit = {
+    if (server != null) {
+      server.stop(CelebornExitKind.EXIT_IMMEDIATELY)
+    }
+    super.afterAll()
+  }
+
+  private def get(path: String): (Int, String) = {
+    val connection = new URL(s"http://${server.getServerUri}/$path";)
+      .openConnection().asInstanceOf[HttpURLConnection]
+    try {
+      val status = connection.getResponseCode
+      val stream = if (status < 400) connection.getInputStream else 
connection.getErrorStream
+      val source = Source.fromInputStream(stream, "UTF-8")
+      try {
+        (status, source.mkString)
+      } finally {
+        source.close()
+      }
+    } finally {
+      connection.disconnect()
+    }
+  }
+
+  test("tenant user queries with one missing parameter return no configs") {
+    Seq(
+      "level=TENANT_USER&tenant=tenantA",
+      "level=TENANT_USER&name=alice",
+      "level=TENANT_USER&tenant=tenantA&name=",
+      "level=TENANT_USER&tenant=&name=alice").foreach { query =>
+      val (status, body) = get(s"api/v1/conf/dynamic?$query")
+      assert(status == 200, body)
+      assert(mapper.readTree(body).path("configs").size() == 0)
+    }
+  }
+
+  test("queries across all levels retain system and tenant results with only a 
tenant") {
+    val (status, body) = get("api/v1/conf/dynamic?tenant=tenantA")
+    assert(status == 200, body)
+    val configs = mapper.readTree(body).path("configs")
+    assert(configs.size() == 2)
+    assert(configs.get(0).path("level").asText() == "SYSTEM")
+    assert(configs.get(1).path("level").asText() == "TENANT")
+    assert(configs.get(1).path("configs").get(0).path("name").asText() == 
"tenant.key")
+  }
+
+  test("tenant user queries with no parameters or both parameters still work") 
{
+    Seq("level=TENANT_USER", "level=TENANT_USER&tenant=tenantA&name=alice")
+      .foreach { query =>
+        val (status, body) = get(s"api/v1/conf/dynamic?$query")
+        assert(status == 200, body)
+        val configs = mapper.readTree(body).path("configs")
+        assert(configs.size() == 1)
+        assert(configs.get(0).path("configs").get(0).path("name").asText() == 
"user.key")
+      }
+  }
+}
diff --git 
a/service/src/test/scala/org/apache/celeborn/server/common/http/DynamicConfigQuerySuite.scala
 
b/service/src/test/scala/org/apache/celeborn/server/common/http/DynamicConfigQuerySuite.scala
new file mode 100644
index 0000000000..ffc21b9b6d
--- /dev/null
+++ 
b/service/src/test/scala/org/apache/celeborn/server/common/http/DynamicConfigQuerySuite.scala
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.celeborn.server.common.http
+
+import java.net.{HttpURLConnection, URL}
+
+import scala.collection.JavaConverters._
+import scala.io.Source
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.mockito.Mockito.{mock, when}
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.funsuite.AnyFunSuite
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.metrics.MetricsSystem
+import org.apache.celeborn.common.util.CelebornExitKind
+import org.apache.celeborn.server.common.HttpService
+import org.apache.celeborn.server.common.http.api.ApiRootResource
+import org.apache.celeborn.server.common.service.config.{ConfigService, 
TenantConfig}
+
+class DynamicConfigQuerySuite extends AnyFunSuite with BeforeAndAfterAll {
+  private val configService = mock(classOf[ConfigService])
+  private val httpService = new HttpService {
+    override def serviceName: String = "master"
+    override def conf: CelebornConf = new CelebornConf()
+    override def metricsSystem: MetricsSystem = null
+    override def configService: ConfigService = 
DynamicConfigQuerySuite.this.configService
+    override def getWorkerInfo: String = ""
+    override def getShuffleList: String = ""
+    override def getApplicationList: String = ""
+  }
+  private val mapper = new ObjectMapper()
+  private var server: HttpServer = _
+
+  override def beforeAll(): Unit = {
+    super.beforeAll()
+    val tenantConfig = new TenantConfig(
+      configService,
+      "tenantA",
+      null,
+      Map("tenant.key" -> "tenant.value").asJava)
+    val userConfig = new TenantConfig(
+      configService,
+      "tenantA",
+      "alice",
+      Map("user.key" -> "user.value").asJava)
+    
when(configService.getRawTenantConfigFromCache("tenantA")).thenReturn(tenantConfig)
+    when(configService.getRawTenantUserConfigFromCache("tenantA", "alice"))
+      .thenReturn(userConfig)
+    
when(configService.listRawTenantConfigsFromCache()).thenReturn(List(tenantConfig).asJava)
+    
when(configService.listRawTenantUserConfigsFromCache()).thenReturn(List(userConfig).asJava)
+    server = HttpServer(
+      "test",
+      "127.0.0.1",
+      0,
+      16,
+      1000,
+      10000,
+      false,
+      None,
+      None,
+      None,
+      None,
+      Seq.empty,
+      Seq.empty)
+    server.addHandler(ApiRootResource.getServletHandler(httpService))
+    server.start()
+  }
+
+  override def afterAll(): Unit = {
+    if (server != null) {
+      server.stop(CelebornExitKind.EXIT_IMMEDIATELY)
+    }
+    super.afterAll()
+  }
+
+  private def get(path: String): (Int, String) = {
+    val connection = new URL(s"http://${server.getServerUri}/$path";)
+      .openConnection().asInstanceOf[HttpURLConnection]
+    try {
+      val status = connection.getResponseCode
+      val stream = if (status < 400) connection.getInputStream else 
connection.getErrorStream
+      val source = Source.fromInputStream(stream, "UTF-8")
+      try {
+        (status, source.mkString)
+      } finally {
+        source.close()
+      }
+    } finally {
+      connection.disconnect()
+    }
+  }
+
+  test("dynamic configuration queries return empty results for missing 
entries") {
+    Seq(
+      "level=TENANT&tenant=missing",
+      "level=TENANT_USER&tenant=tenantA&name=missing").foreach { query =>
+      val (status, body) = get(s"api/v1/conf/dynamic?$query")
+      assert(status == 200, body)
+      assert(mapper.readTree(body).path("configs").isArray)
+      assert(mapper.readTree(body).path("configs").size() == 0)
+
+      val (legacyStatus, legacyBody) = get(s"listDynamicConfigs?$query")
+      assert(legacyStatus == 200, legacyBody)
+      assert(!legacyBody.contains("Tenant:"))
+    }
+  }
+
+  test("dynamic configuration queries still return existing and listed 
entries") {
+    Seq(
+      ("level=TENANT&tenant=tenantA", "tenant.key", "tenant.value"),
+      ("level=TENANT_USER&tenant=tenantA&name=alice", "user.key", 
"user.value"),
+      ("level=TENANT", "tenant.key", "tenant.value"),
+      ("level=TENANT_USER", "user.key", "user.value")).foreach { case (query, 
key, value) =>
+      val (status, body) = get(s"api/v1/conf/dynamic?$query")
+      assert(status == 200, body)
+      val configs = mapper.readTree(body).path("configs")
+      assert(configs.size() == 1)
+      assert(configs.get(0).path("configs").get(0).path("name").asText() == 
key)
+      assert(configs.get(0).path("configs").get(0).path("value").asText() == 
value)
+
+      val (legacyStatus, legacyBody) = get(s"listDynamicConfigs?$query")
+      assert(legacyStatus == 200, legacyBody)
+      assert(legacyBody.contains(key) && legacyBody.contains(value))
+    }
+  }
+}

Reply via email to