Skip to content

Commit

Permalink
Merge pull request #192 from jertel/jertel/scheduler_config
Browse files Browse the repository at this point in the history
Add optional configuration values for scheduler
  • Loading branch information
nsano-rururu authored May 26, 2021
2 parents c01e485 + 0cf1075 commit 52b105d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- None

## New features
- None
- Expose rule scheduler properties as configurable settings - [#192](https://github.com/jertel/elastalert2/pull/192) - #jertel

## Other changes
- Speed up unit tests by adding default parallelism - [164](https://github.com/jertel/elastalert2/pull/164) - @ferozsalam
Expand Down
4 changes: 4 additions & 0 deletions docs/source/elastalert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ it ran the query for a given rule, and periodically query from that time until t
this field is a nested unit of time, such as ``minutes: 5``. This is how time is defined in every ElastAlert
configuration.

``misfire_grace_time``: If the rule scheduler is running behind, due to large numbers of rules or long-running rules, this grace time settings allows a rule to still be executed, provided its next scheduled runt time is no more than this grace period, in seconds, overdue. The default is 5 seconds.

``writeback_index``: The index on ``es_host`` to use.

``max_query_size``: The maximum number of documents that will be downloaded from Elasticsearch in a single query. The
Expand All @@ -174,6 +176,8 @@ using the size of ``max_query_size`` through the set amount of pages, when ``max
``max_scrolling_count``: The maximum amount of pages to scroll through. The default is ``0``, which means the scrolling has no limit.
For example if this value is set to ``5`` and the ``max_query_size`` is set to ``10000`` then ``50000`` documents will be downloaded at most.

``max_threads``: The maximum number of concurrent threads available to process scheduled rules. Large numbers of long-running rules may require this value be increased, though this could overload the Elasticsearch cluster if too many complex queries are running concurrently. Default is 10.

``scroll_keepalive``: The maximum time (formatted in `Time Units <https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units>`_) the scrolling context should be kept alive. Avoid using high values as it abuses resources in Elasticsearch, but be mindful to allow sufficient time to finish processing all the results.

``max_aggregation``: The maximum number of alerts to aggregate together. If a rule has ``aggregation`` set, all
Expand Down
11 changes: 10 additions & 1 deletion elastalert/elastalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import dateutil.tz
import pytz
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.executors.pool import ThreadPoolExecutor
from croniter import croniter
from elasticsearch.exceptions import ConnectionError
from elasticsearch.exceptions import ElasticsearchException
Expand Down Expand Up @@ -171,7 +172,15 @@ def __init__(self, args):
self.thread_data.alerts_sent = 0
self.thread_data.num_hits = 0
self.thread_data.num_dupes = 0
self.scheduler = BackgroundScheduler()
executors = {
'default': ThreadPoolExecutor(max_workers=self.conf.get('max_threads', 10)),
}
job_defaults = {
'misfire_grace_time': self.conf.get('misfire_grace_time', 5),
'coalesce': True,
'max_instances': 1
}
self.scheduler = BackgroundScheduler(executors=executors, job_defaults=job_defaults)
self.string_multi_field_name = self.conf.get('string_multi_field_name', False)
self.statsd_instance_tag = self.conf.get('statsd_instance_tag', '')
self.statsd_host = self.conf.get('statsd_host', '')
Expand Down
2 changes: 2 additions & 0 deletions elastalert/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ properties:
query_delay: *timeframe
max_query_size: {type: integer}
max_scrolling: {type: integer}
max_threads: {type: integer}
misfire_grace_time: {type: integer}

owner: {type: string}
priority: {type: integer}
Expand Down

0 comments on commit 52b105d

Please sign in to comment.