Skip to content

Commit e99cd7e

Browse files
committed
Fix: Many false positives for waf_blocked alarm in idle deployments (#7642)
1 parent 0817583 commit e99cd7e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

terraform/api_gateway.tf.json.template.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def waf_match_path(path_regex: str) -> JSON:
181181
def 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 25%. Note that requests blocked by rules listed in
185-
:py:attr:`Config.waf_rules_not_logged` are not considered.
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.
186186
"""
187187
if not config.enable_monitoring:
188188
return resources
@@ -208,6 +208,7 @@ def add_waf_blocked_alarm(resources: JSON) -> JSON:
208208
]
209209
m_sum = '+'.join(f'm{i}' for i in range(1, len(metrics)))
210210
expression = f'({m_sum})/(m0+{m_sum})*100'
211+
threshold = 25 if config.deployment_stage == 'prod' else 50
211212

212213
assert 'aws_cloudwatch_metric_alarm' not in resources
213214
return resources | {
@@ -240,7 +241,7 @@ def add_waf_blocked_alarm(resources: JSON) -> JSON:
240241
}
241242
],
242243
'comparison_operator': 'GreaterThanThreshold',
243-
'threshold': 25, # percent blocked of total requests in a period
244+
'threshold': threshold,
244245
'evaluation_periods': 1,
245246
'datapoints_to_alarm': 1,
246247
'alarm_actions': ['${data.aws_sns_topic.monitoring.arn}'],

0 commit comments

Comments
 (0)