Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-3288

Sliding time window ignored when using @timestamp and pseudo clock

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

Details

    Description

      When using a custom @timestamp together with PSEUDO clock, all events are accumulated rather than just those within the window:time period. I have tried using long (millisecond) and java.util.Date without success.

      ==================================

      declare SimpleObject
      @role(event)
      @timestamp(customTime)
      @expires(10m)
      end;

      rule "honour custom timestamp"
      when
      $avgVal : Number (longValue > 0) from accumulate ( SimpleObject($valueLng : valueLong ) over window:time (10s) from entry-point "SimpleEP", average ( $valueLng ) )
      then
      System.out.println("avg: " + $avgVal);
      end

      ---------------------------------------

      import java.util.Date;

      public class SimpleObject {

      private long customTime;
      public long valueLong;

      public SimpleObject(Date customTime, long valueLong)

      { this.customTime = customTime.getTime(); this.valueLong = valueLong; }

      public long getCustomTime()

      { return customTime; }

      public void setCustomTime(long customTime)

      { this.customTime = customTime; }

      public long getValueLong()

      { return valueLong; }

      public void setValueLong(long valueLong)

      { this.valueLong = valueLong; }

      }
      ------------ Trivial Spock/Groovy unit test ----------------
      @IgnoreRest
      def "should honour custom timestamp"() {
      when:
      use (TimeCategory)

      { def now = new Date() simpleEp.insert(new SimpleObject(now, 100)) ksession.fireAllRules() clock.advanceTime( 5, TimeUnit.SECONDS ); ksession.fireAllRules() simpleEp.insert(new SimpleObject(5.seconds.from.now, 90)) ksession.fireAllRules() clock.advanceTime( 5, TimeUnit.SECONDS ); ksession.fireAllRules() simpleEp.insert(new SimpleObject(10.seconds.from.now, 80)) ksession.fireAllRules() clock.advanceTime( 5, TimeUnit.SECONDS ); ksession.fireAllRules() simpleEp.insert(new SimpleObject(15.seconds.from.now, 70)) ksession.fireAllRules() clock.advanceTime( 5, TimeUnit.SECONDS ); ksession.fireAllRules() simpleEp.insert(new SimpleObject(20.seconds.from.now, 60)) ksession.fireAllRules() clock.advanceTime( 5, TimeUnit.SECONDS ); ksession.fireAllRules() simpleEp.insert(new SimpleObject(25.seconds.from.now, 50)) ksession.fireAllRules() clock.advanceTime( 5, TimeUnit.SECONDS ); ksession.fireAllRules() }

      then:
      1 == 1 // no assertions - we're examining the stdout.
      }
      ==================================
      OUTPUT (INCORRECT - all values are included for each evalutation):
      avg: 100.0
      avg: 95.0
      avg: 90.0
      avg: 85.0
      avg: 80.0
      avg: 75.0

      Note that when commenting out the @timestamp tag the output changes to the following (correct) output:
      avg: 100.0
      avg: 95.0
      avg: 90.0
      avg: 85.0
      avg: 80.0
      avg: 75.0
      avg: 70.0
      avg: 65.0
      avg: 60.0
      avg: 55.0
      avg: 50.0

      Also note that when using the REALTIME clock with Thread.sleep the output is correct.

      Attachments

        Activity

          People

            etirelli@redhat.com Edson Tirelli
            colinwebber1 Colin Webber (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

            Dates

              Created:
              Updated:
              Archived:

              PagerDuty