File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed
Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -919,5 +919,13 @@ def env() -> Mapping[str, str | None]:
919919 # $1 per one million requests above ten million requests. The blocking
920920 # only applies to URLs disallowed via robots.txt.
921921 #
922- 'azul_waf_bot_control' : '0'
922+ 'azul_waf_bot_control' : '0' ,
923+
924+ # The maximum allowed percentage of blocked requests (number of blocked
925+ # requests, divided by the number of all requests, times 100) for a
926+ # configured period before a metric alarm is tripped.
927+ #
928+ # If None, a default value set in azul.Config will be used.
929+ #
930+ 'azul_blocked_alarm_threshold' : None
923931 }
Original file line number Diff line number Diff line change @@ -1855,6 +1855,15 @@ def __attrs_post_init__(self):
18551855 def waf_bot_control (self ) -> bool :
18561856 return self ._boolean (self .environ ['azul_waf_bot_control' ])
18571857
1858+ @property
1859+ def blocked_alarm_threshold (self ) -> int :
1860+ value = self .environ ['azul_blocked_alarm_threshold' ]
1861+ if value is None :
1862+ return 25 if self .deployment_stage == 'prod' else 50
1863+ else :
1864+ return int (value )
1865+
1866+
18581867 @property
18591868 def vpc_cidr (self ) -> str :
18601869 return self .environ ['azul_vpc_cidr' ]
Original file line number Diff line number Diff line change @@ -181,8 +181,9 @@ def waf_match_path(path_regex: str) -> JSON:
181181def add_waf_blocked_alarm (resources : JSON ) -> JSON :
182182 """
183183 Add a metric alarm that trips if the ratio between blocked and overall
184- requests goes above the set threshold. Note that requests blocked by rules
185- listed in :py:attr:`Config.waf_rules_not_logged` are not considered.
184+ requests goes above a deployment-specific threshold. Note that requests
185+ blocked by rules listed in :py:attr:`Config.waf_rules_not_logged` are not
186+ considered.
186187 """
187188 if not config .enable_monitoring :
188189 return resources
@@ -208,7 +209,6 @@ def add_waf_blocked_alarm(resources: JSON) -> JSON:
208209 ]
209210 m_sum = '+' .join (f'm{ i } ' for i in range (1 , len (metrics )))
210211 expression = f'({ m_sum } )/(m0+{ m_sum } )*100'
211- threshold = 25 if config .deployment_stage == 'prod' else 50
212212
213213 assert 'aws_cloudwatch_metric_alarm' not in resources
214214 return resources | {
@@ -241,7 +241,7 @@ def add_waf_blocked_alarm(resources: JSON) -> JSON:
241241 }
242242 ],
243243 'comparison_operator' : 'GreaterThanThreshold' ,
244- 'threshold' : threshold ,
244+ 'threshold' : config . blocked_alarm_threshold ,
245245 'evaluation_periods' : 1 ,
246246 'datapoints_to_alarm' : 1 ,
247247 'alarm_actions' : ['${data.aws_sns_topic.monitoring.arn}' ],
You can’t perform that action at this time.
0 commit comments