Skip to content

Commit

Permalink
HWKALERTS-50 tests complete and passing
Browse files Browse the repository at this point in the history
- added tests for the remaining single-metric functions
- fixed tests to avoid conflicting with data left from prior tests
- renamed functions delta/deltap to range/rangep which was more clear
  to jsanda and I think is the more standard math term for what they do.
- fixed the rxjava client side fetching range data from metrics

TODO: cleanup
  • Loading branch information
jshaughn committed Jul 2, 2015
1 parent 6a2d7cc commit c287774
Show file tree
Hide file tree
Showing 5 changed files with 453 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;

import com.datastax.driver.core.Session;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ enum Func {
/** Percent change from last week: (((avg - avgSamePeriodLastWeek) / avgSamePeriodLastWeek) * 100) */
avgw(7),
/** Maximum-Minimum for the period (a measurement of volatility) */
delta,
range,
/** (Maximum-Minimum)/avg for the period (a measurement of volatility) */
deltap,
rangep,
/** Minimum reported value for the period. */
min,
/** Maximum reported value for the period. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -46,8 +47,6 @@
import org.hawkular.metrics.core.api.MetricsService;
import org.jboss.logging.Logger;

import rx.observables.BlockingObservable;

/**
* Manages the Metrics expression evaluations and interacts with the Alerts system.
*
Expand Down Expand Up @@ -245,19 +244,19 @@ public void run() {
case card:
log.errorf("Not Yet Supported Function: %s", func);
break;
case delta: {
BlockingObservable<Double> bo = metrics.findGaugeDataRange(tenantId, metricId, start, end)
.toBlocking();
Double min = bo.first();
Double max = bo.last();
case range: {
Iterator<Double> iterator = metrics.findGaugeDataRange(tenantId, metricId, start, end)
.toBlocking().toIterable().iterator();
Double min = iterator.next();
Double max = iterator.next();
value = max - min;
break;
}
case deltap: {
BlockingObservable<Double> bo = metrics.findGaugeDataRange(tenantId, metricId, start, end)
.toBlocking();
Double min = bo.first();
Double max = bo.last();
case rangep: {
Iterator<Double> iterator = metrics.findGaugeDataRange(tenantId, metricId, start, end)
.toBlocking().toIterable().iterator();
Double min = iterator.next();
Double max = iterator.next();
Double avg = metrics.findGaugeDataAverage(tenantId, metricId, start, end).toBlocking().last();
value = (max - min) / avg;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void expressionParseTest() {

x = new Expression("metric:15:delta(foo-bar >= 2), 20m");
assertEquals(x.getTarget(), Target.Metric);
assertEquals(x.getFunc(), Func.delta);
assertEquals(x.getFunc(), Func.range);
assertEquals(x.getInterval().intValue(), 15);
assertEquals(x.getPeriod().intValue(), 20);
assertEquals(x.getOp(), Op.GTE);
Expand All @@ -66,7 +66,7 @@ public void expressionParseTest() {

x = new Expression("TAG:5m:deltap(bar <= 1.5),10");
assertEquals(x.getTarget(), Target.Tag);
assertEquals(x.getFunc(), Func.deltap);
assertEquals(x.getFunc(), Func.rangep);
assertEquals(x.getInterval().intValue(), 5);
assertEquals(x.getPeriod().intValue(), 10);
assertEquals(x.getOp(), Op.LTE);
Expand Down

0 comments on commit c287774

Please sign in to comment.