Skip to content

Commit

Permalink
Issue 159 (#186)
Browse files Browse the repository at this point in the history
* Fixed timer and token

* Added a conditional for end=-1

* Added timeMultiple logic

* Time Multiple Fix
  • Loading branch information
arctan5x authored May 2, 2019
1 parent b9ca648 commit 15988e1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
4 changes: 1 addition & 3 deletions docs/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ The following options are only valid for the default Eventgen generator plugin.

timeMultiple = <float>
* Only valid in mode = replay
* Will slow down the replay of events by <float> factor. For example, allows a 10 minute sample
to play out over 20 minutes with a timeMultiple of 2, or 60 minutes with a timeMultiple of 6.
By the converse, make timeMultiple 0.5 will make the events run twice as fast.
* Will slow down the replay of events by <float> factor. This is achieved by calculating the interval between events and adjusting the interval by the timeMultiple factor. For example, allows a 10 minute sample to play out over 20 minutes with a timeMultiple of 2, or 60 minutes with a timeMultiple of 6. By the converse, make timeMultiple 0.5 will make the events run twice as fast. NOTE that the interval timeMultiple is adjusting is actual time interval between events in your sample file. "timeMultiple" option should not affect your "interval" option.
---
timeField = <field name>
* Only valid in mode = replay
Expand Down
5 changes: 2 additions & 3 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ autotimestamp = <boolean>
* Will enable autotimestamp feature which detects most common forms of timestamps in your samples with no configuration.
timeMultiple = <float>
* Will slow down the replay of events by <float> factor. For example, allows a 10 minute sample
to play out over 20 minutes with a timeMultiple of 2, or 60 minutes with a timeMultiple of 6.
By the converse, make timeMultiple 0.5 will make the events run twice as fast.
* Only valid in mode = replay
* Will slow down the replay of events by <float> factor. This is achieved by calculating the interval between events and adjusting the interval by the timeMultiple factor. For example, allows a 10 minute sample to play out over 20 minutes with a timeMultiple of 2, or 60 minutes with a timeMultiple of 6. By the converse, make timeMultiple 0.5 will make the events run twice as fast. NOTE that the interval timeMultiple is adjusting is actual time interval between events in your sample file. "timeMultiple" option should not affect your "interval" option.
timeField = <field name>
* Only valid in mode = replay
Expand Down
9 changes: 9 additions & 0 deletions docs/TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ Specify that the input file is in CSV format, rather than a plain text file. Wit
timeMultiple = 2
```
This will slow down the replay by a factor of 2 by multiplying all time intervals between events by 2.
For example, let's assume that you have 3 events generated like below:
12:05:04 helloworld
12:05:06 helloworld2
12:05:09 helloworld3

Applying timeMultiple=2 would instead generate 3 events like below:
12:05:04 helloworld
12:05:08 helloworld2
12:05:14 helloworld3

```
backfill = -15m
Expand Down
2 changes: 1 addition & 1 deletion splunk_eventgen/lib/eventgentimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, time, sample=None, config=None, genqueue=None, outputqueue=No
self.logger.error("Invalid setting for timeMultiple: {}, value should be positive".format(
self.sample.timeMultiple))
elif self.sample.timeMultiple != 1:
self.interval = self.sample.interval * self.sample.timeMultiple
self.interval = self.sample.interval
self.logger.debug("Adjusting interval {} with timeMultiple {}, new interval: {}".format(
self.sample.interval, self.sample.timeMultiple, self.interval))
self.logger.info(
Expand Down
4 changes: 2 additions & 2 deletions splunk_eventgen/lib/plugins/generator/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def gen(self, count, earliest, latest, samplename=None):
continue

# Refer to the last event to calculate the new backfill time
time_difference = current_event_timestamp - previous_event_timestamp
time_difference = datetime.timedelta(seconds=(current_event_timestamp - previous_event_timestamp) .total_seconds() * self._sample.timeMultiple)

if self.backfill_time + time_difference >= self.current_time:
sleep_time = time_difference - (self.current_time - self.backfill_time)
if self._sample.backfill and not self._sample.backfilldone:
if not self._sample.backfill or self._sample.backfilldone:
time.sleep(sleep_time.seconds)
self.current_time += sleep_time
self.backfill_time = self.current_time
Expand Down
2 changes: 0 additions & 2 deletions tests/large/test_mode_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test_mode_replay_backfill(eventgen_test_helper):
assert len(events) == 24


@pytest.mark.skip(reason="this issue is not fixed")
def test_mode_replay_timemultiple(eventgen_test_helper):
"""Test normal replay mode with timeMultiple = 0.5 which will replay the sample with half time interval"""
current_datetime = datetime.now()
Expand All @@ -53,7 +52,6 @@ def test_mode_replay_timemultiple(eventgen_test_helper):
# assert the event time is after (now - earliest) time
assert delter_seconds < 11


def test_mode_replay_csv(eventgen_test_helper):
"""Test normal replay mode with sampletype = csv which will get _raw row from the sample"""
events = eventgen_test_helper('eventgen_replay_csv.conf').get_events()
Expand Down

0 comments on commit 15988e1

Please sign in to comment.