private static void setInterpolator(Map<String, List<String>> queryParams, MetricDataQueryBuilder builder) { Interpolator interpolator = null; if (queryParams.containsKey(INTERPOLATE)) { String interpolatorType = queryParams.get(INTERPOLATE).get(0); // timeLimit used in case there is a big gap in the data and we don't want to interpolate points. // the limit defines how big the gap has to be in seconds before we just say they're all zeroes. long timeLimit = queryParams.containsKey(MAX_INTERPOLATE_GAP) ? Long.parseLong(queryParams.get(MAX_INTERPOLATE_GAP).get(0)) : Long.MAX_VALUE; if (STEP_INTERPOLATOR.equals(interpolatorType)) { interpolator = new Interpolators.Step(timeLimit); } else if (LINEAR_INTERPOLATOR.equals(interpolatorType)) { interpolator = new Interpolators.Linear(timeLimit); } } builder.setInterpolator(interpolator); }
private static void setInterpolator(Map<String, List<String>> queryParams, MetricDataQueryBuilder builder) { Interpolator interpolator = null; if (queryParams.containsKey(INTERPOLATE)) { String interpolatorType = queryParams.get(INTERPOLATE).get(0); // timeLimit used in case there is a big gap in the data and we don't want to interpolate points. // the limit defines how big the gap has to be in seconds before we just say they're all zeroes. long timeLimit = queryParams.containsKey(MAX_INTERPOLATE_GAP) ? Long.parseLong(queryParams.get(MAX_INTERPOLATE_GAP).get(0)) : Long.MAX_VALUE; if (STEP_INTERPOLATOR.equals(interpolatorType)) { interpolator = new Interpolators.Step(timeLimit); } else if (LINEAR_INTERPOLATOR.equals(interpolatorType)) { interpolator = new Interpolators.Linear(timeLimit); } } builder.setInterpolator(interpolator); }
private Interpolator getInterpolator(String interpolator, long timeLimit) { if (PARAM_STEP_INTERPOLATOR.equals(interpolator)) { return new Interpolators.Step(timeLimit); } else if (PARAM_LINEAR_INTERPOLATOR.equals(interpolator)) { return new Interpolators.Linear(timeLimit); } return null; }
ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), expectedTimeValues)), new Interpolators.Step()); ImmutableList.of( new TimeSeries("metric1", new HashMap<String, String>(), expectedTimeValues)), new Interpolators.Step(limit));
@Test public void testInterpolateLimit() { long limit = 20; Interpolator interpolator = new Interpolators.Step(limit); TimeValue start = new TimeValue(0, 10); TimeValue end = new TimeValue(limit + 1, 50); // time between points is greater than this limit, values in between should be 0 for (int i = 1; i < 1 + limit; i++) { Assert.assertEquals(0, interpolator.interpolate(start, end, i)); } // time between points is not greater than the limit, values in between should be interpolated end = new TimeValue(limit, 50); for (int i = 1; i < limit; i++) { Assert.assertEquals(10, interpolator.interpolate(start, end, i)); } } }
@Test public void testStepInterpolator() { Interpolator interpolator = new Interpolators.Step(); long startTs = 1; long endTs = 10; TimeValue start = new TimeValue(startTs, 5); TimeValue end = new TimeValue(endTs, 3); for (long i = startTs; i < endTs; i++) { Assert.assertEquals(5, interpolator.interpolate(start, end, i)); } Assert.assertEquals(3, interpolator.interpolate(start, end, endTs)); }
private Interpolator getInterpolator(String interpolator, long timeLimit) { if (PARAM_STEP_INTERPOLATOR.equals(interpolator)) { return new Interpolators.Step(timeLimit); } else if (PARAM_LINEAR_INTERPOLATOR.equals(interpolator)) { return new Interpolators.Linear(timeLimit); } return null; }