Search in sources :

Example 1 with NAMESPACE_SERVICE_CONNECTOR

use of com.alibaba.nacos.naming.misc.UtilsAndCommons.NAMESPACE_SERVICE_CONNECTOR in project nacos by alibaba.

the class UpgradeOpsController method getMetrics.

private ObjectNode getMetrics() throws NacosException {
    ObjectNode result = JacksonUtils.createEmptyJsonNode();
    Set<String> serviceNamesV2 = new HashSet<>();
    Set<String> persistentServiceNamesV2 = new HashSet<>();
    Set<String> ephemeralServiceNamesV2 = new HashSet<>();
    int persistentInstanceCountV2 = 0;
    int ephemeralInstanceCountV2 = 0;
    Set<String> allNamespaces = com.alibaba.nacos.naming.core.v2.ServiceManager.getInstance().getAllNamespaces();
    for (String ns : allNamespaces) {
        Set<com.alibaba.nacos.naming.core.v2.pojo.Service> services = com.alibaba.nacos.naming.core.v2.ServiceManager.getInstance().getSingletons(ns);
        for (com.alibaba.nacos.naming.core.v2.pojo.Service service : services) {
            String nameWithNs = service.getNamespace() + NAMESPACE_SERVICE_CONNECTOR + service.getGroupedServiceName();
            serviceNamesV2.add(nameWithNs);
            if (service.isEphemeral()) {
                ephemeralServiceNamesV2.add(nameWithNs);
            } else {
                persistentServiceNamesV2.add(nameWithNs);
            }
            ServiceInfo data = serviceStorage.getPushData(service);
            for (com.alibaba.nacos.api.naming.pojo.Instance instance : data.getHosts()) {
                if (instance.isEphemeral()) {
                    ephemeralInstanceCountV2 += 1;
                } else {
                    persistentInstanceCountV2 += 1;
                }
            }
        }
    }
    result.put("upgraded", upgradeJudgement.isUseGrpcFeatures());
    result.put("isAll20XVersion", upgradeJudgement.isAll20XVersion());
    result.put("isDoubleWriteEnabled", switchDomain.isDoubleWriteEnabled());
    result.put("doubleWriteDelayTaskCount", doubleWriteDelayTaskEngine.size());
    result.put("serviceCountV1", serviceManager.getServiceCount());
    result.put("instanceCountV1", serviceManager.getInstanceCount());
    result.put("serviceCountV2", MetricsMonitor.getDomCountMonitor().get());
    result.put("instanceCountV2", MetricsMonitor.getIpCountMonitor().get());
    result.put("subscribeCountV2", MetricsMonitor.getSubscriberCount().get());
    result.put("responsibleServiceCountV1", serviceManager.getResponsibleServiceCount());
    result.put("responsibleInstanceCountV1", serviceManager.getResponsibleInstanceCount());
    result.put("ephemeralServiceCountV2", ephemeralServiceNamesV2.size());
    result.put("persistentServiceCountV2", persistentServiceNamesV2.size());
    result.put("ephemeralInstanceCountV2", ephemeralInstanceCountV2);
    result.put("persistentInstanceCountV2", persistentInstanceCountV2);
    Set<String> serviceNamesV1 = serviceManager.getAllServiceNames().entrySet().stream().flatMap(e -> e.getValue().stream().map(name -> {
        if (!name.contains(SERVICE_INFO_SPLITER)) {
            name = NamingUtils.getGroupedName(name, DEFAULT_GROUP);
        }
        return e.getKey() + NAMESPACE_SERVICE_CONNECTOR + name;
    })).collect(Collectors.toSet());
    result.put("service.V1.not.in.V2", String.join("\n", (Collection<String>) CollectionUtils.subtract(serviceNamesV1, serviceNamesV2)));
    result.put("service.V2.not.in.V1", String.join("\n", (Collection<String>) CollectionUtils.subtract(serviceNamesV2, serviceNamesV1)));
    return result;
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) CommonParams(com.alibaba.nacos.api.naming.CommonParams) WebUtils(com.alibaba.nacos.core.utils.WebUtils) URLDecoder(java.net.URLDecoder) HttpRequestInstanceBuilder(com.alibaba.nacos.naming.pojo.instance.HttpRequestInstanceBuilder) Autowired(org.springframework.beans.factory.annotation.Autowired) CanDistro(com.alibaba.nacos.naming.web.CanDistro) NAMESPACE_SERVICE_CONNECTOR(com.alibaba.nacos.naming.misc.UtilsAndCommons.NAMESPACE_SERVICE_CONNECTOR) Selector(com.alibaba.nacos.api.selector.Selector) PutMapping(org.springframework.web.bind.annotation.PutMapping) Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstanceOperatorServiceImpl(com.alibaba.nacos.naming.core.InstanceOperatorServiceImpl) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) MetricsMonitor(com.alibaba.nacos.naming.monitor.MetricsMonitor) JacksonUtils(com.alibaba.nacos.common.utils.JacksonUtils) PostMapping(org.springframework.web.bind.annotation.PostMapping) SelectorManager(com.alibaba.nacos.naming.selector.SelectorManager) DoubleWriteDelayTaskEngine(com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.DoubleWriteDelayTaskEngine) Collection(java.util.Collection) Set(java.util.Set) InstanceOperatorClientImpl(com.alibaba.nacos.naming.core.InstanceOperatorClientImpl) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) UtilsAndCommons(com.alibaba.nacos.naming.misc.UtilsAndCommons) Constants(com.alibaba.nacos.api.common.Constants) StringUtils(com.alibaba.nacos.common.utils.StringUtils) ActionTypes(com.alibaba.nacos.plugin.auth.constant.ActionTypes) Optional(java.util.Optional) Secured(com.alibaba.nacos.auth.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ServiceManager(com.alibaba.nacos.naming.core.ServiceManager) ServiceOperator(com.alibaba.nacos.naming.core.ServiceOperator) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashSet(java.util.HashSet) NumberUtils(com.alibaba.nacos.common.utils.NumberUtils) DEFAULT_GROUP(com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServiceUtil(com.alibaba.nacos.naming.utils.ServiceUtil) CollectionUtils(org.apache.commons.collections.CollectionUtils) SwitchDomain(com.alibaba.nacos.naming.misc.SwitchDomain) NacosException(com.alibaba.nacos.api.exception.NacosException) GetMapping(org.springframework.web.bind.annotation.GetMapping) SERVICE_INFO_SPLITER(com.alibaba.nacos.api.common.Constants.SERVICE_INFO_SPLITER) ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ConvertUtils(com.alibaba.nacos.common.utils.ConvertUtils) Iterator(java.util.Iterator) ServiceOperatorV2Impl(com.alibaba.nacos.naming.core.ServiceOperatorV2Impl) UpgradeJudgement(com.alibaba.nacos.naming.core.v2.upgrade.UpgradeJudgement) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) InstanceOperator(com.alibaba.nacos.naming.core.InstanceOperator) NamingUtils(com.alibaba.nacos.api.naming.utils.NamingUtils) ServiceOperatorV1Impl(com.alibaba.nacos.naming.core.ServiceOperatorV1Impl) NoneSelector(com.alibaba.nacos.naming.selector.NoneSelector) ServiceStorage(com.alibaba.nacos.naming.core.v2.index.ServiceStorage) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Instance(com.alibaba.nacos.api.naming.pojo.Instance) Collection(java.util.Collection) HashSet(java.util.HashSet)

Aggregations

Constants (com.alibaba.nacos.api.common.Constants)1 DEFAULT_GROUP (com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP)1 SERVICE_INFO_SPLITER (com.alibaba.nacos.api.common.Constants.SERVICE_INFO_SPLITER)1 NacosException (com.alibaba.nacos.api.exception.NacosException)1 CommonParams (com.alibaba.nacos.api.naming.CommonParams)1 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)1 NamingUtils (com.alibaba.nacos.api.naming.utils.NamingUtils)1 Selector (com.alibaba.nacos.api.selector.Selector)1 Secured (com.alibaba.nacos.auth.annotation.Secured)1 ConvertUtils (com.alibaba.nacos.common.utils.ConvertUtils)1 JacksonUtils (com.alibaba.nacos.common.utils.JacksonUtils)1 NumberUtils (com.alibaba.nacos.common.utils.NumberUtils)1 StringUtils (com.alibaba.nacos.common.utils.StringUtils)1 WebUtils (com.alibaba.nacos.core.utils.WebUtils)1 InstanceOperator (com.alibaba.nacos.naming.core.InstanceOperator)1 InstanceOperatorClientImpl (com.alibaba.nacos.naming.core.InstanceOperatorClientImpl)1 InstanceOperatorServiceImpl (com.alibaba.nacos.naming.core.InstanceOperatorServiceImpl)1 ServiceManager (com.alibaba.nacos.naming.core.ServiceManager)1 ServiceOperator (com.alibaba.nacos.naming.core.ServiceOperator)1