文档

解析红线异常问题排查参考文档

更新时间:

解析红线异常问题排查参考文档

1、复制错误信息

点击错误信息,弹框出来的内容复制出来 .

image.png

双击复制红线信息。

image.png

2、运行排查用例

将红线信息数据放入下面用例里进行调试,排查问题.

image.png

排查所用到的用例如下:

import com.alibaba.fastjson.JSON;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StatInfoTest {

    private static Pattern STAT_INFO_TITLE_PATTERN = Pattern.compile("^STAT_INFO_TITLE:\\s*(.+)\\s*");
    private static Pattern REDLINE_INFO_PATTERN = Pattern.compile("^REDLINE_ITEM_LINE:\\s*(.+)\\s*");
    private static Pattern STAT_PATTERN = Pattern.compile("^STAT_(VALUE|NAME|TITLE|URL|STYLE)_([^:]+):\\s*(.*)\\s*");


    public static void main(String[] args) {
        // 下面为一个失败的示例数据
        //String statOutMapStr = "{\"10_1682051393916__10_1682051404781\":[\"STAT_INFO_TITLE: \\\"\\\"\",\"STAT_NAME_Total: 缺陷\",\"STAT_VALUE_Total: ww\",\"STAT_STYLE_Total: Error\",\"STAT_NAME_Blocker: 漏洞\",\"STAT_VALUE_Blocker: ww\",\"STAT_STYLE_Blocker: Warning\",\"REDLINE_ITEM_LINE: {\\\"key\\\":\\\"Blocker\\\",\\\"threshold\\\":43,\\\"checkVal\\\":ww,\\\"type\\\":\\\"LE\\\",\\\"checked\\\":true,\\\"checkResult\\\":false}\",\"STAT_NAME_Critical: 坏味道\",\"STAT_VALUE_Critical: ww\",\"STAT_STYLE_Critical: Warning\",\"REDLINE_ITEM_LINE: {\\\"key\\\":\\\"Critical\\\",\\\"threshold\\\":34,\\\"checkVal\\\":ww,\\\"type\\\":\\\"LE\\\",\\\"checked\\\":true,\\\"checkResult\\\":false}\",\"STAT_NAME_Major: 覆盖率\",\"STAT_VALUE_Major: ww0\",\"STAT_STYLE_Major: Default\",\"REDLINE_ITEM_LINE: {\\\"key\\\":\\\"Major\\\",\\\"threshold\\\":4,\\\"checkVal\\\":ww0,\\\"type\\\":\\\"LE\\\",\\\"checked\\\":true,\\\"checkResult\\\":false}\",\"STAT_URL__REPORT: 127.0.0.1/dashboard?id=13212323%3A31313213213\"]}";
        String  statOutMapStr="请将卡片上的数据信息复制到此处进行调试";
        parseStatInfo(statOutMapStr);
    }

    public static void parseStatInfo(String statOutMapStr) {
        Map<String, List<String>> statOutMap = JSON.parseObject(statOutMapStr, new HashMap<String, List<String>>().getClass());
        List<StatGroup> statGroups = new ArrayList<>();
        statOutMap.forEach((k, params) -> {
            StatGroup statGroup = new StatGroup<StatInfo>();
            Map<String, StatInfo> statInfoMap = new LinkedHashMap<>(64);
            List<RedlineResultItem> redlines = new ArrayList<>(64);
            Optional.ofNullable(params).orElse(new ArrayList<>())
                    .forEach(str -> {
                        Matcher matcher = STAT_PATTERN.matcher(str);
                        if (matcher.find()) {
                            String fieldName = matcher.group(1).toLowerCase();
                            String key = matcher.group(2);
                            String value = matcher.group(3);
                            StatInfo statInfo = statInfoMap.get(key);
                            if (statInfo == null) {
                                statInfo = new StatInfo();
                                statInfo.setKey(key);
                            }
                            statInfo.setField(fieldName, value);
                            statInfoMap.put(key, statInfo);
                        }
                        // check redlines
                        Matcher redlineMatcher = REDLINE_INFO_PATTERN.matcher(str);
                        if (redlineMatcher.find()) {
                            String redlineResult = redlineMatcher.group(1);
                            RedlineResultItem redlineItem = JSON.parseObject(redlineResult, RedlineResultItem.class);
                            // check if valid redline item
                            if (redlineItem.getKey() != "" && redlineItem.getThreshold() != null) {
                                redlines.add(redlineItem);
                            }
                        }
                    });
            statGroup.setTitle(getStatInfoTitle(params));
            statGroup.setStatInfoMap(statInfoMap);
            statGroup.setRedlineResult(redlines);
            statGroups.add(statGroup);
        });
        System.out.println(JSON.toJSONString(statGroups));
    }

    private static String getStatInfoTitle(List<String> params) {
        String title = null;
        if (params != null) {
            for (String param : params) {
                Matcher matcher = STAT_INFO_TITLE_PATTERN.matcher(param);
                if (matcher.find()) {
                    title = matcher.group(1);
                    break;
                }
            }
        }
        return title;
    }

    static class StatGroup<T> {
        private String title;
        private Map<String, T> statInfoMap;
        private List<RedlineResultItem> redlineResult;

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public Map<String, T> getStatInfoMap() {
            return statInfoMap;
        }

        public void setStatInfoMap(Map<String, T> statInfoMap) {
            this.statInfoMap = statInfoMap;
        }

        public List<RedlineResultItem> getRedlineResult() {
            return redlineResult;
        }

        public void setRedlineResult(
                List<RedlineResultItem> redlineResult) {
            this.redlineResult = redlineResult;
        }
    }

    public static class RedlineResultItem {

        private String key;
        private Integer threshold;
        private Integer checkVal;
        private String type;
        private Boolean checked;
        private Boolean checkResult;

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public Integer getThreshold() {
            return threshold;
        }

        public void setThreshold(Integer threshold) {
            this.threshold = threshold;
        }

        public Integer getCheckVal() {
            return checkVal;
        }

        public void setCheckVal(Integer checkVal) {
            this.checkVal = checkVal;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public Boolean getChecked() {
            return checked;
        }

        public void setChecked(Boolean checked) {
            this.checked = checked;
        }

        public Boolean getCheckResult() {
            return checkResult;
        }

        public void setCheckResult(Boolean checkResult) {
            this.checkResult = checkResult;
        }
    }

    static class StatInfo implements Serializable {
        private static final long serialVersionUID = -7424772230982171781L;

        private String key;
        private String value;
        private String name;
        private String title;
        private String style;
        private String url;


        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getStyle() {
            return style;
        }

        public void setStyle(String style) {
            this.style = style;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public void setField(String fieldName, String value) {
            try {
                Field field = getClass().getDeclaredField(fieldName);
                field.set(this, value);
            } catch (Exception e) {
            }
        }
    }
}