The AlertRules._from_file() method errors out when adding an empty (zero-size) alert rule file, see below for traceback
To Reproduce
Deploy a client of the prometheus_scrape library
Create an empty alert.rules file: touch alert.rules
Trigger reloading alert rule parsing
Environment
Platform-indep.
Relevant log output
Traceback (most recent call last):
File "/home/peter/src/cos-lite/prometheus-k8s-operator/tests/unit/test_prometheus_rules_provider.py", line 161, in test_reload_with_empty_rules
self.harness.charm.rules_provider._reinitialize_alert_rules()
File "/home/peter/src/cos-lite/prometheus-k8s-operator/lib/charms/prometheus_k8s/v0/prometheus_scrape.py", line 1684, in _reinitialize_alert_rules
self._update_relation_data(None)
File "/home/peter/src/cos-lite/prometheus-k8s-operator/lib/charms/prometheus_k8s/v0/prometheus_scrape.py", line 1692, in _update_relation_data
alert_rules.add_path(self.dir_path, recursive=self._recursive)
File "/home/peter/src/cos-lite/prometheus-k8s-operator/lib/charms/prometheus_k8s/v0/prometheus_scrape.py", line 762, in add_path
self.alert_groups.extend(self._from_dir(path, recursive))
File "/home/peter/src/cos-lite/prometheus-k8s-operator/lib/charms/prometheus_k8s/v0/prometheus_scrape.py", line 740, in _from_dir
alert_groups_from_file = self._from_file(dir_path, file_path)
File "/home/peter/src/cos-lite/prometheus-k8s-operator/lib/charms/prometheus_k8s/v0/prometheus_scrape.py", line 644, in _from_file
if _is_official_alert_rule_format(rule_file):
File "/home/peter/src/cos-lite/prometheus-k8s-operator/lib/charms/prometheus_k8s/v0/prometheus_scrape.py", line 563, in _is_official_alert_rule_format
return "groups" in rules_dict
TypeError: argument of type 'NoneType' is not iterable
Bug Description
The
AlertRules._from_file()
method errors out when adding an empty (zero-size) alert rule file, see below for tracebackTo Reproduce
prometheus_scrape
librarytouch alert.rules
Environment
Platform-indep.
Relevant log output
Additional context
No response