Skip to content

Commit

Permalink
fix: handle budget auto-adjustment events (#419)
Browse files Browse the repository at this point in the history
Update the SRE bot to recognize and ignore spend budget
auto-adjustment notifications.
  • Loading branch information
patheard authored Mar 1, 2024
1 parent e629b12 commit 42e700f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/server/event_handlers/aws.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import re
import os
import urllib.parse
Expand All @@ -23,6 +24,12 @@ def parse(payload, client):
blocks = format_new_iam_user(payload)
elif isinstance(msg, str) and "API Key with value token=" in msg:
blocks = format_api_key_detected(payload, client)
elif (
isinstance(msg, dict)
and {"previousBudgetLimit", "currentBudgetLimit"} <= msg.keys()
):
logging.info(f"Budget auto-adjustment event received: {payload.Message}")
blocks = []
else:
blocks = []
log_ops_message(
Expand Down
13 changes: 13 additions & 0 deletions app/tests/server/event_handlers/test_aws_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ def test_parse_returns_empty_block_if_no_match_and_logs_error(log_ops_message_mo
)


@patch("server.event_handlers.aws.log_ops_message")
def test_parse_returns_empty_block_if_budget_auto_adjustment_event(
log_ops_message_mock,
):
client = MagicMock()
payload = MagicMock(
Message='{"previousBudgetLimit": "1", "currentBudgetLimit": "2"}'
)
response = aws.parse(payload, client)
assert response == []
log_ops_message_mock.assert_not_called()


@patch("server.event_handlers.aws.format_cloudwatch_alarm")
def test_parse_returns_blocks_if_AlarmArn_in_msg(format_cloudwatch_alarm_mock):
client = MagicMock()
Expand Down

0 comments on commit 42e700f

Please sign in to comment.