You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ki...@apache.org on 2020/06/12 14:46:10 UTC
[shardingsphere] branch master updated: Init MetricsConfiguration
into ConfigCenter. (#6018)
This is an automated email from the ASF dual-hosted git repository.
kimmking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 7c02d59 Init MetricsConfiguration into ConfigCenter. (#6018)
7c02d59 is described below
commit 7c02d596b4f2284a04cf2a88627c056084625e4f
Author: xiaoyu <54...@qq.com>
AuthorDate: Fri Jun 12 22:45:55 2020 +0800
Init MetricsConfiguration into ConfigCenter. (#6018)
* Init MetricsConfiguration into ConfigCenter.
* Init MetricsConfiguration into ConfigCenter.
* Init MetricsConfiguration into ConfigCenter.
---
.../swapper/MetricsConfigurationYamlSwapper.java | 2 +-
.../metrics/facade/MetricsTrackerFacade.java | 9 ++++
.../facade/handler/MetricsTrackerHandler.java | 3 +-
.../metrics/facade/MetricsTrackerFacadeTest.java | 6 +++
.../event/MetricsConfigurationChangedEvent.java | 32 +++++++++++
.../core/configcenter/ConfigCenter.java | 28 ++++++++++
.../ConfigurationChangedListenerManager.java | 4 ++
.../MetricsConfigurationChangedListener.java | 43 +++++++++++++++
.../core/configcenter/ConfigCenterTest.java | 17 ++++++
.../MetricsConfigurationChangedListenerTest.java | 62 ++++++++++++++++++++++
.../pom.xml | 6 +++
.../core/facade/ShardingOrchestrationFacade.java | 10 ++++
.../facade/ShardingOrchestrationFacadeTest.java | 8 +++
.../pom.xml | 5 ++
.../core/schema/OrchestrationSchemaContexts.java | 14 +++++
.../org/apache/shardingsphere/proxy/Bootstrap.java | 15 +++---
16 files changed, 256 insertions(+), 8 deletions(-)
diff --git a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-configuration/src/main/java/org/apache/shardingsphere/metrics/configuration/swapper/MetricsConfigurationYamlSwapper.java b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-configuration/src/main/java/org/apache/shardingsphere/metrics/configuration/swapper/MetricsConfigurationYamlSwapper.java
index e68dce5..0f3dc85 100644
--- a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-configuration/src/main/java/org/apache/shardingsphere/metrics/configuration/swapper/MetricsConfigurationYamlSwapper.java
+++ b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-configuration/src/main/java/org/apache/shardingsphere/metrics/configuration/swapper/MetricsConfigurationYamlSwapper.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.metrics.configuration.swapper;
+import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
import org.apache.shardingsphere.metrics.configuration.yaml.YamlMetricsConfiguration;
-import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
/**
* Metrics configuration YAML swapper.
diff --git a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
index bd2db68..34936a4 100644
--- a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
+++ b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
@@ -167,6 +167,15 @@ public final class MetricsTrackerFacade {
}
}
+ /**
+ * Stop to metrics.
+ */
+ public void stop() {
+ enabled = false;
+ metricsTrackerManager.stop();
+ MetricsTrackerHandler.getInstance().close();
+ }
+
private void loadMetricsManager() {
for (MetricsTrackerManager each : ServiceLoader.load(MetricsTrackerManager.class)) {
if (METRICS_MAP.containsKey(each.getType())) {
diff --git a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/handler/MetricsTrackerHandler.java b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/handler/MetricsTrackerHandler.java
index 2dd10ea..0c81ad2 100644
--- a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/handler/MetricsTrackerHandler.java
+++ b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/handler/MetricsTrackerHandler.java
@@ -78,7 +78,7 @@ public final class MetricsTrackerHandler {
public void init(final boolean async, final int threadCount, final MetricsTrackerManager metricsTrackerManager) {
this.async = async;
this.metricsTrackerManager = metricsTrackerManager;
- if (async) {
+ if (this.async) {
executorService = new MetricsThreadPoolExecutor(NAME_FORMAT, threadCount, QUEUE_SIZE);
}
}
@@ -193,6 +193,7 @@ public final class MetricsTrackerHandler {
* Executor service close.
*/
public void close() {
+ async = false;
if (null != executorService && !executorService.isShutdown()) {
executorService.shutdown();
}
diff --git a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/test/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacadeTest.java b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/test/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacadeTest.java
index 48cc98b..f7d7417 100644
--- a/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/test/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacadeTest.java
+++ b/shardingsphere-control-panel/shardingsphere-metrics/shardingsphere-metrics-facade/src/test/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacadeTest.java
@@ -104,5 +104,11 @@ public final class MetricsTrackerFacadeTest {
Optional<SummaryMetricsTrackerDelegate> empty = metricsTrackerFacade.summaryStartTimer("request");
assertThat(empty, is(Optional.empty()));
}
+
+ @Test
+ public void testStop() {
+ metricsTrackerFacade.stop();
+ assertThat(metricsTrackerFacade.isEnabled(), is(false));
+ }
}
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/MetricsConfigurationChangedEvent.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/MetricsConfigurationChangedEvent.java
new file mode 100644
index 0000000..c92f415
--- /dev/null
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-common/src/main/java/org/apache/shardingsphere/orchestration/core/common/event/MetricsConfigurationChangedEvent.java
@@ -0,0 +1,32 @@
+/*
+ * 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.shardingsphere.orchestration.core.common.event;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+
+/**
+ * Metrics configuration changed event.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class MetricsConfigurationChangedEvent implements ShardingOrchestrationEvent {
+
+ private final MetricsConfiguration metricsConfiguration;
+}
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenter.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenter.java
index 9db13ea..4990999 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenter.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenter.java
@@ -23,6 +23,9 @@ import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+import org.apache.shardingsphere.metrics.configuration.swapper.MetricsConfigurationYamlSwapper;
+import org.apache.shardingsphere.metrics.configuration.yaml.YamlMetricsConfiguration;
import org.apache.shardingsphere.orchestration.center.ConfigCenterRepository;
import org.apache.shardingsphere.orchestration.core.configuration.DataSourceConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration;
@@ -145,6 +148,22 @@ public final class ConfigCenter {
return !Strings.isNullOrEmpty(repository.get(node.getRulePath(shardingSchemaName)));
}
+ /**
+ * Persist metrics configuration.
+ *
+ * @param metricsConfiguration metrics configuration.
+ * @param isOverwrite is overwrite registry center's configuration
+ */
+ public void persistMetricsConfiguration(final MetricsConfiguration metricsConfiguration, final boolean isOverwrite) {
+ if (null != metricsConfiguration && (isOverwrite || !hasMetricsConfiguration())) {
+ repository.persist(node.getMetricsPath(), YamlEngine.marshal(new MetricsConfigurationYamlSwapper().swap(metricsConfiguration)));
+ }
+ }
+
+ private boolean hasMetricsConfiguration() {
+ return !Strings.isNullOrEmpty(repository.get(node.getMetricsPath()));
+ }
+
private void persistAuthentication(final Authentication authentication, final boolean isOverwrite) {
if (null != authentication && (isOverwrite || !hasAuthentication())) {
repository.persist(node.getAuthenticationPath(), YamlEngine.marshal(new AuthenticationYamlSwapper().swap(authentication)));
@@ -205,6 +224,15 @@ public final class ConfigCenter {
}
/**
+ * Load metrics configuration.
+ *
+ * @return metrics configuration
+ */
+ public MetricsConfiguration loadMetricsConfiguration() {
+ return new MetricsConfigurationYamlSwapper().swap(YamlEngine.unmarshal(repository.get(node.getMetricsPath()), YamlMetricsConfiguration.class));
+ }
+
+ /**
* Load authentication.
*
* @return authentication
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/ConfigurationChangedListenerManager.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/listen [...]
index 3f17634..9befa52 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/ConfigurationChangedListenerManager.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/ConfigurationChangedListenerManager.java
@@ -33,10 +33,13 @@ public final class ConfigurationChangedListenerManager {
private final AuthenticationChangedListener authenticationChangedListener;
+ private final MetricsConfigurationChangedListener metricsConfigurationChangedListener;
+
public ConfigurationChangedListenerManager(final String name, final ConfigCenterRepository configCenterRepository, final Collection<String> shardingSchemaNames) {
schemaChangedListener = new SchemaChangedListener(name, configCenterRepository, shardingSchemaNames);
propertiesChangedListener = new PropertiesChangedListener(name, configCenterRepository);
authenticationChangedListener = new AuthenticationChangedListener(name, configCenterRepository);
+ metricsConfigurationChangedListener = new MetricsConfigurationChangedListener(name, configCenterRepository);
}
/**
@@ -46,5 +49,6 @@ public final class ConfigurationChangedListenerManager {
schemaChangedListener.watch(ChangedType.UPDATED, ChangedType.DELETED);
propertiesChangedListener.watch(ChangedType.UPDATED);
authenticationChangedListener.watch(ChangedType.UPDATED);
+ metricsConfigurationChangedListener.watch(ChangedType.UPDATED);
}
}
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/MetricsConfigurationChangedListener.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/listen [...]
new file mode 100644
index 0000000..b5546c8
--- /dev/null
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/MetricsConfigurationChangedListener.java
@@ -0,0 +1,43 @@
+/*
+ * 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.shardingsphere.orchestration.core.configcenter.listener;
+
+import java.util.Collections;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
+import org.apache.shardingsphere.metrics.configuration.swapper.MetricsConfigurationYamlSwapper;
+import org.apache.shardingsphere.metrics.configuration.yaml.YamlMetricsConfiguration;
+import org.apache.shardingsphere.orchestration.center.ConfigCenterRepository;
+import org.apache.shardingsphere.orchestration.center.listener.DataChangedEvent;
+import org.apache.shardingsphere.orchestration.core.common.event.MetricsConfigurationChangedEvent;
+import org.apache.shardingsphere.orchestration.core.common.listener.PostShardingCenterRepositoryEventListener;
+import org.apache.shardingsphere.orchestration.core.configcenter.ConfigCenterNode;
+
+/**
+ * Metrics configuration changed listener.
+ */
+public final class MetricsConfigurationChangedListener extends PostShardingCenterRepositoryEventListener {
+
+ public MetricsConfigurationChangedListener(final String name, final ConfigCenterRepository configCenterRepository) {
+ super(configCenterRepository, Collections.singletonList(new ConfigCenterNode(name).getMetricsPath()));
+ }
+
+ @Override
+ protected MetricsConfigurationChangedEvent createShardingOrchestrationEvent(final DataChangedEvent event) {
+ return new MetricsConfigurationChangedEvent(new MetricsConfigurationYamlSwapper().swap(YamlEngine.unmarshal(event.getValue(), YamlMetricsConfiguration.class)));
+ }
+}
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java
index b8841dc..1fd5068 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenterTest.java
@@ -21,6 +21,7 @@ import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.algorithm.EncryptAlgorithmConfiguration;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
import org.apache.shardingsphere.orchestration.center.ConfigCenterRepository;
import org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
@@ -182,6 +183,11 @@ public final class ConfigCenterTest {
+ " authorizedSchemas: sharding_db,ms_db\n"
+ " password: root2\n";
+ private static final String METRICS_YAML = ""
+ + " name: prometheus\n"
+ + " host: 127.0.0.1\n"
+ + " port: 9190\n";
+
private static final String PROPS_YAML = "sql.show: false\n";
private static final String DATA_SOURCE_YAML_WITH_CONNECTION_INIT_SQLS = ""
@@ -525,6 +531,17 @@ public final class ConfigCenterTest {
}
@Test
+ public void assertLoadMetricsConfiguration() {
+ when(configCenterRepository.get("/test/config/metrics")).thenReturn(METRICS_YAML);
+ ConfigCenter configurationService = new ConfigCenter("test", configCenterRepository);
+ MetricsConfiguration actual = configurationService.loadMetricsConfiguration();
+ assertThat(actual.getMetricsName(), is("prometheus"));
+ assertThat(actual.getPort(), is(9190));
+ assertThat(actual.getHost(), is("127.0.0.1"));
+ assertThat(actual.getAsync(), is(true));
+ }
+
+ @Test
public void assertLoadProperties() {
when(configCenterRepository.get("/test/config/properties")).thenReturn(PROPS_YAML);
ConfigCenter configurationService = new ConfigCenter("test", configCenterRepository);
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/MetricsConfigurationChangedListenerTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/li [...]
new file mode 100644
index 0000000..d3f3be5
--- /dev/null
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/MetricsConfigurationChangedListenerTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.shardingsphere.orchestration.core.configcenter.listener;
+
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+import org.apache.shardingsphere.orchestration.center.ConfigCenterRepository;
+import org.apache.shardingsphere.orchestration.center.listener.DataChangedEvent;
+import org.apache.shardingsphere.orchestration.core.common.event.MetricsConfigurationChangedEvent;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class MetricsConfigurationChangedListenerTest {
+
+ private static final String METRICS_YAML = ""
+ + " name: prometheus\n"
+ + " host: 127.0.0.1\n"
+ + " port: 9190\n";
+
+ @Mock
+ private ConfigCenterRepository configCenterRepository;
+
+ private MetricsConfigurationChangedListener metricsConfigurationChangedListener;
+
+ @Before
+ public void setUp() {
+ metricsConfigurationChangedListener = new MetricsConfigurationChangedListener("test", configCenterRepository);
+ }
+
+ @Test
+ public void assertCreateShardingOrchestrationEvent() {
+ MetricsConfigurationChangedEvent event = metricsConfigurationChangedListener.createShardingOrchestrationEvent(new DataChangedEvent("test", METRICS_YAML, DataChangedEvent.ChangedType.UPDATED));
+ MetricsConfiguration actual = event.getMetricsConfiguration();
+ assertThat(actual, notNullValue());
+ assertThat(actual.getMetricsName(), is("prometheus"));
+ assertThat(actual.getPort(), is(9190));
+ assertThat(actual.getHost(), is("127.0.0.1"));
+ assertThat(actual.getAsync(), is(true));
+ }
+}
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configuration/pom.xml b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configuration/pom.xml
index c047a7b..54af448 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configuration/pom.xml
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-configuration/pom.xml
@@ -37,5 +37,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-metrics-configuration</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/main/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacade.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/main/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacade.java
index b216e12..62c18c5 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/main/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacade.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/main/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacade.java
@@ -22,6 +22,7 @@ import com.google.common.base.Splitter;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.auth.Authentication;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
import org.apache.shardingsphere.orchestration.center.ConfigCenterRepository;
import org.apache.shardingsphere.orchestration.center.RegistryCenterRepository;
import org.apache.shardingsphere.orchestration.center.config.CenterConfiguration;
@@ -137,6 +138,15 @@ public final class ShardingOrchestrationFacade implements AutoCloseable {
listenerManager.initListeners();
}
+ /**
+ * Init metrics configuration to config center.
+ *
+ * @param metricsConfiguration metrics configuration.
+ */
+ public void initMetricsConfiguration(final MetricsConfiguration metricsConfiguration) {
+ configCenter.persistMetricsConfiguration(metricsConfiguration, isOverwrite);
+ }
+
@Override
public void close() {
try {
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/test/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacadeTest.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/test/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacadeTest.java
index 5c3f07a..d36dbb2 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/test/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacadeTest.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-facade/src/test/java/org/apache/shardingsphere/orchestration/core/facade/ShardingOrchestrationFacadeTest.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.orchestration.core.facade;
import org.apache.shardingsphere.infra.auth.Authentication;
import org.apache.shardingsphere.infra.auth.ProxyUser;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
import org.apache.shardingsphere.orchestration.center.RegistryCenterRepository;
import org.apache.shardingsphere.orchestration.center.config.CenterConfiguration;
import org.apache.shardingsphere.orchestration.center.config.OrchestrationConfiguration;
@@ -106,6 +107,13 @@ public final class ShardingOrchestrationFacadeTest {
}
@Test
+ public void assertInitMetricsConfiguration() {
+ MetricsConfiguration metricsConfiguration = new MetricsConfiguration("fixture", null, null, false, 8, null);
+ shardingOrchestrationFacade.initMetricsConfiguration(metricsConfiguration);
+ verify(configCenter).persistMetricsConfiguration(metricsConfiguration, false);
+ }
+
+ @Test
public void assertInitWithoutParameters() {
shardingOrchestrationFacade.init();
verify(registryCenter).persistInstanceOnline();
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/pom.xml b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/pom.xml
index 461d70c..5f810dc 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/pom.xml
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/pom.xml
@@ -49,5 +49,10 @@
<artifactId>shardingsphere-cluster-facade</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-metrics-facade</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java
index e4f981a..a5bc62e 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java
@@ -42,8 +42,10 @@ import org.apache.shardingsphere.kernel.context.SchemaContextsAware;
import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.metrics.facade.MetricsTrackerFacade;
import org.apache.shardingsphere.orchestration.core.common.event.AuthenticationChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.event.DataSourceChangedEvent;
+import org.apache.shardingsphere.orchestration.core.common.event.MetricsConfigurationChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.event.PropertiesChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.event.RuleConfigurationsChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.event.SchemaAddedEvent;
@@ -156,6 +158,18 @@ public abstract class OrchestrationSchemaContexts implements SchemaContextsAware
}
/**
+ * Renew metrics configuration.
+ *
+ * @param event metrics configuration changed event
+ */
+ @Subscribe
+ public synchronized void renew(final MetricsConfigurationChangedEvent event) {
+ MetricsTrackerFacade.getInstance().stop();
+ MetricsTrackerFacade.getInstance().init(event.getMetricsConfiguration());
+ }
+
+
+ /**
* Renew meta data of the schema.
*
* @param event meta data changed event.
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
index c16f975..a7c46b6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
@@ -39,6 +39,7 @@ import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
import org.apache.shardingsphere.kernel.context.SchemaContextsAware;
import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
import org.apache.shardingsphere.metrics.configuration.swapper.MetricsConfigurationYamlSwapper;
import org.apache.shardingsphere.metrics.configuration.yaml.YamlMetricsConfiguration;
import org.apache.shardingsphere.metrics.facade.MetricsTrackerFacade;
@@ -123,7 +124,7 @@ public final class Bootstrap {
Authentication authentication = new AuthenticationYamlSwapper().swap(yamlAuthenticationConfig);
Map<String, Map<String, DataSourceParameter>> schemaDataSources = getDataSourceParametersMap(ruleConfigs);
Map<String, Collection<RuleConfiguration>> schemaRules = getRuleConfigurations(ruleConfigs);
- initialize(authentication, properties, schemaDataSources, schemaRules, metricsConfiguration, clusterConfiguration, false);
+ initialize(authentication, properties, schemaDataSources, schemaRules, new MetricsConfigurationYamlSwapper().swap(metricsConfiguration), clusterConfiguration, false);
ShardingSphereProxy.getInstance().start(port);
}
@@ -136,17 +137,18 @@ public final class Bootstrap {
Properties properties = shardingOrchestrationFacade.getConfigCenter().loadProperties();
Map<String, Map<String, DataSourceParameter>> schemaDataSources = getDataSourceParametersMap(shardingOrchestrationFacade);
Map<String, Collection<RuleConfiguration>> schemaRules = getSchemaRules(shardingOrchestrationFacade);
- initialize(authentication, properties, schemaDataSources, schemaRules, serverConfig.getMetrics(), serverConfig.getCluster(), true);
+ MetricsConfiguration metricsConfiguration = shardingOrchestrationFacade.getConfigCenter().loadMetricsConfiguration();
+ initialize(authentication, properties, schemaDataSources, schemaRules, metricsConfiguration, serverConfig.getCluster(), true);
ShardingSphereProxy.getInstance().start(port);
}
}
private static void initialize(final Authentication authentication, final Properties properties, final Map<String, Map<String, DataSourceParameter>> schemaDataSources,
- final Map<String, Collection<RuleConfiguration>> schemaRules, final YamlMetricsConfiguration metrics,
+ final Map<String, Collection<RuleConfiguration>> schemaRules, final MetricsConfiguration metricsConfiguration,
final YamlClusterConfiguration cluster, final boolean isOrchestration) throws SQLException {
initProxySchemaContexts(schemaDataSources, schemaRules, authentication, properties, isOrchestration);
log(authentication, properties);
- initMetrics(metrics);
+ initMetrics(metricsConfiguration);
initOpenTracing();
initCluster(cluster);
}
@@ -208,6 +210,7 @@ public final class Bootstrap {
shardingOrchestrationFacade.init(getDataSourceConfigurationMap(ruleConfigs),
getRuleConfigurations(ruleConfigs), new AuthenticationYamlSwapper().swap(serverConfig.getAuthentication()), serverConfig.getProps());
}
+ shardingOrchestrationFacade.initMetricsConfiguration(new MetricsConfigurationYamlSwapper().swap(serverConfig.getMetrics()));
}
private static void initOpenTracing() {
@@ -216,9 +219,9 @@ public final class Bootstrap {
}
}
- private static void initMetrics(final YamlMetricsConfiguration metricsConfiguration) {
+ private static void initMetrics(final MetricsConfiguration metricsConfiguration) {
if (ProxySchemaContexts.getInstance().getSchemaContexts().getProperties().<Boolean>getValue(ConfigurationPropertyKey.PROXY_METRICS_ENABLED)) {
- MetricsTrackerFacade.getInstance().init(new MetricsConfigurationYamlSwapper().swap(metricsConfiguration));
+ MetricsTrackerFacade.getInstance().init(metricsConfiguration);
}
}