loki修改
This commit is contained in:
@@ -25,16 +25,10 @@ public class LokiController {
|
||||
|
||||
private final LokiService lokiService;
|
||||
|
||||
@GetMapping("/labels")
|
||||
@GetMapping("/labels/values")
|
||||
@ApiOperation("获取标签")
|
||||
public ResponseEntity<Object> labels() {
|
||||
return new ResponseEntity<>(lokiService.getLabels(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/values")
|
||||
@ApiOperation("根据标签获取值")
|
||||
public ResponseEntity<Object> getAllValues(@RequestBody String label) {
|
||||
return new ResponseEntity<>(lokiService.getValuesByLabel(label), HttpStatus.OK);
|
||||
public ResponseEntity<Object> labelsValues() {
|
||||
return new ResponseEntity<>(lokiService.getLabelsValues(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/logs")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.nl.modules.loki.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
@@ -8,18 +9,6 @@ import com.alibaba.fastjson.JSONObject;
|
||||
* @Date: 2022-08-15
|
||||
*/
|
||||
public interface LokiService {
|
||||
/**
|
||||
* 获取日志的所有标签
|
||||
* @return
|
||||
*/
|
||||
JSONObject getLabels();
|
||||
|
||||
/**
|
||||
* 根据label获取值
|
||||
* @param label
|
||||
* @return
|
||||
*/
|
||||
JSONObject getValuesByLabel(String label);
|
||||
|
||||
/**
|
||||
* 获取日志信息
|
||||
@@ -27,4 +16,10 @@ public interface LokiService {
|
||||
* @return
|
||||
*/
|
||||
JSONObject getLogData(JSONObject json);
|
||||
|
||||
/**
|
||||
* 获取labels和values树
|
||||
* @return
|
||||
*/
|
||||
JSONArray getLabelsValues();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.nl.modules.loki.service.impl;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.loki.service.LokiService;
|
||||
@@ -23,20 +24,6 @@ public class LokiServiceImpl implements LokiService {
|
||||
@Value("${loki.systemName}")
|
||||
private String systemName;
|
||||
|
||||
@Override
|
||||
public JSONObject getLabels() {
|
||||
String result = HttpUtil.get(lokiUrl + "/labels", CharsetUtil.CHARSET_UTF_8);
|
||||
JSONObject parse = (JSONObject) JSONObject.parse(result);
|
||||
return parse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getValuesByLabel(String label) {
|
||||
String result = HttpUtil.get(lokiUrl + "/label/" + label + "/values", CharsetUtil.CHARSET_UTF_8);
|
||||
JSONObject parse = (JSONObject) JSONObject.parse(result);
|
||||
return parse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getLogData(JSONObject json) {
|
||||
String logLabel = "";
|
||||
@@ -78,4 +65,49 @@ public class LokiServiceImpl implements LokiService {
|
||||
return parse;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取labels和values树
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JSONArray getLabelsValues() {
|
||||
/**
|
||||
* [{
|
||||
* label:
|
||||
* value:
|
||||
* children:[{
|
||||
* label
|
||||
* value
|
||||
* }]
|
||||
* }]
|
||||
*/
|
||||
JSONArray result = new JSONArray();
|
||||
// 获取所有标签
|
||||
String labelString = HttpUtil.get(lokiUrl + "/labels", CharsetUtil.CHARSET_UTF_8);
|
||||
JSONObject parse = (JSONObject) JSONObject.parse(labelString);
|
||||
JSONArray labels = parse.getJSONArray("data");
|
||||
for (int i=0; i<labels.size(); i++) {
|
||||
// 获取标签下的所有值
|
||||
String valueString = HttpUtil.get(lokiUrl + "/label/" + labels.getString(i) + "/values", CharsetUtil.CHARSET_UTF_8);
|
||||
JSONObject parse2 = (JSONObject) JSONObject.parse(valueString);
|
||||
JSONArray values = parse2.getJSONArray("data");
|
||||
JSONArray children = new JSONArray();
|
||||
// 组成树形状态 两级
|
||||
for (int j=0; j<values.size(); j++) {
|
||||
JSONObject leaf = new JSONObject();
|
||||
leaf.put("label", values.getString(j));
|
||||
leaf.put("value", values.getString(j));
|
||||
children.add(leaf);
|
||||
}
|
||||
|
||||
JSONObject node = new JSONObject();
|
||||
node.put("label", labels.getString(i));
|
||||
node.put("value", labels.getString(i));
|
||||
node.put("children", children);
|
||||
result.add(node);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class LokiLogAspect {
|
||||
LokiLogType logType = lokiLog.type();
|
||||
|
||||
MDC.put("log_file_type", logType.name());
|
||||
log.info("入参:" + JSONObject.toJSONString(pjp.getArgs()));
|
||||
log.info("输入参数:" + JSONObject.toJSONString(pjp.getArgs()));
|
||||
|
||||
Object proceed = pjp.proceed();
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ public class OutController {
|
||||
@Log("套轴确认")
|
||||
@ApiOperation("套轴确认")
|
||||
public ResponseEntity<Object> confirm(@RequestBody JSONObject whereJson) {
|
||||
return new ResponseEntity<>(casingService.confirm(whereJson), HttpStatus.OK);
|
||||
casingService.confirm(whereJson);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user