[ISSUE #11325]Fix logging for Config pull events. (#11326)

* [ISSUE #11325]Fix logging for Config pull events.

* Update style.
This commit is contained in:
阿魁 2023-12-06 13:10:17 +08:00 committed by GitHub
parent 319ec8c257
commit 3058f9f8ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 34 deletions

View File

@ -148,10 +148,7 @@ public class ConfigServletInner {
String tenant, String tag, String isNotify, String clientIp, boolean isV2)
throws IOException, ServletException {
boolean notify = false;
if (StringUtils.isNotBlank(isNotify)) {
notify = Boolean.parseBoolean(isNotify);
}
boolean notify = StringUtils.isNotBlank(isNotify) && Boolean.parseBoolean(isNotify);
String acceptCharset = ENCODE_UTF8;
@ -167,7 +164,6 @@ public class ConfigServletInner {
final String requestIp = RequestUtil.getRemoteIp(request);
boolean isBeta = false;
boolean isSli = false;
if (lockResult > 0) {
// LockResult > 0 means cacheItem is not null and other thread can`t delete this cacheItem
try {
@ -181,7 +177,7 @@ public class ConfigServletInner {
final String configType =
(null != cacheItem.getType()) ? cacheItem.getType() : FileTypeEnum.TEXT.getFileType();
response.setHeader("Config-Type", configType);
response.setHeader(com.alibaba.nacos.api.common.Constants.CONFIG_TYPE, configType);
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(configType);
String contentTypeHeader = fileTypeEnum.getContentType();
response.setHeader(HttpHeaderConsts.CONTENT_TYPE, contentTypeHeader);
@ -190,10 +186,9 @@ public class ConfigServletInner {
response.setHeader(HttpHeaderConsts.CONTENT_TYPE, MediaType.APPLICATION_JSON);
}
String pullEvent = ConfigTraceService.PULL_EVENT;
String pullEvent;
String content = null;
ConfigInfoBase configInfoBase = null;
PrintWriter out;
if (isBeta) {
ConfigCache configCacheBeta = cacheItem.getConfigCacheBeta();
pullEvent = ConfigTraceService.PULL_EVENT_BETA;
@ -248,7 +243,6 @@ public class ConfigServletInner {
return get404Result(response, isV2);
}
isSli = true;
}
} else {
md5 = cacheItem.getTagMd5(tag, acceptCharset);
@ -264,7 +258,7 @@ public class ConfigServletInner {
// FIXME CacheItem
// No longer exists. It is impossible to simply calculate the push delayed. Here, simply record it as - 1.
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, -1, pullEvent,
ConfigTraceService.PULL_TYPE_NOTFOUND, -1, requestIp, notify && isSli, "http");
ConfigTraceService.PULL_TYPE_NOTFOUND, -1, requestIp, notify, "http");
// pullLog.info("[client-get] clientIp={}, {},
// no data",
@ -283,7 +277,7 @@ public class ConfigServletInner {
response.setHeader("Cache-Control", "no-cache,no-store");
response.setDateHeader("Last-Modified", lastModified);
putEncryptedDataKeyHeader(response, tag, clientIp, acceptCharset, cacheItem, isBeta, autoTag);
PrintWriter out;
if (PropertyUtil.isDirectRead()) {
Pair<String, String> pair = EncryptionHandler.decryptHandler(dataId,
configInfoBase.getEncryptedDataKey(), configInfoBase.getContent());
@ -309,17 +303,9 @@ public class ConfigServletInner {
LogUtil.PULL_CHECK_LOG.warn("{}|{}|{}|{}", groupKey, requestIp, md5, TimeUtils.getCurrentTimeStr());
final long delayed = System.currentTimeMillis() - lastModified;
if (notify) {
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, lastModified, pullEvent,
ConfigTraceService.PULL_TYPE_OK, delayed, requestIp, true, "http");
} else {
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, lastModified, pullEvent,
ConfigTraceService.PULL_TYPE_OK, -1, requestIp, false, "http");
}
final long delayed = notify ? -1 : System.currentTimeMillis() - lastModified;
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, lastModified, pullEvent,
ConfigTraceService.PULL_TYPE_OK, delayed, clientIp, notify, "http");
} finally {
releaseConfigReadLock(groupKey);
}
@ -327,7 +313,7 @@ public class ConfigServletInner {
// FIXME CacheItem No longer exists. It is impossible to simply calculate the push delayed. Here, simply record it as - 1.
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, -1, ConfigTraceService.PULL_EVENT,
ConfigTraceService.PULL_TYPE_NOTFOUND, -1, requestIp, notify && isSli, "http");
ConfigTraceService.PULL_TYPE_NOTFOUND, -1, requestIp, notify, "http");
return get404Result(response, isV2);

View File

@ -210,15 +210,9 @@ public class ConfigQueryRequestHandler extends RequestHandler<ConfigQueryRequest
LogUtil.PULL_CHECK_LOG.warn("{}|{}|{}|{}", groupKey, clientIp, md5, TimeUtils.getCurrentTimeStr());
final long delayed = System.currentTimeMillis() - lastModified;
if (notify) {
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, lastModified, pullEvent,
ConfigTraceService.PULL_TYPE_OK, delayed, clientIp, notify, "grpc");
} else {
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, lastModified, pullEvent,
ConfigTraceService.PULL_TYPE_OK, System.currentTimeMillis(), clientIp, notify, "grpc");
}
final long delayed = notify ? -1 : System.currentTimeMillis() - lastModified;
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, lastModified, pullEvent,
ConfigTraceService.PULL_TYPE_OK, delayed, clientIp, notify, "grpc");
} finally {
releaseConfigReadLock(groupKey);
}

View File

@ -17,11 +17,11 @@
package com.alibaba.nacos.config.server.service.trace;
import com.alibaba.nacos.common.utils.MD5Utils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.sys.utils.InetUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
@ -272,6 +272,8 @@ public class ConfigTraceService {
* @param type type
* @param delayed delayed
* @param clientIp clientIp
* @param isNotify isNotify
* @param model model
*/
public static void logPullEvent(String dataId, String group, String tenant, String requestIpAppName, long ts,
String event, String type, long delayed, String clientIp, boolean isNotify, String model) {
@ -287,7 +289,7 @@ public class ConfigTraceService {
delayed = 0;
}
//localIp | dataid | group | tenant| requestIpAppName| ts | event | type | [delayed] |clientIp| mode,http/grpc
// localIp | dataid | group | tenant| requestIpAppName| ts | event | type | [delayed] |clientIp| isNotify | modehttp/grpc)
LogUtil.TRACE_LOG.info("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}", InetUtils.getSelfIP(), dataId, group, tenant,
requestIpAppName, ts, event, type, delayed, clientIp, isNotify, model);
}