use of com.srotya.sidewinder.core.functions.list.Function in project sidewinder by srotya.
the class GrafanaUtils method extractTargetsFromJson.
/**
* Extract target series from Grafana Json query payload
*
* @param json
* @param targetSeries
* @throws InvalidFilterException
*/
public static void extractTargetsFromJson(JsonObject json, List<TargetSeries> targetSeries) throws InvalidFilterException {
JsonArray targets = json.get("targets").getAsJsonArray();
for (int i = 0; i < targets.size(); i++) {
JsonObject jsonElement = targets.get(i).getAsJsonObject();
if (jsonElement == null) {
continue;
}
if (jsonElement.has("target") && jsonElement.has("field")) {
TagFilter filter = extractGrafanaFilter(jsonElement);
Function aggregationFunction = extractGrafanaAggregation(jsonElement);
FunctionIteratorFactory functionIterator = extractGrafanaFunction(jsonElement);
boolean correlate = false;
if (jsonElement.has("correlate")) {
correlate = jsonElement.get("correlate").getAsBoolean();
}
TargetSeries e = new TargetSeries(jsonElement.get("target").getAsString(), jsonElement.get("field").getAsString(), filter, aggregationFunction, correlate, functionIterator);
targetSeries.add(e);
logger.log(Level.FINE, () -> "Parsed and extracted target:" + e);
} else if (jsonElement.has("raw") && jsonElement.get("rawQuery").getAsBoolean()) {
// raw query recieved
TargetSeries e;
try {
e = MiscUtils.extractTargetFromQuery(jsonElement.get("raw").getAsString());
} catch (Exception e1) {
throw new InvalidFilterException("Bad function expression:" + jsonElement.get("raw").getAsString() + " reason:" + e1.getMessage());
}
logger.log(Level.FINE, () -> "Parsed and extracted raw query:" + e);
if (e != null) {
targetSeries.add(e);
}
}
}
}
use of com.srotya.sidewinder.core.functions.list.Function in project sidewinder by srotya.
the class TestTransformFunctions method testLog10.
@Test
public void testLog10() {
Function f = new Log10Function();
List<SeriesOutput> series = new ArrayList<>();
SeriesOutput s = new SeriesOutput(Arrays.asList(new DataPoint(1L, 100), new DataPoint(1L, 1000)));
series.add(s);
List<SeriesOutput> apply = f.apply(series);
assertEquals(2, apply.get(0).getDataPoints().size());
assertEquals(2, apply.get(0).getDataPoints().get(0).getLongValue(), 0.1);
assertEquals(3, apply.get(0).getDataPoints().get(1).getLongValue(), 0.1);
}
use of com.srotya.sidewinder.core.functions.list.Function in project sidewinder by srotya.
the class TestTransformFunctions method testLog.
@Test
public void testLog() {
Function f = new LogFunction();
List<SeriesOutput> series = new ArrayList<>();
SeriesOutput s = new SeriesOutput(Arrays.asList(new DataPoint(1L, 100), new DataPoint(1L, 1000)));
series.add(s);
List<SeriesOutput> apply = f.apply(series);
assertEquals(2, apply.get(0).getDataPoints().size());
assertEquals(4.0, apply.get(0).getDataPoints().get(0).getLongValue(), 0.1);
assertEquals(6.0, apply.get(0).getDataPoints().get(1).getLongValue(), 0.1);
}
use of com.srotya.sidewinder.core.functions.list.Function in project sidewinder by srotya.
the class TestTransformFunctions method testCeil.
@Test
public void testCeil() {
Function f = new CeilFunction();
List<SeriesOutput> series = new ArrayList<>();
SeriesOutput s = new SeriesOutput(Arrays.asList(new DataPoint(1L, 3.2), new DataPoint(1L, 4.7)));
series.add(s);
List<SeriesOutput> apply = f.apply(series);
assertEquals(2, apply.get(0).getDataPoints().size());
assertEquals(3.2, apply.get(0).getDataPoints().get(0).getValue(), 0.1);
assertEquals(4.7, apply.get(0).getDataPoints().get(1).getValue(), 0.1);
}
use of com.srotya.sidewinder.core.functions.list.Function in project sidewinder by srotya.
the class TestTransformFunctions method testSquareRoot.
@Test
public void testSquareRoot() {
Function f = new SqrtFunction();
List<SeriesOutput> series = new ArrayList<>();
SeriesOutput s = new SeriesOutput(Arrays.asList(new DataPoint(1L, 9), new DataPoint(1L, 16)));
series.add(s);
List<SeriesOutput> apply = f.apply(series);
assertEquals(2, apply.get(0).getDataPoints().size());
assertEquals(3, apply.get(0).getDataPoints().get(0).getLongValue());
assertEquals(4, apply.get(0).getDataPoints().get(1).getLongValue());
}
Aggregations