-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
213 additions
and
2 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
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
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
...home-web/src/test/java/io/holoinsight/server/home/web/controller/QueryFacadeImplTest.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 @@ | ||
/* | ||
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. | ||
*/ | ||
package io.holoinsight.server.home.web.controller; | ||
|
||
import io.holoinsight.server.common.J; | ||
import io.holoinsight.server.common.dao.entity.MetricInfo; | ||
import io.holoinsight.server.common.model.DataQueryRequest; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author masaimu | ||
* @version 2023-08-10 14:56:00 | ||
*/ | ||
public class QueryFacadeImplTest { | ||
|
||
@Test | ||
public void name() { | ||
String json = | ||
"{\"start\":1691644303000,\"end\":1691647903000,\"name\":\"a\",\"metric\":\"k8s_pod_mem_util\",\"groupBy\":[\"app\",\"hostname\",\"workspace\",\"pod\",\"ip\",\"namespace\"],\"filters\":[{\"type\":\"literal_or\",\"name\":\"app\",\"value\":\"holoinsight-server|aaaaa\"},{\"type\":\"literal\",\"name\":\"应用ID\",\"value\":\"111111111\"},{\"type\":\"literal\",\"name\":\"fake应用ID\",\"value\":\"22222222\"}]}"; | ||
DataQueryRequest.QueryDataSource queryDataSource = | ||
J.fromJson(json, DataQueryRequest.QueryDataSource.class); | ||
MetricInfo metricInfo = new MetricInfo(); | ||
metricInfo.setTags(J.toJson(Arrays.asList("app", "应用ID"))); | ||
QueryFacadeImpl queryFacade = new QueryFacadeImpl(); | ||
queryFacade.parseQl(queryDataSource, metricInfo); | ||
System.out.println(queryDataSource.ql); | ||
Assert.assertTrue(StringUtils.equals( | ||
"select count(1) as value , `period` from k8s_pod_mem_util where `period` <= 1691647903000 and `period` >= 1691644303000 and `app` in ('holoinsight-server','aaaaa') and `应用ID` = '111111111' group by `period` , `app` order by `period` asc", | ||
queryDataSource.ql)); | ||
|
||
json = | ||
"{\"start\":1691644303000,\"end\":1691647903000,\"name\":\"a\",\"metric\":\"k8s_pod_mem_util\",\"groupBy\":[\"app\",\"hostname\",\"workspace\",\"pod\",\"ip\",\"namespace\"],\"filters\":[{\"type\":\"literal_or\",\"name\":\"app\",\"value\":\"holoinsight-server|aaaaa\"},{\"type\":\"literal\",\"name\":\"应用ID\",\"value\":\"111111111\"},{\"type\":\"literal\",\"name\":\"fake应用ID\",\"value\":\"22222222\"}],\"select\":{\"app\":null,\"dd\":\"distinct(`aaa`)\"}}"; | ||
queryDataSource = J.fromJson(json, DataQueryRequest.QueryDataSource.class); | ||
metricInfo = new MetricInfo(); | ||
metricInfo.setTags(J.toJson(Arrays.asList("app", "应用ID"))); | ||
queryFacade = new QueryFacadeImpl(); | ||
queryFacade.parseQl(queryDataSource, metricInfo); | ||
System.out.println(queryDataSource.ql); | ||
Assert.assertTrue(StringUtils.equals( | ||
"select `app` , distinct(`aaa`) as dd , `period` from k8s_pod_mem_util where `period` <= 1691647903000 and `period` >= 1691644303000 and `app` in ('holoinsight-server','aaaaa') and `应用ID` = '111111111' group by `period` , `app` order by `period` asc", | ||
queryDataSource.ql)); | ||
} | ||
} |