From a2d4b13cecf9239a8c7f361692a6606dd0aee0a3 Mon Sep 17 00:00:00 2001 From: Dr-kyle <13636814471@163.com> Date: Sun, 10 May 2020 14:31:50 +0800 Subject: [PATCH] job detail page fix bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 优化jobdetail页面Key Prefix Info和TTL请求分别发2次问题 2. 优化jobdetail页面发送无用的获取数据请求 3. 优化jobdetail页面key过长时表格分页无法显示问题 4. 优化jobdetail页面非cluster分析结果时还发送折线图请求数据的问题 5. 修复jobdetail页面出现与非cluster分析结果对比的问题 6. 优化jobdetail页面折线图显示效果 7. jobdetail页面增加折线图可以选择前缀的功能 --- .gitignore | 2 + .../controller/RDBAnalyzeController.java | 55 +++---- .../plugin/alert/dao/IAlertChannelDao.java | 2 - .../service/IRdbAnalyzeResultService.java | 3 +- .../service/impl/RdbAnalyzeResultService.java | 77 ++++++---- .../redis-manager-vue/src/api/rctapi.js | 6 +- .../src/components/rct/JobResultDetail.vue | 42 +++++- .../components/rct/chart/PrefixKeysCount.vue | 139 ++++++++---------- .../components/rct/chart/PrefixKeysMemory.vue | 139 +++++++++--------- .../src/components/rct/chart/Table.vue | 32 ++-- .../rct/chart/Top1000KeysByTypeTable.vue | 6 +- 11 files changed, 263 insertions(+), 240 deletions(-) diff --git a/.gitignore b/.gitignore index 827b97f7..16794601 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ selenium-debug.log *.njsproj *.sln redis-manger-ui/redis-manager-vue/package-lock.json +redis-manager-dashboard/logs/ +redis-manager-dashboard/logs/ diff --git a/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/controller/RDBAnalyzeController.java b/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/controller/RDBAnalyzeController.java index ba127684..cccff5a1 100644 --- a/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/controller/RDBAnalyzeController.java +++ b/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/controller/RDBAnalyzeController.java @@ -1,6 +1,5 @@ package com.newegg.ec.redis.controller; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.newegg.ec.redis.entity.*; @@ -257,34 +256,24 @@ public Result getAllScheduleId(@RequestParam Long analyzeResultId) { } } -// /** -// * get all key_prefix -// * -// * @param clusterId -// * @param scheduleId -// * @return -// */ -// @GetMapping("/all/key_prefix") -// public Result getAllKeyPrefix(@RequestParam Long clusterId, @RequestParam(value = "scheduleId", required = false) Long scheduleId) { -// try { -// if (null == clusterId) { -// return Result.failResult("clusterId should not null!"); -// } -// RDBAnalyzeResult rdbAnalyzeResult; -// if(null != scheduleId){ -// rdbAnalyzeResult = rdbAnalyzeResultService.selectResultByRIDandSID(clusterId, scheduleId); -// } else { -// rdbAnalyzeResult = rdbAnalyzeResultService.selectLatestResultByRID(clusterId); -// } -// if(null == rdbAnalyzeResult) { -// return Result.successResult(null); -// } -// return Result.successResult(rdbAnalyzeResultService.getAllKeyPrefixByResult(rdbAnalyzeResult.getResult())); -// } catch (Exception e) { -// LOG.error("getAllKey_prefix failed!", e); -// return Result.failResult("getAllKey_prefix failed!"); -// } -// } + /** + * get all key_prefix + * + * @param analyzeResultId + * @return + */ + @GetMapping("/all/key_prefix") + public Result getAllKeyPrefix(@RequestParam Long analyzeResultId) { + try { + if (null == analyzeResultId) { + return Result.failResult("analyzeResultId should not null!"); + } + return Result.successResult(rdbAnalyzeResultService.getAllKeyPrefixById(analyzeResultId)); + } catch (Exception e) { + LOG.error("getAllKey_prefix failed!", e); + return Result.failResult("getAllKey_prefix failed!"); + } + } /** @@ -367,9 +356,13 @@ public Result getPrefixKeyByMem(@RequestParam Long analyzeResultId, */ @GetMapping("/line/prefix/{type}") public Result getPrefixLineByCountOrMem(@PathVariable String type, @RequestParam Long analyzeResultId, - @RequestParam(value = "prefixKey", required = false) String prefixKey) { + @RequestParam(value = "prefixKey", required = false) String prefixKey, + @RequestParam(value = "top", required = false) Integer top) { try { - JSONArray result = rdbAnalyzeResultService.getPrefixLineByCountOrMem(analyzeResultId, type, 20, prefixKey); + if (null == top || top == 0) { + top = 10; + } + JSONObject result = rdbAnalyzeResultService.getPrefixLineByCountOrMem(analyzeResultId, type, top, prefixKey); return Result.successResult(result); } catch (Exception e) { diff --git a/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/plugin/alert/dao/IAlertChannelDao.java b/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/plugin/alert/dao/IAlertChannelDao.java index 07db922a..3ab735c1 100644 --- a/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/plugin/alert/dao/IAlertChannelDao.java +++ b/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/plugin/alert/dao/IAlertChannelDao.java @@ -1,9 +1,7 @@ package com.newegg.ec.redis.plugin.alert.dao; import com.newegg.ec.redis.plugin.alert.entity.AlertChannel; -import jdk.nashorn.internal.objects.annotations.Where; import org.apache.ibatis.annotations.*; -import org.springframework.stereotype.Component; import java.util.List; diff --git a/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/service/IRdbAnalyzeResultService.java b/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/service/IRdbAnalyzeResultService.java index c82fa24b..e4c9c9ce 100644 --- a/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/service/IRdbAnalyzeResultService.java +++ b/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/service/IRdbAnalyzeResultService.java @@ -1,6 +1,7 @@ package com.newegg.ec.redis.service; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.newegg.ec.redis.entity.Cluster; import com.newegg.ec.redis.entity.RDBAnalyze; import com.newegg.ec.redis.entity.RDBAnalyzeResult; @@ -16,7 +17,7 @@ public interface IRdbAnalyzeResultService { List selectList(Long groupId); RDBAnalyzeResult reportDataWriteToDb(RDBAnalyze rdbAnalyze, Map> data); Object getListStringFromResult(Long analyzeResultId, String key) throws Exception; - JSONArray getPrefixLineByCountOrMem(Long analyzeResultId, String type, int top, String prefixKey); + JSONObject getPrefixLineByCountOrMem(Long analyzeResultId, String type, int top, String prefixKey); JSONArray getPrefixType(Long analyzeResultId) throws Exception; Map getReportDataLatest(Long clusterId); void createRdbAnalyzeResultTable(); diff --git a/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/service/impl/RdbAnalyzeResultService.java b/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/service/impl/RdbAnalyzeResultService.java index c2fba170..52868acf 100644 --- a/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/service/impl/RdbAnalyzeResultService.java +++ b/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/service/impl/RdbAnalyzeResultService.java @@ -238,32 +238,41 @@ public RDBAnalyzeResult reportDataWriteToDb(RDBAnalyze rdbAnalyze, Map + */ + public List getAllKeyPrefixById(Long analyzeResultId) { + RDBAnalyzeResult result = selectResultById(analyzeResultId); + return getAllKeyPrefixByResult(result.getResult()); + } -// /** -// * get list keyPrefix -// * @param result result -// * @return List keyPrefix -// */ -// public List getAllKeyPrefixByResult(String result){ -// List resultJsonObj = new ArrayList<>(500); -// if(null == result || "".equals(result.trim())) { -// return resultJsonObj; -// } -// JSONArray jsonArray = getJSONArrayFromResultByKey(result, IAnalyzeDataConverse.PREFIX_KEY_BY_COUNT); -// if(null == jsonArray) { -// return resultJsonObj; -// } -// JSONObject oneRow; -// JSONObject jsonObject; -// for(Object obj : jsonArray) { -// oneRow = (JSONObject) obj; -// jsonObject = new JSONObject(); -// jsonObject.put("value", oneRow.getString("prefixKey")); -// jsonObject.put("label", oneRow.getString("prefixKey")); -// resultJsonObj.add(jsonObject); -// } -// return resultJsonObj; -// } + /** + * get list keyPrefix + * @param result result + * @return List keyPrefix + */ + private List getAllKeyPrefixByResult(String result){ + List resultJsonObj = new ArrayList<>(500); + if(null == result || "".equals(result.trim())) { + return resultJsonObj; + } + JSONArray jsonArray = getJSONArrayFromResultByKey(result, IAnalyzeDataConverse.PREFIX_KEY_BY_COUNT); + if(null == jsonArray) { + return resultJsonObj; + } + JSONObject oneRow; + JSONObject jsonObject; + for(Object obj : jsonArray) { + oneRow = (JSONObject) obj; + jsonObject = new JSONObject(); + jsonObject.put("value", oneRow.getString("prefixKey")); + jsonObject.put("label", oneRow.getString("prefixKey")); + resultJsonObj.add(jsonObject); + } + return resultJsonObj; + } // /** // * gong zhe xian tu shi yong, @@ -363,7 +372,8 @@ private JSONArray getTopKeyFromResultByKey(String result, Long startNum) { * @return JSONArray */ @Override - public JSONArray getPrefixLineByCountOrMem(Long analyzeResultId, String type, int top, String prefixKey) { + public JSONObject getPrefixLineByCountOrMem(Long analyzeResultId, String type, int top, String prefixKey) { + JSONObject jsonResultObject = new JSONObject(); String sortColumn = getSortColumn(type); // RDBAnalyzeResult rdbAnalyzeLatestResult = selectLatestResultByRID(clusterId); RDBAnalyzeResult rdbAnalyzeLatestResult = selectResultById(analyzeResultId); @@ -382,6 +392,15 @@ public JSONArray getPrefixLineByCountOrMem(Long analyzeResultId, String type, in // except Latest RDBAnalyzeResult List rdbAnalyzeResultList = selectRecentlyResultByIdExceptSelf(analyzeResultId, rdbAnalyzeLatestResult.getClusterId(), rdbAnalyzeLatestResult.getScheduleId()); + // 过滤掉非集群模式的分析结果 + rdbAnalyzeResultList = rdbAnalyzeResultList.stream().filter(rdbAnalyzeResult -> { + JSONObject object = JSONObject.parseObject(rdbAnalyzeResult.getAnalyzeConfig()); + JSONArray array = object.getJSONArray("nodes"); + if (array.size() == 1 && "-1".equals(array.getString(0))) { + return true; + } + return false; + }).collect(Collectors.toList()); // key :prefixKey Map> resultMap = new HashMap<>(7); Map latest = getMapJSONByResult(rdbAnalyzeLatestResult, arrayResult); @@ -423,7 +442,9 @@ public JSONArray getPrefixLineByCountOrMem(Long analyzeResultId, String type, in arrayJsonObj.put("key", prefix); result.add(arrayJsonObj); } - return result; + jsonResultObject.put("time", scheduleList); + jsonResultObject.put("data", result); + return jsonResultObject; } @@ -458,7 +479,7 @@ private Map getMapJSONByResult(RDBAnalyzeResult rdbAnalyzeRe private List getcolumnKeyList(String prefixKey, List resultObjecList, String columnName, int top) { List prefixKeyList = new ArrayList<>(10); - if (null == prefixKey) { + if (null == prefixKey || "".equals(prefixKey)) { if (top == -1) { top = resultObjecList.size(); } diff --git a/redis-manager-ui/redis-manager-vue/src/api/rctapi.js b/redis-manager-ui/redis-manager-vue/src/api/rctapi.js index 9e71d7fc..dc025e96 100644 --- a/redis-manager-ui/redis-manager-vue/src/api/rctapi.js +++ b/redis-manager-ui/redis-manager-vue/src/api/rctapi.js @@ -113,9 +113,9 @@ export const getAnalyzeResults = (groupId) => RCTAPI(`/rdb/results?groupId=${gro export const getPieByType = (analyzeResultId) => RCTAPI('/rdb/chart/DataTypeAnalyze', 'GET', {analyzeResultId}) -export const getPrefixKeysCount = (analyzeResultId) => RCTAPI('/rdb/line/prefix/PrefixKeyByCount', 'GET', {analyzeResultId}) +export const getPrefixKeysCount = (analyzeResultId, prefixKey) => RCTAPI('/rdb/line/prefix/PrefixKeyByCount', 'GET', {analyzeResultId, prefixKey}) -export const getPrefixKeysMemory = (analyzeResultId) => RCTAPI('/rdb/line/prefix/PrefixKeyByMemory', 'GET', {analyzeResultId}) +export const getPrefixKeysMemory = (analyzeResultId, prefixKey) => RCTAPI('/rdb/line/prefix/PrefixKeyByMemory', 'GET', {analyzeResultId, prefixKey}) export const getTop1000KeysByPrefix = (analyzeResultId) => API('/rdb/table/prefix', 'GET', {analyzeResultId}) @@ -136,3 +136,5 @@ export const getTimeData = (analyzeResultId) => RCTAPI('/rdb/all/schedule_id', ' export const getScheduleDetail = (id) => API(`/rdb/schedule_detail/${id}`) export const cancelAnalyzeTask = (id, scheduleID) => API(`/rdb/cance_job/${id}/${scheduleID}`) + +export const getSelectKeys = (analyzeResultId) => RCTAPI('/rdb/all/key_prefix', 'GET', { analyzeResultId }) diff --git a/redis-manager-ui/redis-manager-vue/src/components/rct/JobResultDetail.vue b/redis-manager-ui/redis-manager-vue/src/components/rct/JobResultDetail.vue index 4f17d2a6..4e494dd4 100644 --- a/redis-manager-ui/redis-manager-vue/src/components/rct/JobResultDetail.vue +++ b/redis-manager-ui/redis-manager-vue/src/components/rct/JobResultDetail.vue @@ -8,8 +8,22 @@ - - +
+ + + + + + + + + + +
@@ -27,7 +41,8 @@ import KeyByTypePie from '@/components/rct/chart/KeyByTypePie' import Top1000KeysByType from '@/components/rct/chart/Top1000KeysByType' import Tables from '@/components/rct/chart/Table' import { formatBytes, formatterInput } from '@/utils/format.js' -import { getTop1000KeysByPrefix, getKeysTTLInfo } from '@/api/rctapi.js' +import { getTop1000KeysByPrefix, getKeysTTLInfo, getSelectKeys } from '@/api/rctapi.js' +import { error } from 'highcharts' export default { beforeCreate: function () { document.querySelector('body').setAttribute('style', 'overflow:auto') @@ -45,6 +60,8 @@ export default { data () { return { + selectPrefixValue: '', + selectOptions: [], isCluster: '', analyseResults: [], name: '', @@ -52,7 +69,9 @@ export default { columns: [{ label: 'Prefix', type: 'String', - prop: 'prefixKey' + prop: 'prefixKey', + show_tooltip: true, + min_width: '200px' }, { label: 'Count', sort: true, @@ -68,13 +87,15 @@ export default { }], searchVis: true, searchColumn: 'prefixKey', - title: 'Top 1000 Largest Keys By Custom Prefixes' + title: 'Key Prefix Info' }, keysTTL: { columns: [{ label: 'Prefix', prop: 'prefix', - type: 'String' + type: 'String', + show_tooltip: true, + min_width: '200px' }, { label: 'TTL', sort: true, @@ -126,6 +147,15 @@ export default { let analyzeConfigObj = JSON.parse(analyzeConfig) if (!analyzeConfigObj.nodes || analyzeConfigObj.nodes[0] === '-1') { this.isCluster = true + getSelectKeys(this.resultId).then(res => { + if (res.code === 0) { + this.selectOptions = res.data + } else { + console.error(res.message) + } + }).catch(error => { + console.error(error) + }) } else { this.isCluster = false } diff --git a/redis-manager-ui/redis-manager-vue/src/components/rct/chart/PrefixKeysCount.vue b/redis-manager-ui/redis-manager-vue/src/components/rct/chart/PrefixKeysCount.vue index c0ec149a..d7d41f9d 100644 --- a/redis-manager-ui/redis-manager-vue/src/components/rct/chart/PrefixKeysCount.vue +++ b/redis-manager-ui/redis-manager-vue/src/components/rct/chart/PrefixKeysCount.vue @@ -1,132 +1,113 @@