add testcase
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,6 @@
|
|||||||
.classpath
|
.classpath
|
||||||
.project
|
.project
|
||||||
|
promql_client/.settings/
|
||||||
|
promql_client/target
|
||||||
|
promql_client_test/.settings/
|
||||||
|
promql_client_test/target
|
||||||
|
@ -18,6 +18,11 @@ public class DefaultQueryResult<T extends Data> extends Result<T>{
|
|||||||
public List<T> getResult() {
|
public List<T> getResult() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DefaultQueryResult [result=" + result + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class QueryResultItemValue {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ResultDataItemValue [timestamp=" + timestamp + ", value=" + value + "]";
|
return "QueryResultItemValue [timestamp=" + timestamp + ", value=" + value + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
40
promql_client_test/pom.xml
Normal file
40
promql_client_test/pom.xml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.bdwise.prometheus.client</groupId>
|
||||||
|
<artifactId>promql_client_test</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>promql_client_test</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.bdwise.prometheus.client</groupId>
|
||||||
|
<artifactId>promql_client</artifactId>
|
||||||
|
<version>0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>1.5.6.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,75 @@
|
|||||||
|
package com.bdwise.prometheus.client;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.builder.InstantQueryBuilder;
|
||||||
|
import com.bdwise.prometheus.client.builder.QueryBuilderType;
|
||||||
|
import com.bdwise.prometheus.client.builder.RangeQueryBuilder;
|
||||||
|
import com.bdwise.prometheus.client.converter.ConvertUtil;
|
||||||
|
import com.bdwise.prometheus.client.converter.query.DefaultQueryResult;
|
||||||
|
import com.bdwise.prometheus.client.converter.query.MatrixData;
|
||||||
|
import com.bdwise.prometheus.client.converter.query.VectorData;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class PromqlTest extends TestCase {
|
||||||
|
private final static String TARGET_SERVER = "http://52.192.4.59:30900";
|
||||||
|
|
||||||
|
private RestTemplate template = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
|
||||||
|
httpRequestFactory.setConnectTimeout(1000);
|
||||||
|
httpRequestFactory.setReadTimeout(2000);
|
||||||
|
HttpClient httpClient = HttpClientBuilder.create()
|
||||||
|
.setMaxConnTotal(100)
|
||||||
|
.setMaxConnPerRoute(10)
|
||||||
|
.build();
|
||||||
|
httpRequestFactory.setHttpClient(httpClient);
|
||||||
|
|
||||||
|
template = new RestTemplate(httpRequestFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimpleRangeQuery() throws MalformedURLException {
|
||||||
|
RangeQueryBuilder rangeQueryBuilder = QueryBuilderType.RangeQuery.newInstance(TARGET_SERVER);
|
||||||
|
URI targetUri = rangeQueryBuilder.withQuery("irate(received_api_call_total[60s])")
|
||||||
|
.withStartEpochTime(System.currentTimeMillis() / 1000 - 60*10)
|
||||||
|
.withEndEpochTime(System.currentTimeMillis() / 1000)
|
||||||
|
.withStepTime("60s")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
|
||||||
|
String rtVal = template.getForObject(targetUri, String.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DefaultQueryResult<MatrixData> result = ConvertUtil.convertQueryResultString(rtVal);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimpleInstantQuery() throws MalformedURLException {
|
||||||
|
InstantQueryBuilder iqb = QueryBuilderType.InstantQuery.newInstance(TARGET_SERVER);
|
||||||
|
URI targetUri = iqb.withQuery("irate(received_api_call_total[60s])").build();
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
|
||||||
|
|
||||||
|
String rtVal = template.getForObject(targetUri, String.class);
|
||||||
|
|
||||||
|
|
||||||
|
DefaultQueryResult<VectorData> result = ConvertUtil.convertQueryResultString(rtVal);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user