Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional configuration values for scheduler #192

Merged
merged 2 commits into from
May 26, 2021
Merged
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
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