Skip to content

Commit

Permalink
HWKALERTS-74 ANY-Match Dampening
Browse files Browse the repository at this point in the history
- add validators in Dampening.forXxx methods
- replace some constructor use with Dampening.forXxx
- add some sleep time to lifecycle itests but print perf msg when it runs
  unecepectedly long. Note that recently it is taking longer to process
  the alerting, or maybe I am imagining it.
  • Loading branch information
jshaughn committed Aug 3, 2015
1 parent 9b504ca commit f138332
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ public Dampening() {
* no time limit for the evaluations.
* @param triggerId the triggerId
* @param triggerMode the trigger mode for when this dampening is active
* @param numConsecutiveTrueEvals the numConsecutiveTrueEvals
* @param numConsecutiveTrueEvals the numConsecutiveTrueEvals, >= 1.
* @return the configured Dampening
*/
public static Dampening forStrict(String triggerId, Mode triggerMode, int numConsecutiveTrueEvals) {
if (numConsecutiveTrueEvals < 1) {
throw new IllegalArgumentException("NumConsecutiveTrueEvals must be >= 1");
}
return new Dampening(triggerId, triggerMode, Type.STRICT, numConsecutiveTrueEvals, numConsecutiveTrueEvals, 0);
}

Expand All @@ -120,11 +123,17 @@ public static Dampening forStrict(String triggerId, Mode triggerMode, int numCon
* no time limit for the evaluations.
* @param triggerId the triggerId
* @param triggerMode the trigger mode for when this dampening is active
* @param numTrueEvals the numTrueEvals
* @param numTotalEvals the numTotalEvals
* @param numTrueEvals the numTrueEvals, >=1
* @param numTotalEvals the numTotalEvals, > numTotalEvals
* @return the configured Dampening
*/
public static Dampening forRelaxedCount(String triggerId, Mode triggerMode, int numTrueEvals, int numTotalEvals) {
if (numTrueEvals < 1) {
throw new IllegalArgumentException("NumTrueEvals must be >= 1");
}
if (numTotalEvals <= numTrueEvals) {
throw new IllegalArgumentException("NumTotalEvals must be > NumTrueEvals");
}
return new Dampening(triggerId, triggerMode, Type.RELAXED_COUNT, numTrueEvals, numTotalEvals, 0);
}

Expand All @@ -134,12 +143,18 @@ public static Dampening forRelaxedCount(String triggerId, Mode triggerMode, int
* the requisite data must be supplied in a timely manner.
* @param triggerId the triggerId
* @param triggerMode the trigger mode for when this dampening is active
* @param numTrueEvals the numTrueEvals
* @param numTrueEvals the numTrueEvals, >= 1.
* @param evalPeriod Elapsed real time, in milliseconds. In other words, this is not measured against
* collectionTimes (i.e. the timestamp on the data) but rather the evaluation times.
* collectionTimes (i.e. the timestamp on the data) but rather the evaluation times. >=1ms.
* @return the configured Dampening
*/
public static Dampening forRelaxedTime(String triggerId, Mode triggerMode, int numTrueEvals, long evalPeriod) {
if (numTrueEvals < 1) {
throw new IllegalArgumentException("NumTrueEvals must be >= 1");
}
if (evalPeriod < 1) {
throw new IllegalArgumentException("EvalPeriod must be >= 1ms");
}
return new Dampening(triggerId, triggerMode, Type.RELAXED_TIME, numTrueEvals, 0, evalPeriod);
}

Expand All @@ -150,10 +165,13 @@ public static Dampening forRelaxedTime(String triggerId, Mode triggerMode, int n
* @param triggerId the triggerId
* @param triggerMode the trigger mode for when this dampening is active
* @param evalPeriod Elapsed real time, in milliseconds. In other words, this is not measured against
* collectionTimes (i.e. the timestamp on the data) but rather the evaluation times.
* collectionTimes (i.e. the timestamp on the data) but rather the evaluation times. >=1ms.
* @return the configured Dampening
*/
public static Dampening forStrictTime(String triggerId, Mode triggerMode, long evalPeriod) {
if (evalPeriod < 1) {
throw new IllegalArgumentException("EvalPeriod must be >= 1ms");
}
return new Dampening(triggerId, triggerMode, Type.STRICT_TIME, 0, 0, evalPeriod);
}

Expand All @@ -164,10 +182,13 @@ public static Dampening forStrictTime(String triggerId, Mode triggerMode, long e
* @param triggerId the triggerId
* @param triggerMode the trigger mode for when this dampening is active
* @param evalPeriod Elapsed real time, in milliseconds. In other words, this is not measured against
* collectionTimes (i.e. the timestamp on the data) but rather the clock starts at true-evaluation-time-1.
* collectionTimes (i.e. the timestamp on the data) but rather the clock starts at true-evaluation-time-1. >=1ms.
* @return the configured Dampening
*/
public static Dampening forStrictTimeout(String triggerId, Mode triggerMode, long evalPeriod) {
if (evalPeriod < 1) {
throw new IllegalArgumentException("EvalPeriod must be >= 1ms");
}
return new Dampening(triggerId, triggerMode, Type.STRICT_TIMEOUT, 0, 0, evalPeriod);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ rule ProvideDefaultDampening
if (log != null && log.isDebugEnabled()) {
log.debug("Adding default " + $tmode + " dampening for trigger! " + $t.getId());
}
Dampening d = new Dampening( $tid, $tmode, Dampening.Type.STRICT, 1, 1, 0L );
Dampening d = Dampening.forStrict( $tid, $tmode, 1 );
insert( d );
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DampeningITest extends AbstractITestBase {
def resp = client.post(path: "triggers", body: testTrigger)
assertEquals(200, resp.status)

Dampening d = new Dampening("test-trigger-6", Mode.FIRING, Type.RELAXED_COUNT, 1, 1, 1);
Dampening d = Dampening.forRelaxedCount("test-trigger-6", Mode.FIRING, 1, 2);

resp = client.post(path: "triggers/test-trigger-6/dampenings", body: d)
assertEquals(200, resp.status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ class LifecycleITest extends AbstractITestBase {
assertEquals(200, resp.status)

// The alert processing happens async, so give it a little time before failing...
for ( int i=0; i < 10; ++i ) {
println "SLEEP!" ;
Thread.sleep(1000);
for ( int i=0; i < 20; ++i ) {
Thread.sleep(500);

// FETCH recent alerts for trigger, there should be 1
resp = client.get(path: "", query: [startTime:start,triggerIds:"test-autodisable-trigger"] )
if ( resp.status == 200 && resp.data != null && resp.data.size > 0) {
if ( i > 10 ) {
println( "Perf: passing but sleep iterations high [" + i + "]" );
}
break;
}
assertEquals(200, resp.status)
Expand Down Expand Up @@ -227,13 +229,15 @@ class LifecycleITest extends AbstractITestBase {
assertEquals(200, resp.status)

// The alert processing happens async, so give it a little time before failing...
for ( int i=0; i < 10; ++i ) {
println "SLEEP!" ;
Thread.sleep(1000);
for ( int i=0; i < 20; ++i ) {
Thread.sleep(500);

// FETCH recent alerts for trigger, there should be 1
resp = client.get(path: "", query: [startTime:start,triggerIds:"test-autoresolve-trigger"] )
if ( resp.status == 200 && resp.data.size() == 1 ) {
if ( i > 10 ) {
println( "Perf: passing but sleep iterations high [" + i + "]" );
}
break;
}
assertEquals(200, resp.status)
Expand Down Expand Up @@ -271,13 +275,15 @@ class LifecycleITest extends AbstractITestBase {
assertEquals(200, resp.status)

// The alert processing happens async, so give it a little time before failing...
for ( int i=0; i < 10; ++i ) {
println "SLEEP!" ;
Thread.sleep(1000);
for ( int i=0; i < 20; ++i ) {
Thread.sleep(500);

// FETCH recent alerts for trigger, there should be 1
resp = client.get(path: "", query: [startTime:start,triggerIds:"test-autoresolve-trigger",statuses:"RESOLVED"] )
if ( resp.status == 200 && resp.data.size() == 1 ) {
if ( i > 10 ) {
println( "Perf: passing but sleep iterations high [" + i + "]" );
}
break;
}
assertEquals(200, resp.status)
Expand Down Expand Up @@ -349,12 +355,14 @@ class LifecycleITest extends AbstractITestBase {

// The alert processing happens async, so give it a little time before failing...
for ( int i=0; i < 20; ++i ) {
println "SLEEP!" ;
Thread.sleep(1000);
Thread.sleep(500);

// FETCH recent alerts for trigger, there should be 5
resp = client.get(path: "", query: [startTime:start,triggerIds:"test-manual-trigger"] )
if ( resp.status == 200 && resp.data.size() == 5 ) {
if ( i > 10 ) {
println( "Perf: passing but sleep iterations high [" + i + "]" );
}
break;
}
}
Expand Down Expand Up @@ -598,13 +606,15 @@ class LifecycleITest extends AbstractITestBase {
}

// The alert processing happens async, so give it a little time before failing...
for ( int i=0; i < 10; ++i ) {
// println "SLEEP!" ;
Thread.sleep(1000);
for ( int i=0; i < 20; ++i ) {
Thread.sleep(500);

// FETCH recent alerts for trigger, there should be 5
resp = client.get(path: "", query: [startTime:start,triggerIds:"test-manual2-trigger"] )
if ( resp.status == 200 && resp.data != null && resp.data.size() == 5 ) {
if ( i > 10 ) {
println( "Perf: passing but sleep iterations high [" + i + "]" );
}
break;
}
}
Expand Down Expand Up @@ -730,14 +740,16 @@ class LifecycleITest extends AbstractITestBase {
/*
Step 9: Wait until the engine detects the data, matches the conditions and sends an alert
*/
for ( int i=0; i < 10; ++i ) {
println "SLEEP!" ;
Thread.sleep(1000);
for ( int i=0; i < 20; ++i ) {
Thread.sleep(500);
resp = client.get(path: "", query: [startTime:start,triggerIds:"test-autoresolve-threshold-trigger"] )
/*
We should have only 1 alert
*/
if ( resp.status == 200 && resp.data.size() == 1 ) {
if ( i > 10 ) {
println( "Perf: passing but sleep iterations high [" + i + "]" );
}
break;
}
assertEquals(200, resp.status)
Expand Down Expand Up @@ -800,14 +812,16 @@ class LifecycleITest extends AbstractITestBase {
Step 15: Wait until the engine detects the data
It should retrieve 2 data
*/
for ( int i=0; i < 10; ++i ) {
println "SLEEP!" ;
Thread.sleep(1000);
for ( int i=0; i < 20; ++i ) {
Thread.sleep(500);
resp = client.get(path: "", query: [startTime:start,triggerIds:"test-autoresolve-threshold-trigger"] )
/*
We should have only 2 alert
*/
if ( resp.status == 200 && resp.data.size() == 2 ) {
if ( i > 10 ) {
println( "Perf: passing but sleep iterations high [" + i + "]" );
}
break;
}
assertEquals(200, resp.status)
Expand Down Expand Up @@ -880,13 +894,15 @@ class LifecycleITest extends AbstractITestBase {
}

// The alert processing happens async, so give it a little time before failing...
for ( int i=0; i < 10; ++i ) {
println "SLEEP!" ;
Thread.sleep(1000);
for ( int i=0; i < 20; ++i ) {
Thread.sleep(500);

// FETCH recent alerts for trigger, there should be 1 because the trigger should have disabled after firing
resp = client.get(path: "", query: [startTime:start,triggerIds:"test-autoenable-trigger"] )
if ( resp.status == 200 && resp.data.size() == 1 ) {
if ( i > 10 ) {
println( "Perf: passing but sleep iterations high [" + i + "]" );
}
break;
}
}
Expand Down Expand Up @@ -994,13 +1010,15 @@ class LifecycleITest extends AbstractITestBase {
assertEquals(200, resp.status)

// The alert processing happens async, so give it a little time before failing...
for ( int i=0; i < 10; ++i ) {
println "SLEEP!" ;
Thread.sleep(1000);
for ( int i=0; i < 20; ++i ) {
Thread.sleep(500);

// FETCH recent alerts for trigger, there should be 1
resp = client.get(path: "", query: [startTime:start,triggerIds:"test-manual-autoresolve-trigger"] )
if ( resp.status == 200 && resp.data.size() == 1 ) {
if ( i > 10 ) {
println( "Perf: passing but sleep iterations high [" + i + "]" );
}
break;
}
assertEquals(200, resp.status)
Expand Down Expand Up @@ -1044,14 +1062,16 @@ class LifecycleITest extends AbstractITestBase {
assertEquals(200, resp.status)

// The alert processing happens async, so give it a little time before failing...
for ( int i=0; i < 10; ++i ) {
println "SLEEP!" ;
Thread.sleep(1000);
for ( int i=0; i < 20; ++i ) {
Thread.sleep(500);

// FETCH recent OPEN alerts for trigger, there should be 1
resp = client.get(path: "",
query: [startTime:start,triggerIds:"test-manual-autoresolve-trigger",statuses:"OPEN"] )
if ( resp.status == 200 && resp.data.size() == 1 ) {
if ( i > 10 ) {
println( "Perf: passing but sleep iterations high [" + i + "]" );
}
break;
}
assertEquals(200, resp.status)
Expand Down

0 comments on commit f138332

Please sign in to comment.