Metrics and Metadata Service Export when needed (#12346)

This commit is contained in:
Albumen Kevin 2023-05-19 16:18:12 +08:00 committed by GitHub
parent 9c72fdea69
commit 08727e8e27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 7 deletions

View File

@ -239,6 +239,10 @@ public interface CommonConstants {
String REMOTE_METADATA_STORAGE_TYPE = "remote";
String INTERFACE_REGISTER_MODE = "interface";
String DEFAULT_REGISTER_MODE = "all";
String GENERIC_KEY = "generic";
/**

View File

@ -19,8 +19,8 @@ package org.apache.dubbo.config;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.config.nested.AggregationConfig;
import org.apache.dubbo.config.nested.PrometheusConfig;
import org.apache.dubbo.config.nested.HistogramConfig;
import org.apache.dubbo.config.nested.PrometheusConfig;
import org.apache.dubbo.config.support.Nested;
import org.apache.dubbo.rpc.model.ApplicationModel;
@ -56,6 +56,11 @@ public class MetricsConfig extends AbstractConfig {
*/
private Boolean enableMetadata;
/**
* Export metrics service.
*/
private Boolean exportMetricsService;
/**
* @deprecated After metrics config is refactored.
* This parameter should no longer use and will be deleted in the future.
@ -186,6 +191,14 @@ public class MetricsConfig extends AbstractConfig {
this.enableMetadata = enableMetadata;
}
public Boolean getExportMetricsService() {
return exportMetricsService;
}
public void setExportMetricsService(Boolean exportMetricsService) {
this.exportMetricsService = exportMetricsService;
}
public Boolean getEnableThreadpool() {
return enableThreadpool;
}

View File

@ -751,11 +751,15 @@ public class DefaultApplicationDeployer extends AbstractDeployer<ApplicationMode
}
private void exportMetricsService() {
try {
metricsServiceExporter.export();
} catch (Exception e) {
logger.error(LoggerCodeConstants.COMMON_METRICS_COLLECTOR_EXCEPTION, "", "",
"exportMetricsService an exception occurred when handle starting event", e);
boolean exportMetrics = applicationModel.getApplicationConfigManager().getMetrics()
.map(MetricsConfig::getExportMetricsService).orElse(true);
if (exportMetrics) {
try {
metricsServiceExporter.export();
} catch (Exception e) {
logger.error(LoggerCodeConstants.COMMON_METRICS_COLLECTOR_EXCEPTION, "", "",
"exportMetricsService an exception occurred when handle starting event", e);
}
}
}

View File

@ -23,6 +23,8 @@ import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation;
import org.apache.dubbo.rpc.model.ApplicationModel;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_REGISTER_MODE;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_REGISTER_MODE;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
public class ExporterDeployListener implements ApplicationDeployListener, Prioritized {
@ -56,6 +58,13 @@ public class ExporterDeployListener implements ApplicationDeployListener, Priori
return type;
}
private String getRegisterMode(ApplicationModel applicationModel) {
String type = applicationModel.getApplicationConfigManager().getApplicationOrElseThrow().getRegisterMode();
if (StringUtils.isEmpty(type)) {
type = DEFAULT_REGISTER_MODE;
}
return type;
}
public ConfigurableMetadataServiceExporter getMetadataServiceExporter() {
return metadataServiceExporter;
@ -72,7 +81,7 @@ public class ExporterDeployListener implements ApplicationDeployListener, Priori
if (metadataServiceExporter == null) {
metadataServiceExporter = new ConfigurableMetadataServiceExporter(applicationModel, metadataService);
// fixme, let's disable local metadata service export at this moment
if (!REMOTE_METADATA_STORAGE_TYPE.equals(getMetadataType(applicationModel))) {
if (!REMOTE_METADATA_STORAGE_TYPE.equals(getMetadataType(applicationModel)) && !INTERFACE_REGISTER_MODE.equals(getRegisterMode(applicationModel))) {
metadataServiceExporter.export();
}
}

View File

@ -1087,6 +1087,12 @@
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="export-metrics-service" type="xsd:boolean" default="true">
<xsd:annotation>
<xsd:documentation><![CDATA[ Enable export metrics service. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="port" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[ Deprecated. No longer use. ]]></xsd:documentation>