Skip to content

Commit

Permalink
This is a combination of 12 commits.
Browse files Browse the repository at this point in the history
The first commit's message is:

Catch parse exception so that a proper response can be built

This is the 2nd commit message:

Use plain text error messages as Influx does

This is the 3rd commit message:

Import changes from rx-migration branch to ease future merge

This is the 4th commit message:

Fixed list series output bug

Also, make sure Influx tests never fail because of data conflict (user distinct tenantId/dbName)

This is the 5th commit message:

Import changes from rx-migration branch to ease future merge

This is the 6th commit message:

Fix PrettyInterceptor: InfluxHandler may have changed the media type

This is the 7th commit message:

Support absolute moment operands in queries. For example:

select * from test where time > 1501560s and time < 4560546h

It's like using a date operand, but with timestamps.

This is the 8th commit message:

Change ptrans log level in development config file

This is the 9th commit message:

Add empty collections/arrays to JSON output

This is the 10th commit message:

Minor change in "pretty" filter and interceptor

This is the 11th commit message:

Checkstyle fixes

This is the 12th commit message:

Revert change in JacksonConfig to avoid failing itests

But configure InfluxObject explicitly to include empty points collection in JSON output
  • Loading branch information
tsegismont committed May 19, 2015
1 parent 6c91134 commit 9135f3c
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ booleanExpression: operand '=' operand #eqExpression
;

operand: prefix? name #nameOperand
| TIMESPAN #absoluteMomentOperand
| ID '(' ')' DASH TIMESPAN #pastMomentOperand
| ID '(' ')' PLUS TIMESPAN #futureMomentOperand
| ID '(' ')' #presentMomentOperand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
package org.hawkular.metrics.api.jaxrs.influx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Transfer object which is returned by Influx queries
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class InfluxObject {
private final String name;
private final List<String> columns;
Expand All @@ -35,7 +38,7 @@ private InfluxObject(@JsonProperty("name") String name, @JsonProperty("columns")
@JsonProperty("points") List<List<?>> points) {
this.name = name;
this.columns = columns;
this.points = points;
this.points = points == null ? Collections.emptyList() : points;
}

public String getName() {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.hawkular.metrics.api.jaxrs.influx.prettyprint;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;

import java.io.IOException;

import javax.ws.rs.container.ContainerRequestContext;
Expand All @@ -39,8 +37,7 @@ public class PrettyFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
UriInfo uriInfo = requestContext.getUriInfo();
if (!APPLICATION_JSON_TYPE.equals(requestContext.getMediaType())
|| !uriInfo.getPath().startsWith("/db")) {
if (!uriInfo.getPath().startsWith("/db")) {
return;
}
requestContext.setProperty(PRETTY_PRINT, Boolean.valueOf(uriInfo.getQueryParameters().getFirst("pretty")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static java.lang.Boolean.TRUE;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;

import static org.hawkular.metrics.api.jaxrs.influx.prettyprint.PrettyFilter.PRETTY_PRINT;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -52,7 +54,7 @@ public PrettyInterceptor() {

@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
if (context.getProperty(PRETTY_PRINT) != TRUE) {
if (context.getProperty(PRETTY_PRINT) != TRUE || !APPLICATION_JSON_TYPE.equals(context.getMediaType())) {
context.proceed();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.antlr.v4.runtime.misc.NotNull;
import org.hawkular.metrics.api.jaxrs.influx.query.parse.InfluxQueryBaseListener;
import org.hawkular.metrics.api.jaxrs.influx.query.parse.InfluxQueryParser;
import org.joda.time.Instant;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -256,6 +258,18 @@ public void exitNameOperand(@NotNull NameOperandContext ctx) {
name = null;
}

@Override
public void exitAbsoluteMomentOperand(InfluxQueryParser.AbsoluteMomentOperandContext ctx) {
String timespan = ctx.TIMESPAN().getText();
int amount = Integer.parseInt(timespan.substring(0, timespan.length() - 1));
char unitId = timespan.charAt(timespan.length() - 1);
InfluxTimeUnit unit = InfluxTimeUnit.findById(unitId);
if (unit == null) {
throw new RuntimeException("Unknown time unit: " + unitId);
}
operandQueue.addLast(new DateOperand(new Instant(unit.convertTo(TimeUnit.MILLISECONDS, amount))));
}

@Override
public void exitPastMomentOperand(@NotNull PastMomentOperandContext ctx) {
String functionName = ctx.ID().getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ select mean(a.value) from c as a where time < now() - 50w
select a.value as b from c as a where time < '2011-07-28' and time > now() + 50w
select a.value as b from c as a where '2011-07-28' < a.time and now() + 50w > a.time
select a.value as b from c as a where '2011-07-28' > a.time and now() + 50w < a.time
select * from test where time > 1501560s and time < 4560546h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ select percentile("d", .95) from a
SeleCt dup.time as now, _agjsqdha(clui) as p from z as bi group by time(15s)
SeleCt dup.time as now, _agjsqdha(clui) as p from z as bi group by time(15s) where time > now() -15s
SeleCt dup.time as now, _agjsqdha(clui, -5, -33.1) as p from z as bi group by time(15s) where time > now() -15s and a=-.33
select * from test where time > 1501560s and time < 4560546h
SeleCt dup.a fROm "z" as bi order desc
SeleCt dup.b fROm "z" as bi order asc
2 changes: 1 addition & 1 deletion clients/ptranslator/log4j-dev.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</appender>

<root>
<level value="TRACE"/>
<level value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,48 @@
*/
package org.hawkular.metrics.rest

import org.joda.time.DateTime
import org.junit.Test

import static org.joda.time.DateTime.now
import static org.junit.Assert.assertEquals

import org.joda.time.DateTime
import org.junit.Test

/**
* @author Thomas Segismont
*/
class InfluxITest extends RESTTest {

static def tenantId = "influxtest"
@Test
void testListSeries() {
def tenantId = nextTenantId()

postData(tenantId, "serie1", now())
postData(tenantId, "serie2", now())

def response = hawkularMetrics.get(path: "db/${tenantId}/series", query: [q: "list series"])
assertEquals(200, response.status)

assertEquals(
[
[
name : "list_series_result",
columns: ["time", "name"],
points : [
[0, "serie1"],
[0, "serie2"],
]
]
],
response.data
)
}

@Test
void testInfluxDataOrderedAsc() {
def tenantId = nextTenantId()
def timeseriesName = "influx.dataasc"
def start = now().minus(4000)
postData(timeseriesName, start)
postData(tenantId, timeseriesName, start)

def influxQuery = 'select value from "' + timeseriesName + '" order asc'

Expand All @@ -60,9 +84,10 @@ class InfluxITest extends RESTTest {

@Test
void testInfluxDataOrderedDescByDefault() {
def tenantId = nextTenantId()
def timeseriesName = "influx.datadesc"
def start = now().minus(4000)
postData(timeseriesName, start)
postData(tenantId, timeseriesName, start)

def influxQuery = 'select value from "' + timeseriesName + '"'

Expand All @@ -89,9 +114,10 @@ class InfluxITest extends RESTTest {

@Test
void testInfluxAddGetOneMetric() {
def tenantId = nextTenantId()
def timeseriesName = "influx.foo"
def start = now().minus(4000)
postData(timeseriesName, start)
postData(tenantId, timeseriesName, start)

def influxQuery = 'select mean(value) from "' + timeseriesName + '" where time > now() - 30s group by time(30s) '

Expand All @@ -114,9 +140,10 @@ class InfluxITest extends RESTTest {

@Test
void testInfluxLimitClause() {
def tenantId = nextTenantId()
def timeseriesName = "influx.limitclause"
def start = now().minus(4000)
postData(timeseriesName, start)
postData(tenantId, timeseriesName, start)

def influxQuery = 'select value from "' + timeseriesName + '" limit 2 order asc '

Expand All @@ -140,9 +167,10 @@ class InfluxITest extends RESTTest {

@Test
void testInfluxAddGetOneSillyMetric() {
def tenantId = nextTenantId()
def timeseriesName = "influx.foo3"
def start = now().minus(4000)
postData(timeseriesName, start)
postData(tenantId, timeseriesName, start)

def influxQuery = 'select mean(value) from "' + timeseriesName + '''" where time > '2013-08-12 23:32:01.232'
and time < '2013-08-13' group by time(30s) '''
Expand All @@ -155,7 +183,8 @@ class InfluxITest extends RESTTest {
[
[
columns: ["time", "mean"],
name: timeseriesName
name: timeseriesName,
points: []
]
],
response.data
Expand All @@ -164,9 +193,10 @@ class InfluxITest extends RESTTest {

@Test
void testInfluxTop() {
def tenantId = nextTenantId()
def timeseriesName = "influx.top"
def start = now().minus(4000)
postData(timeseriesName, start)
postData(tenantId, timeseriesName, start)

def influxQuery = 'select top(value, 3) from "' + timeseriesName + '" where time > now() - 30s group by time(30s)'

Expand All @@ -190,9 +220,10 @@ class InfluxITest extends RESTTest {
}
@Test
void testInfluxBottom() {
def tenantId = nextTenantId()
def timeseriesName = "influx.bottom"
def start = now().minus(4000)
postData(timeseriesName, start)
postData(tenantId, timeseriesName, start)

def influxQuery = 'select bottom(value, 3) from "' + timeseriesName + '" where time > now() - 30s group by time(30s)'

Expand All @@ -217,9 +248,10 @@ class InfluxITest extends RESTTest {

@Test
void testInfluxStddev() {
def tenantId = nextTenantId()
def timeseriesName = "influx.stddev"
def start = now().minus(4000)
postData(timeseriesName, start)
postData(tenantId, timeseriesName, start)

def influxQuery = 'select stddev(value) from "' + timeseriesName + '" where time > now() - 30s group by time(30s)'

Expand All @@ -240,7 +272,7 @@ class InfluxITest extends RESTTest {
)
}

private static void postData(String timeseriesName, DateTime start) {
private static void postData(String tenantId, String timeseriesName, DateTime start) {
def response = hawkularMetrics.post(path: "db/${tenantId}/series", body: [
[
name: timeseriesName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.hawkular.metrics.test;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
Expand All @@ -25,14 +26,18 @@
* @author Jeeva Kandasamy
*/
public class InfluxDBTest {
private static final String TENANT_PREFIX = UUID.randomUUID().toString();
private static final AtomicInteger TENANT_ID_COUNTER = new AtomicInteger(0);

static String baseURI = System.getProperty("hawkular-metrics.base-uri", "127.0.0.1:8080/hawkular/metrics");
static final String DB_PREFIX = UUID.randomUUID().toString();
static InfluxDB influxDB = null;
static InfluxDB influxDB;

@BeforeClass
public static void initClient() {
if(influxDB == null){
influxDB = InfluxDBFactory.connect("http://"+baseURI+"/", "hawkular", "hawkular");
}
}

static String nextTenantId() {
return "T" + TENANT_PREFIX + TENANT_ID_COUNTER.incrementAndGet();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author Jeeva Kandasamy
*/
public class InfluxDatabaseITest extends InfluxDBTest {
private static String dbName = DB_PREFIX + "influxdbjavaclienttest";
private String dbName = nextTenantId();

/**
* Test that writing of a simple Serie works.
Expand All @@ -48,7 +48,6 @@ public void testQueryOrderedAsc() {
long startTime = System.currentTimeMillis();
Serie generatedSerie = getSerie(timeSeries, startTime);
influxDB.write(dbName, TimeUnit.MILLISECONDS, generatedSerie);
startTime = startTime - 9000L;
List<Serie> series = influxDB.query(dbName,
"select value from " + timeSeries + " order asc",
TimeUnit.MILLISECONDS);
Expand Down Expand Up @@ -224,7 +223,7 @@ private void assertSeriesEquals(Serie serieOne, Serie serieTwo) {

private static Serie getSerie(String timeSeries, long startTime) {
startTime = startTime - 9000L;//Minus N milliseconds from 'start time' based on number of rows going to write.
Serie serie = new Serie.Builder(timeSeries)
return new Serie.Builder(timeSeries)
.columns("time", "value")
.values(startTime, 10.9)
.values(startTime + 1000L, 11.9)
Expand All @@ -236,6 +235,5 @@ private static Serie getSerie(String timeSeries, long startTime) {
.values(startTime + 7000L, 17.9)
.values(startTime + 8000L, 18.9)
.build();
return serie;
}
}

0 comments on commit 9135f3c

Please sign in to comment.