wy471x commented on code in PR #7966:
URL: https://github.com/apache/shenyu/pull/7966#discussion_r4343576100


##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/scale/monitor/observer/ScaleObserver.java:
##########
@@ -24,9 +24,11 @@
 import org.apache.shenyu.admin.scale.scaler.dynamic.ScaleAction;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
 
 import java.util.Objects;
 
+@Component

Review Comment:
   **Blocking:** Registering this bean activates metric-driven scaling on every 
Admin replica. `ScaleService.startDynamicTask()` still schedules 
`monitorMetrics()` per replica, so one evaluation will call `scaleByAction` 
once per Admin until #7964 is merged. Please make #7964 a hard merge dependency 
or gate this registration/scheduling on the scaling owner.



##########
shenyu-admin/src/test/java/org/apache/shenyu/admin/scale/monitor/subject/MetricsMonitorTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.shenyu.admin.scale.monitor.subject;
+
+import org.apache.shenyu.admin.model.entity.ScaleRuleDO;
+import org.apache.shenyu.admin.scale.collector.PrometheusMetricsProvider;
+import org.apache.shenyu.admin.scale.collector.provider.MetricData;
+import org.apache.shenyu.admin.scale.monitor.observer.Observer;
+import org.apache.shenyu.admin.scale.monitor.observer.ScaleObserver;
+import org.apache.shenyu.admin.scale.monitor.subject.cache.ScaleRuleCache;
+import org.apache.shenyu.admin.scale.scaler.KubernetesScaler;
+import org.apache.shenyu.admin.scale.scaler.dynamic.ScaleAction;
+import org.apache.shenyu.admin.scale.scaler.dynamic.ScaleRuleEvaluator;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for metric monitoring and scaling observer registration.
+ */
+public final class MetricsMonitorTest {
+
+    private static final String METRIC_NAME = "cpu_usage";
+
+    private PrometheusMetricsProvider metricsProvider;
+
+    private ScaleRuleCache scaleRuleCache;
+
+    private KubernetesScaler kubernetesScaler;
+
+    private MetricsMonitor metricsMonitor;
+
+    @BeforeEach
+    public void setUp() {
+        metricsProvider = mock(PrometheusMetricsProvider.class);
+        scaleRuleCache = mock(ScaleRuleCache.class);
+        kubernetesScaler = mock(KubernetesScaler.class);
+        final ScaleObserver scaleObserver = new 
ScaleObserver(kubernetesScaler, new ScaleRuleEvaluator());

Review Comment:
   **Blocking:** The test constructs and injects the observer itself, bypassing 
the production wiring that failed. Removing `@Component` from `ScaleObserver` 
would leave this suite green. Please add a context-level test that resolves 
`MetricsMonitor` and asserts the discovered `ScaleObserver` is invoked exactly 
once.



-- 
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