[SCB-2683] Modifying Invalid Fields in the Data Reported by the Dashboard (#3342)

diff --git a/dependencies/default/pom.xml b/dependencies/default/pom.xml
index 1789c9c..9981b15 100644
--- a/dependencies/default/pom.xml
+++ b/dependencies/default/pom.xml
@@ -427,8 +427,8 @@
             <artifactId>org.abego.treelayout.core</artifactId>
           </exclusion>
           <exclusion>
-              <groupId>com.google.inject.extensions</groupId>
-              <artifactId>guice-multibindings</artifactId>
+            <groupId>com.google.inject.extensions</groupId>
+            <artifactId>guice-multibindings</artifactId>
           </exclusion>
         </exclusions>
       </dependency>
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
index 15529eb..e919995 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/BootStrapProperties.java
@@ -227,16 +227,6 @@
     return readServiceInstanceExtendedClass(BootStrapProperties.configuration);
   }
 
-  public static String readServiceInstanceEnvironment(Configuration configuration) {
-    return readStringValue(configuration, CONFIG_SERVICE_INSTANCE_ENVIRONMENT,
-        OLD_CONFIG_SERVICE_INSTANCE_ENVIRONMENT,
-        DEFAULT_MICROSERVICE_INSTANCE_ENVIRONMENT);
-  }
-
-  public static String readServiceInstanceEnvironment() {
-    return readServiceInstanceEnvironment(BootStrapProperties.configuration);
-  }
-
   public static String readServiceInstanceInitialStatus(Configuration configuration) {
     return readStringValue(configuration, CONFIG_SERVICE_INSTANCE_INITIAL_STATUS,
         OLD_CONFIG_SERVICE_INSTANCE_INITIAL_STATUS,
diff --git a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/registry/MicroserviceInstance.java b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/registry/MicroserviceInstance.java
index 316221d..fdab707 100644
--- a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/registry/MicroserviceInstance.java
+++ b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/api/registry/MicroserviceInstance.java
@@ -53,12 +53,6 @@
 
   private HealthCheck healthCheck;
 
-  /**
-   * Will be abandoned, use Microservice Environment instead
-   */
-  @Deprecated
-  private String environment;
-
   private String stage;
 
   private DataCenterInfo dataCenterInfo;
@@ -149,14 +143,6 @@
     this.healthCheck = healthCheck;
   }
 
-  public String getEnvironment() {
-    return environment;
-  }
-
-  public void setEnvironment(String environment) {
-    this.environment = environment;
-  }
-
   @Deprecated
   public String getStage() {
     return stage;
@@ -193,8 +179,6 @@
     MicroserviceInstance microserviceInstance = new MicroserviceInstance();
     // default hard coded values
     microserviceInstance.setStage(DefinitionConst.DEFAULT_STAGE);
-    microserviceInstance
-        .setEnvironment(BootStrapProperties.readServiceInstanceEnvironment(configuration));
     microserviceInstance.setStatus(MicroserviceInstanceStatus
         .valueOf(BootStrapProperties.readServiceInstanceInitialStatus()));
     HealthCheck healthCheck = new HealthCheck();
diff --git a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/model/MonitorDataProvider.java b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/model/MonitorDataProvider.java
index bbcbe56..1dc5787 100644
--- a/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/model/MonitorDataProvider.java
+++ b/huawei-cloud/dashboard/src/main/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/model/MonitorDataProvider.java
@@ -49,7 +49,7 @@
     monitorData.setServiceId(microservice.getServiceId());
     monitorData.setInstance(microserviceInstance.getHostName());
     monitorData.setInstanceId(microserviceInstance.getInstanceId());
-    monitorData.setEnvironment(microserviceInstance.getEnvironment());
+    monitorData.setEnvironment(microservice.getEnvironment());
   }
 
   default void exactProcessInfo(MonitorData monitorData) {
diff --git a/huawei-cloud/dashboard/src/test/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MetricsMonitorDataProviderTest.java b/huawei-cloud/dashboard/src/test/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MetricsMonitorDataProviderTest.java
index c5411fe..3758bd4 100644
--- a/huawei-cloud/dashboard/src/test/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MetricsMonitorDataProviderTest.java
+++ b/huawei-cloud/dashboard/src/test/java/org/apache/servicecomb/huaweicloud/dashboard/monitor/MetricsMonitorDataProviderTest.java
@@ -16,6 +16,15 @@
  */
 package org.apache.servicecomb.huaweicloud.dashboard.monitor;
 
+import org.apache.commons.configuration.Configuration;
+import org.apache.servicecomb.config.ConfigUtil;
+import org.apache.servicecomb.huaweicloud.dashboard.monitor.model.MonitorDataProvider;
+import org.apache.servicecomb.registry.api.registry.Microservice;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.ServiceRegistry;
+import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
+import org.apache.servicecomb.serviceregistry.registry.ServiceRegistryFactory;
+import org.junit.Assert;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
@@ -27,4 +36,15 @@
     Assertions.assertFalse("2002".matches(MetricsMonitorDataProvider.CODE_SUCCESS));
     Assertions.assertFalse("400".matches(MetricsMonitorDataProvider.CODE_SUCCESS));
   }
+
+  @Test
+  public void testEnvironment() {
+    Configuration configuration = ConfigUtil.createLocalConfig();
+    ServiceRegistry serviceRegistry = ServiceRegistryFactory.create(ServiceRegistryConfig.INSTANCE, configuration);
+    Microservice microservice = serviceRegistry.getMicroservice();
+    MonitorDataProvider monitorDataProvider = new HealthMonitorDataProvider();
+    RegistryUtils.setServiceRegistry(serviceRegistry);
+    Assert.assertEquals(monitorDataProvider.getData().getEnvironment(), microservice.getEnvironment());
+    Assert.assertEquals("development", monitorDataProvider.getData().getEnvironment());
+  }
 }
diff --git a/huawei-cloud/dashboard/src/test/resources/microservice.yaml b/huawei-cloud/dashboard/src/test/resources/microservice.yaml
new file mode 100644
index 0000000..7af5033
--- /dev/null
+++ b/huawei-cloud/dashboard/src/test/resources/microservice.yaml
@@ -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.
+## ---------------------------------------------------------------------------
+# spring boot configurations
+server:
+  port: 9093  # should be same with servicecomb.rest.address to use web container
+
+# override common configurations in common module
+servicecomb-config-order: 10
+instance_description:
+  environment: production
+
+servicecomb:
+  service:
+    environment: development
+    application: demo-java-chassis-dashboard
+    name: test-dashboard
+    version: 0.0.1
+    registry:
+      address: http://127.0.0.1:30100
+      instance:
+        watch: false
+  kie:
+    serverUri: http://127.0.0.1:30110
+    customLabel: public
+
+  rest:
+    address: 0.0.0.0:9097 # should be same with server.port to use web container
\ No newline at end of file