-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(interactive): Standardized log for sls metric (#4073)
- support pass upstream traceId to engine,log trace id to info and metric log - print critical infos in json format which allows log framework like SLS to parse.
- Loading branch information
Showing
32 changed files
with
988 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...engine/common/src/main/java/com/alibaba/graphscope/groot/common/constant/LogConstant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.alibaba.graphscope.groot.common.constant; | ||
|
||
public class LogConstant { | ||
|
||
public static String TRACE_ID = "traceId"; | ||
|
||
public static String UPSTREAM_ID = "upstreamId"; | ||
|
||
public static String QUERY_ID = "queryId"; | ||
|
||
/** | ||
* 具体查询语句 | ||
*/ | ||
public static String QUERY = "query"; | ||
|
||
public static String SUCCESS = "success"; | ||
|
||
public static String ERROR_MESSAGE = "errorMessage"; | ||
|
||
public static String STACK_TRACE = "stackTrace"; | ||
|
||
/** | ||
* 查询计划 | ||
*/ | ||
public static String IR_PLAN = "irPlan"; | ||
|
||
/** | ||
* 打印日志的阶段 | ||
* query: java/rust | ||
* write: writeKafka/consumeKafka/writeDb | ||
*/ | ||
public static String STAGE = "stage"; | ||
|
||
public static String RESULT = "result"; | ||
|
||
public static String COST = "cost"; | ||
|
||
public static String START_TIME = "startMillis"; | ||
|
||
public static String END_TIME = "endMillis"; | ||
|
||
/** | ||
* 日志类型: query/write | ||
*/ | ||
public static String LOG_TYPE = "logType"; | ||
|
||
public static String BATCH_SIZE = "batchSize"; | ||
|
||
public static String PARTITION_ID = "partitionId"; | ||
} |
63 changes: 63 additions & 0 deletions
63
interactive_engine/common/src/main/java/com/alibaba/graphscope/groot/common/util/Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.alibaba.graphscope.groot.common.util; | ||
|
||
import com.alibaba.graphscope.groot.common.constant.LogConstant; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Utils { | ||
|
||
private static final ObjectMapper jsonMapper = new ObjectMapper(); | ||
private static final Logger defaultLogger = LoggerFactory.getLogger(Utils.class); | ||
|
||
/** | ||
* build metric json log for monitor | ||
* plz dont delete any field | ||
* could add new field | ||
* @param isSuccess | ||
* @param traceId | ||
* @param batchSize | ||
* @param partitionId | ||
* @param cost | ||
* @param endTime | ||
* @param stage | ||
* @param logType | ||
* @return | ||
*/ | ||
public static String buildMetricJsonLog( | ||
boolean isSuccess, | ||
String traceId, | ||
Integer batchSize, | ||
Integer partitionId, | ||
long cost, | ||
Long endTime, | ||
String stage, | ||
String logType) { | ||
String jsonLog = ""; | ||
ObjectNode metricJsonLog = jsonMapper.createObjectNode(); | ||
metricJsonLog.put(LogConstant.TRACE_ID, traceId); | ||
metricJsonLog.put(LogConstant.SUCCESS, isSuccess); | ||
if (batchSize != null) { | ||
metricJsonLog.put(LogConstant.BATCH_SIZE, batchSize); | ||
} | ||
if (partitionId != null) { | ||
metricJsonLog.put(LogConstant.PARTITION_ID, partitionId); | ||
} | ||
if (endTime != null) { | ||
metricJsonLog.put(LogConstant.END_TIME, endTime); | ||
} | ||
metricJsonLog.put(LogConstant.COST, cost); | ||
if (stage != null) { | ||
metricJsonLog.put(LogConstant.STAGE, stage); | ||
} | ||
metricJsonLog.put(LogConstant.LOG_TYPE, logType); | ||
try { | ||
jsonLog = jsonMapper.writeValueAsString(metricJsonLog); | ||
} catch (Exception e) { | ||
defaultLogger.error("JsonProcessingException!", e); | ||
} | ||
return jsonLog; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.