Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/events/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ func (rb *Bucket) getMaxDwell() time.Duration {

// CanFlush returns if the bucket can be evicted from the db
func (rb *Bucket) CanFlush() bool {
return time.Since(rb.CreatedAt) >= time.Millisecond*time.Duration(rb.flushWait)
if rb.Rule.DwellCount < 1 {
return time.Since(rb.CreatedAt) >= time.Millisecond*time.Duration(rb.flushWait)
}
return time.Since(rb.CreatedAt) >= time.Millisecond*time.Duration(rb.flushWait) ||
uint64(len(rb.Events)) >= rb.Rule.DwellCount
}

// CanFlushIn returns time left for flush
Expand Down
3 changes: 3 additions & 0 deletions pkg/rules/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Rule struct {
EventTypePatterns []string `json:"event_type_patterns"` // a list of event types to look for. wildcards are allowed.
Dwell uint64 `json:"dwell"` // dwell duration in milliseconds for events to arrive
DwellDeadline uint64 `json:"dwell_deadline"` // dwell duration threshold after which arriving events expand the dwell window
DwellCount uint64 `json:"dwell_count"` // dwell count is no of events it should wait before flushing events
MaxDwell uint64 `json:"max_dwell"` // maximum dwell duration including expansion
Regexes []string `json:"regexes,omitempty"` // generated regex string array from event types
Disabled bool `json:"disabled,omitempty"` // if the rule is disabled
Expand Down Expand Up @@ -61,6 +62,7 @@ type PublicRule struct {
HookRetry int `json:"hook_retry"` // number of retries while attempting to post
EventTypePatterns []string `json:"event_type_patterns"` // a list of event types to look for. wildcards are allowed.
Dwell uint64 `json:"dwell"` // dwell duration in milliseconds for events to arrive
DwellCount uint64 `json:"dwell_count"` // dwell count is no of events it should wait before flushing events
DwellDeadline uint64 `json:"dwell_deadline"` // dwell duration threshold after which arriving events expand the dwell window
MaxDwell uint64 `json:"max_dwell"` // maximum dwell duration including expansion
Disabled bool `json:"disabled,omitempty"` // if the rule is disabled
Expand All @@ -76,6 +78,7 @@ func NewFromPublic(r *PublicRule) *Rule {
HookRetry: r.HookRetry,
EventTypePatterns: r.EventTypePatterns,
Dwell: r.Dwell,
DwellCount: r.DwellCount,
DwellDeadline: r.DwellDeadline,
MaxDwell: r.MaxDwell,
Disabled: r.Disabled,
Expand Down