Copilot commented on code in PR #3714:
URL: https://github.com/apache/celeborn/pull/3714#discussion_r3332167971


##########
master/src/main/scala/org/apache/celeborn/service/deploy/master/MasterSource.scala:
##########
@@ -19,19 +19,29 @@ package org.apache.celeborn.service.deploy.master
 
 import org.apache.celeborn.common.CelebornConf
 import org.apache.celeborn.common.metrics.source.{AbstractSource, Role}
+import org.apache.celeborn.common.protocol.message.StatusCode
 
 class MasterSource(conf: CelebornConf) extends AbstractSource(conf, 
Role.MASTER) {
   override val sourceName = "master"
 
   import MasterSource._
+  RequestSlotsFailureStatuses.foreach { status =>
+    addCounter(REQUEST_SLOTS_FAILED_COUNT, Map(STATUS_LABEL -> status.name()))
+  }
   // add timers
   addTimer(OFFER_SLOTS_TIME)
   addTimer(UPDATE_RESOURCE_CONSUMPTION_TIME)
   // start cleaner
   startCleaner()
+
+  def incRequestSlotsFailed(status: StatusCode): Unit = {
+    incCounter(REQUEST_SLOTS_FAILED_COUNT, 1, Map(STATUS_LABEL -> 
status.name()))
+  }

Review Comment:
   `incRequestSlotsFailed` accepts any `StatusCode`, but the metric is intended 
to have a bounded `status` label (and the counters are only pre-registered for 
`SLOT_NOT_AVAILABLE` and `WORKER_EXCLUDED`). If another status is passed, 
`incCounter` will just log a warning and drop the increment, and it also risks 
violating the bounded-label intent if counters are later added for arbitrary 
statuses. Consider guarding so only the allowed statuses are recorded (and 
others are ignored).



##########
master/src/test/scala/org/apache/celeborn/service/deploy/master/MasterSourceSuite.scala:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.service.deploy.master
+
+import org.apache.celeborn.CelebornFunSuite
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.protocol.message.StatusCode
+
+class MasterSourceSuite extends CelebornFunSuite {
+
+  test("test request slots failed metrics") {
+    val conf = new CelebornConf()
+    conf.set(CelebornConf.METRICS_EXTRA_LABELS.key, "status=prod")
+    val source = new MasterSource(conf)
+
+    source.incRequestSlotsFailed(StatusCode.SLOT_NOT_AVAILABLE)
+    source.incRequestSlotsFailed(StatusCode.WORKER_EXCLUDED)
+
+    val metrics = source.getMetrics
+    assert(metrics.contains(
+      """metrics_RequestSlotsFailed_Count{instance="""))
+    assert(metrics.contains(

Review Comment:
   The test currently asserts `instance=""`, but `instance` is derived from 
`Utils.localHostName(conf)` and the master HTTP port, so it is 
environment-dependent and usually non-empty. This makes the test brittle across 
machines/CI environments. Use the instance label from the source when asserting 
the exported metric text.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to