Search in sources :

Example 1 with ChainFunction

use of com.srotya.sidewinder.core.functions.multiseries.ChainFunction in project sidewinder by srotya.

the class TestChainFunction method testTwoFunctions.

@Test
public void testTwoFunctions() throws Exception {
    Series series = new Series("cpu", "test", Arrays.asList(new Tag("t", "1"), new Tag("t", "2")));
    List<DataPoint> dps = new ArrayList<>();
    long baseTs = 1486617103629L;
    for (int i = 0; i < 4; i++) {
        dps.add(new DataPoint(baseTs + 30_000 * i, 1));
    }
    series.setDataPoints(dps);
    series.setFp(false);
    List<Series> seriesList = Arrays.asList(series);
    ChainFunction cf = new ChainFunction();
    ReducingWindowedAggregator rwa = new WindowedMean();
    rwa.init(new Object[] { 70, "smean" });
    ReducingWindowedAggregator rwa2 = new WindowedMean();
    rwa2.init(new Object[] { 200, "smean" });
    cf.init(new Function[] { rwa, rwa2 });
    List<Series> apply = cf.apply(seriesList);
    List<DataPoint> result = apply.get(0).getDataPoints();
    assertEquals(1, result.size());
    assertEquals(1, result.get(0).getLongValue());
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) ReducingWindowedAggregator(com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ChainFunction(com.srotya.sidewinder.core.functions.multiseries.ChainFunction) ArrayList(java.util.ArrayList) Tag(com.srotya.sidewinder.core.filters.Tag) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 2 with ChainFunction

use of com.srotya.sidewinder.core.functions.multiseries.ChainFunction in project sidewinder by srotya.

the class MiscUtils method createFunctionChain.

public static Function createFunctionChain(String[] parts, int startIndex) throws InstantiationException, IllegalAccessException, Exception {
    Function[] arguments = new Function[parts.length - startIndex];
    for (int k = startIndex, p = 0; k < parts.length; k++, p++) {
        String[] args = parts[k].split(",");
        Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(args[0]);
        if (lookupFunction == null) {
            throw new BadRequestException("Unknown function:" + args[0]);
        }
        Function instance = (Function) lookupFunction.newInstance();
        if (args.length - 1 < instance.getNumberOfArgs()) {
            throw new BadRequestException("Insufficient arguments for aggregation function, needed:" + instance.getNumberOfArgs() + ", found:" + (args.length - 1));
        }
        Object[] ary = new Object[args.length - 1];
        for (int i = 1; i < args.length; i++) {
            Matcher matcher = NUMBER.matcher(args[i]);
            if (matcher.matches()) {
                if (matcher.group(1) != null) {
                    ary[i - 1] = Double.parseDouble(args[i]);
                } else {
                    ary[i - 1] = Integer.parseInt(args[i]);
                }
            } else {
                ary[i - 1] = args[i];
            }
        }
        instance.init(ary);
        arguments[p] = instance;
    }
    ChainFunction function = new ChainFunction();
    function.init(arguments);
    return function;
}
Also used : ChainFunction(com.srotya.sidewinder.core.functions.multiseries.ChainFunction) Function(com.srotya.sidewinder.core.functions.Function) Matcher(java.util.regex.Matcher) ChainFunction(com.srotya.sidewinder.core.functions.multiseries.ChainFunction) BadRequestException(javax.ws.rs.BadRequestException) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point)

Example 3 with ChainFunction

use of com.srotya.sidewinder.core.functions.multiseries.ChainFunction in project sidewinder by srotya.

the class TestChainFunction method testSingleFunction.

@Test
public void testSingleFunction() throws Exception {
    Series series = new Series("cpu", "test", Arrays.asList(new Tag("t", "1"), new Tag("t", "2")));
    List<DataPoint> dps = new ArrayList<>();
    long baseTs = 1486617103629L;
    for (int i = 0; i < 4; i++) {
        dps.add(new DataPoint(baseTs + 30_000 * i, 1));
    }
    series.setDataPoints(dps);
    series.setFp(false);
    List<Series> seriesList = Arrays.asList(series);
    ChainFunction cf = new ChainFunction();
    ReducingWindowedAggregator rwa = new WindowedMean();
    rwa.init(new Object[] { 70, "smean" });
    cf.init(new Function[] { rwa });
    List<Series> apply = cf.apply(seriesList);
    List<DataPoint> result = apply.get(0).getDataPoints();
    assertEquals(2, result.size());
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) ReducingWindowedAggregator(com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ChainFunction(com.srotya.sidewinder.core.functions.multiseries.ChainFunction) ArrayList(java.util.ArrayList) Tag(com.srotya.sidewinder.core.filters.Tag) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Aggregations

ChainFunction (com.srotya.sidewinder.core.functions.multiseries.ChainFunction)3 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)3 Tag (com.srotya.sidewinder.core.filters.Tag)2 ReducingWindowedAggregator (com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator)2 Series (com.srotya.sidewinder.core.storage.Series)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Function (com.srotya.sidewinder.core.functions.Function)1 Point (com.srotya.sidewinder.core.rpc.Point)1 Matcher (java.util.regex.Matcher)1 BadRequestException (javax.ws.rs.BadRequestException)1