kylixs commented on a change in pull request #8983: URL: https://github.com/apache/dubbo/pull/8983#discussion_r762410043
########## File path: dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metrics/DefaultMetricsServiceExporter.java ########## @@ -0,0 +1,159 @@ +/* + * 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.dubbo.config.metrics; + +import org.apache.dubbo.common.extension.ExtensionLoader; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.metrics.service.MetricsService; +import org.apache.dubbo.common.metrics.service.MetricsServiceExporter; +import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.MetricsConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.ServiceConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.ScopeModelAware; + +import java.util.List; + +import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL; +import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMETHEUS; + +/** + * Default implementation of {@link MetricsServiceExporter} + */ +public class DefaultMetricsServiceExporter implements MetricsServiceExporter, ScopeModelAware { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + private ApplicationModel applicationModel; + private MetricsService metricsService; + private volatile ServiceConfig<MetricsService> serviceConfig; + + public DefaultMetricsServiceExporter() { + } + + @Override + public void init() { + initialize(); + } + + private void initialize() { + MetricsConfig metricsConfig = applicationModel.getApplicationConfigManager().getMetrics().orElse(null); + // TODO compatible with old usage of metrics, remove protocol check after new metrics is ready for use. + if (metricsConfig != null && PROTOCOL_PROMETHEUS.equals(metricsConfig.getProtocol())) { + ExtensionLoader<MetricsService> extensionLoader = applicationModel.getExtensionLoader(MetricsService.class); Review comment: The protocol of metrics maybe changed if user has custom it. The `MetricsService` is not rely on prometheus. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
