Skip to content

Commit

Permalink
Some enhancement for logs and ability. (alibaba#5482)
Browse files Browse the repository at this point in the history
  • Loading branch information
KomachiSion authored Apr 25, 2021
1 parent 6c064bf commit 267d671
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,35 @@
*/
public class ServerNamingAbility implements Serializable {

private boolean exampleAbility;
private static final long serialVersionUID = 8308895444341445512L;

public boolean isExampleAbility() {
return exampleAbility;
/**
* Nacos server can use SOFA-Jraft to handle persist service and metadata.
*/
private boolean supportJraft;

public boolean isSupportJraft() {
return supportJraft;
}

public void setExampleAbility(boolean exampleAbility) {
this.exampleAbility = exampleAbility;
public void setSupportJraft(boolean supportJraft) {
this.supportJraft = supportJraft;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof ServerNamingAbility)) {
return false;
}
ServerNamingAbility that = (ServerNamingAbility) o;
return exampleAbility == that.exampleAbility;
return supportJraft == that.supportJraft;
}

@Override
public int hashCode() {
return Objects.hash(exampleAbility);
return Objects.hash(supportJraft);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 1999-2020 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.naming;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;

public class ServerNamingAbilityTest {

private static ObjectMapper jacksonMapper;

@BeforeClass
public static void setUpClass() throws Exception {
jacksonMapper = new ObjectMapper();
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
jacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

@Test
public void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException {
String nonExistItemJson = "{\"exampleAbility\":false}";
ServerNamingAbility actual = jacksonMapper.readValue(nonExistItemJson, ServerNamingAbility.class);
assertFalse(actual.isSupportJraft());
}

@Test
public void testEquals() throws JsonProcessingException {
ServerNamingAbility expected = new ServerNamingAbility();
expected.setSupportJraft(true);
String serializeJson = jacksonMapper.writeValueAsString(expected);
ServerNamingAbility actual = jacksonMapper.readValue(serializeJson, ServerNamingAbility.class);
assertEquals(expected, actual);
actual = new ServerNamingAbility();
assertNotEquals(expected, actual);
actual.setSupportJraft(true);
assertEquals(expected, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void onConnected() {
}

private void redoSubscribe() {
LogUtils.NAMING_LOGGER.info("Grpc re-connect, redo subscribe services");
for (String each : subscribes) {
ServiceInfo serviceInfo = ServiceInfo.fromKey(each);
try {
Expand All @@ -68,6 +69,7 @@ private void redoSubscribe() {
}

private void redoRegisterEachService() {
LogUtils.NAMING_LOGGER.info("Grpc re-connect, redo register services");
for (Map.Entry<String, Set<Instance>> each : registeredInstanceCached.entrySet()) {
String serviceName = NamingUtils.getServiceName(each.getKey());
String groupName = NamingUtils.getGroupName(each.getKey());
Expand All @@ -88,6 +90,7 @@ private void redoRegisterEachInstance(String serviceName, String groupName, Set<

@Override
public void onDisConnect() {
LogUtils.NAMING_LOGGER.warn("Grpc connection disconnect");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ protected void init() throws NacosException {
private ServerAbilities initMemberAbilities() {
ServerAbilities serverAbilities = new ServerAbilities();
serverAbilities.getRemoteAbility().setSupportRemoteConnection(true);
// TODO naming and config ability should build and init by sub module.
serverAbilities.getNamingAbility().setSupportJraft(true);
return serverAbilities;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ public void onSuccess() {
long pushCostTimeForNetWork = pushFinishTime - executeStartTime;
long pushCostTimeForAll = pushFinishTime - delayTask.getLastProcessTime();
long serviceLevelAgreementTime = pushFinishTime - service.getLastUpdatedTime();
Loggers.PUSH.info("[PUSH-SUCC] {}ms, all delay time {}ms, SLA {}ms, {}, DataSize={}, target={}",
pushCostTimeForNetWork, pushCostTimeForAll, serviceLevelAgreementTime, service,
serviceInfo.getHosts().size(), subscriber.getIp());
if (isPushToAll) {
Loggers.PUSH.info("[PUSH-SUCC] {}ms, all delay time {}ms, SLA {}ms, {}, DataSize={}, target={}",
pushCostTimeForNetWork, pushCostTimeForAll, serviceLevelAgreementTime, service,
serviceInfo.getHosts().size(), subscriber.getIp());
} else {
Loggers.PUSH.info("[PUSH-SUCC] {}ms, all delay time {}ms for subscriber {}, {}, DataSize={}",
pushCostTimeForNetWork, pushCostTimeForAll, subscriber.getIp(), service,
serviceInfo.getHosts().size());
}
PushResult result = PushResult
.pushSuccess(service, clientId, serviceInfo, subscriber, pushCostTimeForNetWork, pushCostTimeForAll,
serviceLevelAgreementTime, isPushToAll);
Expand Down

0 comments on commit 267d671

Please sign in to comment.