Skip to content

Commit

Permalink
optimize log display inner 2378
Browse files Browse the repository at this point in the history
  • Loading branch information
ylinzhu committed Nov 27, 2023
1 parent 5f16887 commit 60cd6f5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ public boolean checkInstanceExist(String instanceName) {

private void reportDisableError(PhysicalDbInstance ins) throws IOException {
final DbInstanceConfig config = ins.getConfig();
String disableError = "the dbInstance[" + config.getUrl() + "] is disable. Please check the dbInstance disable status";
String disableError = "the dbInstance[" + config.getInstanceMessage(dbGroupConfig.getName()) + "] is disable. Please check the dbInstance disable status";
LOGGER.warn(disableError);
Map<String, String> labels = AlertUtil.genSingleLabel("dbInstance", dbGroupConfig.getName() + "-" + config.getInstanceName());
AlertUtil.alert(AlarmCode.DB_INSTANCE_CAN_NOT_REACH, Alert.AlertLevel.WARN, disableError, "mysql", config.getId(), labels);
Expand All @@ -694,7 +694,7 @@ private void reportDisableError(PhysicalDbInstance ins) throws IOException {

private void reportFakeNodeError(PhysicalDbInstance ins) throws IOException {
final DbInstanceConfig config = ins.getConfig();
String fakeNodeError = "the dbInstance[" + config.getUrl() + "] is fake node. Please check the dbInstance whether or not it is used";
String fakeNodeError = "the dbInstance[" + config.getInstanceMessage(dbGroupConfig.getName() + "] is fake node. Please check the dbInstance whether or not it is used");
LOGGER.warn(fakeNodeError);
Map<String, String> labels = AlertUtil.genSingleLabel("dbInstance", dbGroupConfig.getName() + "-" + config.getInstanceName());
AlertUtil.alert(AlarmCode.DB_INSTANCE_CAN_NOT_REACH, Alert.AlertLevel.WARN, fakeNodeError, "mysql", config.getId(), labels);
Expand All @@ -703,7 +703,7 @@ private void reportFakeNodeError(PhysicalDbInstance ins) throws IOException {

private void reportHeartbeatError(PhysicalDbInstance ins) throws IOException {
final DbInstanceConfig config = ins.getConfig();
String heartbeatError = "the dbInstance[" + config.getUrl() + "] can't reach. Please check the dbInstance is accessible";
String heartbeatError = "the dbInstance[" + config.getInstanceMessage(dbGroupConfig.getName()) + "] can't reach. Please check the dbInstance is accessible";
if (dbGroupConfig.isShowSlaveSql()) {
heartbeatError += " and the privileges of user is sufficient (NOTE:heartbeat[show slave status] need grant the SUPER or REPLICATION CLIENT privilege(s) to db user,and then restart the dble or fresh conn).";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ public void updateLastReceivedQryTime() {
}

private void setTimeout() {
LOGGER.warn("delayDetection to [" + source.getConfig().getUrl() + "] setTimeout");
LOGGER.warn("delayDetection to [" + source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()) + "] setTimeout");
delayDetectionStatus = DelayDetectionStatus.TIMEOUT;
source.setDelayDetectionStatus(delayDetectionStatus);
alert(AlarmCode.DB_SLAVE_INSTANCE_DELAY, errorMessage, dbGroupConfig.instanceDatabaseType().name().toLowerCase());
}

private void setError() {
LOGGER.warn("delayDetection to [" + source.getConfig().getUrl() + "] setError");
LOGGER.warn("delayDetection to [" + source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()) + "] setError");
delayDetectionStatus = DelayDetectionStatus.ERROR;
source.setDelayDetectionStatus(delayDetectionStatus);
if (!source.isReadInstance()) {
Expand All @@ -245,7 +245,7 @@ private void setError() {
}

private void setOk() {
LOGGER.debug("delayDetection to [" + source.getConfig().getUrl() + "] setOK");
LOGGER.debug("delayDetection to [" + source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()) + "] setOK");
if (errorCount.get() > 0) {
errorCount.set(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void setStatusForNormalHeartbeat(PhysicalDbInstance source) {
*/
private boolean checkRecoverFail(PhysicalDbInstance source) {
if (heartbeat.isStop()) {
LOGGER.warn("heartbeat[{}] had been stop", source.getConfig().getUrl());
LOGGER.warn("heartbeat[{}] had been stop", source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()));
return true;
}
if (heartbeat.getStatus() == MySQLHeartbeatStatus.OK) { // ok->ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ public void start(long heartbeatPeriodMillis) {

public void stop(String reason) {
if (isStop) {
LOGGER.warn("heartbeat[{}] had been stop", source.getConfig().getUrl());
LOGGER.warn("heartbeat[{}] had been stop", source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()));
return;
}
LOGGER.info("stop heartbeat of instance[{}], due to {}", source.getConfig().getUrl(), reason);
LOGGER.info("stop heartbeat of instance[{}], due to {}", source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()), reason);
isStop = true;
scheduledFuture.cancel(false);
initHeartbeat.set(false);
Expand Down Expand Up @@ -164,7 +164,7 @@ boolean doHeartbeatRetry() {
}

void setErrorResult(String errMsg) {
LOGGER.warn("heartbeat to [" + source.getConfig().getUrl() + "] setError");
LOGGER.warn("heartbeat to [" + source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()) + "] setError");
// should continue checking error status
if (detector != null) {
detector.quit();
Expand Down Expand Up @@ -203,7 +203,7 @@ void setResult(MySQLHeartbeatStatus result) {

private void setOk() {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("heartbeat to [" + source.getConfig().getUrl() + "] setOK");
LOGGER.debug("heartbeat to [" + source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()) + "] setOK");
}
MySQLHeartbeatStatus previousStatus = status;
switch (status) {
Expand All @@ -212,17 +212,17 @@ private void setOk() {
this.errorCount.set(0);
this.startErrorTime.set(-1);
if (isStop) {
LOGGER.warn("heartbeat[{}] had been stop", source.getConfig().getUrl());
LOGGER.warn("heartbeat[{}] had been stop", source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()));
detector.quit();
} else {
LOGGER.info("heartbeat to [{}] setOk, previous status is timeout", source.getConfig().getUrl());
LOGGER.info("heartbeat to [{}] setOk, previous status is timeout", source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()));
heartbeat(); // timeout, heart beat again
}
break;
case OK:
break;
default:
LOGGER.info("heartbeat to [{}] setOk, previous status is {}", source.getConfig().getUrl(), status);
LOGGER.info("heartbeat to [{}] setOk, previous status is {}", source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()), status);
this.status = MySQLHeartbeatStatus.OK;
this.errorCount.set(0);
this.startErrorTime.set(-1);
Expand All @@ -236,7 +236,7 @@ private void setOk() {
source.updatePoolCapacity();
}
if (isStop) {
LOGGER.warn("heartbeat[{}] had been stop", source.getConfig().getUrl());
LOGGER.warn("heartbeat[{}] had been stop", source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()));
detector.quit();
}
}
Expand All @@ -253,10 +253,10 @@ private void recordErrorCount() {

private void setTimeout() {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("heartbeat to [" + source.getConfig().getUrl() + "] setTimeout");
LOGGER.debug("heartbeat to [" + source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()) + "] setTimeout");
}
if (status != MySQLHeartbeatStatus.TIMEOUT) {
LOGGER.warn("heartbeat to [{}] setTimeout, previous status is {}", source.getConfig().getUrl(), status);
LOGGER.warn("heartbeat to [{}] setTimeout, previous status is {}", source.getConfig().getInstanceMessage(source.getDbGroupConfig().getName()), status);
status = MySQLHeartbeatStatus.TIMEOUT;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public void setDbDataCenter(String dbDataCenter) {
this.dbDataCenter = dbDataCenter;
}

public String getInstanceMessage(String dbGroupName) {
StringBuilder sb = new StringBuilder(dbGroupName);
return sb.append(":").append(instanceName).append(":").append(url).toString();
}

@Override
public String toString() {
return "DbInstanceConfig [hostName=" + instanceName + ", url=" + url + "]";
Expand Down

0 comments on commit 60cd6f5

Please sign in to comment.