Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ import unicorn from 'eslint-plugin-unicorn';
import { defineConfig, globalIgnores } from 'eslint/config';
import tseslint from 'typescript-eslint';

import { FlatCompat } from '@eslint/eslintrc';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

export default defineConfig([
globalIgnores([
'**/*/coverage/*',
Expand Down
4 changes: 4 additions & 0 deletions infrastructure/terraform/components/nudge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
| <a name="input_aws_account_id"></a> [aws\_account\_id](#input\_aws\_account\_id) | The AWS Account ID (numeric) | `string` | n/a | yes |
| <a name="input_component"></a> [component](#input\_component) | The variable encapsulating the name of this component | `string` | `"nudge"` | no |
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A map of default tags to apply to all taggable resources within the component | `map(string)` | `{}` | no |
| <a name="input_enable_event_anomaly_detection"></a> [enable\_event\_anomaly\_detection](#input\_enable\_event\_anomaly\_detection) | Enable CloudWatch anomaly detection alarm for inbound event queue message reception | `bool` | `true` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
| <a name="input_event_anomaly_band_width"></a> [event\_anomaly\_band\_width](#input\_event\_anomaly\_band\_width) | The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4. | `number` | `3` | no |
| <a name="input_event_anomaly_evaluation_periods"></a> [event\_anomaly\_evaluation\_periods](#input\_event\_anomaly\_evaluation\_periods) | Number of evaluation periods for the anomaly alarm. Each period is defined by event\_anomaly\_period. | `number` | `2` | no |
| <a name="input_event_anomaly_period"></a> [event\_anomaly\_period](#input\_event\_anomaly\_period) | The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600. | `number` | `300` | no |
| <a name="input_eventbus_account_id"></a> [eventbus\_account\_id](#input\_eventbus\_account\_id) | The AWS Account ID for the event bus | `string` | n/a | yes |
| <a name="input_force_destroy"></a> [force\_destroy](#input\_force\_destroy) | Flag to force deletion of S3 buckets | `bool` | `false` | no |
| <a name="input_force_lambda_code_deploy"></a> [force\_lambda\_code\_deploy](#input\_force\_lambda\_code\_deploy) | If the lambda package in s3 has the same commit id tag as the terraform build branch, the lambda will not update automatically. Set to True if making changes to Lambda code from on the same commit for example during development | `bool` | `false` | no |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "aws_cloudwatch_metric_alarm" "inbound_event_subscriber_anomaly" {
count = var.enable_event_anomaly_detection ? 1 : 0

alarm_name = "${local.csi}-inbound-event-subscriber-anomaly"
alarm_description = "ANOMALY: Detects anomalous patterns in messages received from the inbound event queue"
comparison_operator = "LessThanLowerOrGreaterThanUpperThreshold"
evaluation_periods = var.event_anomaly_evaluation_periods
threshold_metric_id = "ad1"
treat_missing_data = "notBreaching"

metric_query {
id = "m1"
return_data = true

metric {
metric_name = "NumberOfMessagesReceived"
namespace = "AWS/SQS"
period = var.event_anomaly_period
stat = "Sum"

dimensions = {
QueueName = module.sqs_inbound_event.sqs_queue_name
}
}
}

metric_query {
id = "ad1"
expression = "ANOMALY_DETECTION_BAND(m1, ${var.event_anomaly_band_width})"
label = "NumberOfMessagesReceived (expected)"
return_data = true
}

tags = merge(
var.default_tags,
{
Name = "${local.csi}-inbound-event-subscriber-anomaly"
}
)
}
33 changes: 33 additions & 0 deletions infrastructure/terraform/components/nudge/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,36 @@ variable "force_destroy" {
description = "Flag to force deletion of S3 buckets"
default = false
}

##
# CloudWatch Anomaly Detection Variables
##

variable "enable_event_anomaly_detection" {
type = bool
description = "Enable CloudWatch anomaly detection alarm for inbound event queue message reception"
default = true
}

variable "event_anomaly_evaluation_periods" {
type = number
description = "Number of evaluation periods for the anomaly alarm. Each period is defined by event_anomaly_period."
default = 2
}

variable "event_anomaly_period" {
type = number
description = "The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600."
default = 300
}

variable "event_anomaly_band_width" {
type = number
description = "The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4."
default = 3

validation {
condition = var.event_anomaly_band_width >= 2 && var.event_anomaly_band_width <= 10
error_message = "Band width must be between 2 and 10"
}
}
Loading