Skip to content

Commit

Permalink
Merge branch 'master' into jertel/docs-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nsano-rururu authored Dec 7, 2023
2 parents b588981 + c004579 commit 995fe53
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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
- [Docs] Refactor the docs structure for improved ease-of-use - [#1337](https://github.com/jertel/elastalert2/pull/1337) - @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

0 comments on commit 995fe53

Please sign in to comment.