You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/11/17 01:58:18 UTC

[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4167: [IOTDB-1851] Optimize iot-grafana code and fix some bugs

SteveYurongSu commented on a change in pull request #4167:
URL: https://github.com/apache/iotdb/pull/4167#discussion_r750823625



##########
File path: grafana/src/main/java/org/apache/iotdb/web/grafana/controller/DatabaseConnectController.java
##########
@@ -69,15 +68,12 @@ public void testDataConnection(HttpServletResponse response) throws IOException
   /**
    * get metrics numbers in JSON string structure.
    *
-   * @param request http request
-   * @param response http response
    * @return metrics numbers in JSON string structure
    */
   @RequestMapping(value = "/search")
   @ResponseBody
-  public String metricFindQuery(HttpServletRequest request, HttpServletResponse response) {
+  public String metricFindQuery() {

Review comment:
       Why can we make this change here?

##########
File path: grafana/src/main/java/org/apache/iotdb/web/grafana/controller/DatabaseConnectController.java
##########
@@ -88,58 +84,52 @@ public String metricFindQuery(HttpServletRequest request, HttpServletResponse re
     for (int i = 0; i < columnsName.size(); i++) {
       root.addProperty(String.valueOf(i), columnsName.get(i));
     }
-
     return root.toString();
   }
 
   /**
-   * convert query result data to JSON format.
+   * query and return data in JSON format.
    *
-   * @param request http request
-   * @param response http response
    * @return data in JSON format
    */
   @RequestMapping(value = "/query")
   @ResponseBody
-  public String query(HttpServletRequest request, HttpServletResponse response) {
+  public String query(@RequestBody String json) {
     String targetStr = "target";
-    response.setStatus(200);
     try {
-      JsonObject jsonObject = getRequestBodyJson(request);
+      JsonObject jsonObject = GSON.fromJson(json, JsonObject.class);
       if (Objects.isNull(jsonObject)) {
         return null;
       }
-
       Pair<ZonedDateTime, ZonedDateTime> timeRange = getTimeFromAndTo(jsonObject);
-      JsonArray array = (JsonArray) jsonObject.get("targets"); // []
+      JsonArray array = jsonObject.getAsJsonArray("targets");
       JsonArray result = new JsonArray();
       for (int i = 0; i < array.size(); i++) {
-        JsonObject object = array.get(i).getAsJsonObject(); // {}
+        JsonObject object = array.get(i).getAsJsonObject();
         if (!object.has(targetStr)) {
-          return "[]";
+          continue;

Review comment:
       It's different from `return "[]"`, right?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org