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

Implement skip_invalid feature, fixes #1336 #1338

Merged
merged 1 commit into from
Dec 7, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [Docs] Fix broken search function caused by sphinx upgrade a few releases ago - [#1332](https://github.com/jertel/elastalert2/pull/1332) - @jertel
- [Docs] Fix mismatch for parameter iris_customer_id - [1334](https://github.com/jertel/elastalert2/pull/1334) @malinkinsa
- [IRIS] Make parameter iris_customer_id optional with default value - [1334](https://github.com/jertel/elastalert2/pull/1334) @malinkinsa
- (Re)Implement `skip_invalid` to continue loading rules if one is invalid - [#1338](https://github.com/jertel/elastalert2/pull/1338) - @jertel

# 2.15.0

Expand Down
6 changes: 5 additions & 1 deletion elastalert/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ def load(self, conf, args=None):
if rule['name'] in names:
raise EAException('Duplicate rule named %s' % (rule['name']))
except EAException as e:
raise EAException('Error loading file %s: %s' % (rule_file, e))
if (conf.get('skip_invalid')):
elastalert_logger.error(e)
continue
else:
raise EAException('Error loading file %s: %s' % (rule_file, e))

rules.append(rule)
names.append(rule['name'])
Expand Down
26 changes: 26 additions & 0 deletions tests/loaders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,32 @@ def test_raises_on_missing_config():
rules['rules'] = rules['rules_loader'].load(rules)


def test_no_raises_when_skip_invalid():
optional_keys = (
'aggregation', 'use_count_query', 'query_key', 'compare_key', 'filter', 'include', 'es_host', 'es_port',
'name', 'fields'
)
test_rule_copy = copy.deepcopy(test_rule)
for key in list(test_rule_copy.keys()):
test_rule_copy = copy.deepcopy(test_rule)
test_config_copy = copy.deepcopy(test_config)
test_rule_copy.pop(key)

# Non required keys
if key in optional_keys:
continue

with mock.patch('elastalert.config.read_yaml') as mock_conf_open:
mock_conf_open.return_value = test_config_copy
with mock.patch('elastalert.loaders.read_yaml') as mock_rule_open:
mock_rule_open.return_value = test_rule_copy
with mock.patch('os.walk') as mock_walk:
mock_walk.return_value = [('', [], ['testrule.yaml'])]
rules = load_conf(test_args)
rules['skip_invalid'] = True
rules['rules'] = rules['rules_loader'].load(rules)


def test_compound_query_key():
test_config_copy = copy.deepcopy(test_config)
rules_loader = FileRulesLoader(test_config_copy)
Expand Down