Skip to content

Commit

Permalink
New: [AEA-4488] - Adds NPPTS Slack Alerts (#1339)
Browse files Browse the repository at this point in the history
## Summary

- ✨ New Feature

### Details

Adds NPPTS Slack Alerts
  • Loading branch information
JackSpagnoliNHS authored Oct 4, 2024
1 parent 08ab654 commit 9bfb428
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 7 deletions.
91 changes: 84 additions & 7 deletions SAMtemplates/alarms/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Description: |
Parameters:
StackName:
Type: String
Default: none

GetMyPrescriptionsFunctionName:
Type: String
Default: none

EnrichPrescriptionsFunctionName:
Type: String

EnableAlerts:
Type: String
Expand All @@ -23,14 +24,14 @@ Resources:
ServiceSearchErrorsLogsMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
FilterName: GetMyPrescriptionsErrors
# Match logs with $.message starting with "call to service search unsuccessful"
FilterPattern: !Sub '{ ($.level = "WARN") && ($.function_name = "${GetMyPrescriptionsFunctionName}") && $.message = %call to service search unsuccessful% }' # function_name included to allow it to be set as a dimension on the metric
FilterName: ServiceSearchErrors
# Match logs with $.message starting with "error in request to serviceSearch"
FilterPattern: !Sub '{ ($.level = "ERROR") && ($.function_name = "${GetMyPrescriptionsFunctionName}") && $.message = %error in request to serviceSearch% }' # function_name included to allow it to be set as a dimension on the metric
LogGroupName:
Fn::ImportValue: !Sub ${StackName}:functions:${GetMyPrescriptionsFunctionName}:LambdaLogGroupName
MetricTransformations:
- MetricNamespace: LambdaLogFilterMetrics
MetricName: ErrorCount
MetricName: ServiceSearchErrorCount
MetricValue: 1
Unit: Count
Dimensions: # dimensions for a logs filter metric can only be a field/value from the filter pattern
Expand All @@ -43,7 +44,7 @@ Resources:
AlarmDescription: Count of Service Search errors
AlarmName: !Sub ${StackName}_ServiceSearch_Errors
Namespace: LambdaLogFilterMetrics
MetricName: ErrorCount
MetricName: ServiceSearchErrorCount
Dimensions:
- Name: FunctionName
Value: !Ref GetMyPrescriptionsFunctionName
Expand Down Expand Up @@ -107,3 +108,79 @@ Resources:
- !ImportValue lambda-resources:SlackAlertsSnsTopicArn
OKActions:
- !ImportValue lambda-resources:SlackAlertsSnsTopicArn

GetMyPrescriptionsErrorsLogsMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
FilterName: GetMyPrescriptionsErrors
FilterPattern: !Sub '{ ($.level = "ERROR") && ($.function_name = "${GetMyPrescriptionsFunctionName}") && ($.message != %error in request to serviceSearch%) }'
LogGroupName:
Fn::ImportValue: !Sub ${StackName}:functions:${GetMyPrescriptionsFunctionName}:LambdaLogGroupName
MetricTransformations:
- MetricNamespace: LambdaLogFilterMetrics
MetricName: ErrorCount
MetricValue: 1
Unit: Count
Dimensions:
- Key: FunctionName
Value: $.function_name

GetMyPrescriptionsErrorsAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: Count of GetMyPrescriptions errors
AlarmName: !Sub ${StackName}_GetMyPrescriptions_Errors
Namespace: LambdaLogFilterMetrics
MetricName: ErrorCount
Dimensions:
- Name: FunctionName
Value: !Ref GetMyPrescriptionsFunctionName
Period: 60 #seconds
EvaluationPeriods: 1
Statistic: Sum
ComparisonOperator: GreaterThanOrEqualToThreshold
Threshold: 1
Unit: Count
TreatMissingData: notBreaching
ActionsEnabled: !Ref EnableAlerts
AlarmActions:
- !ImportValue lambda-resources:SlackAlertsSnsTopicArn
InsufficientDataActions:
- !ImportValue lambda-resources:SlackAlertsSnsTopicArn
OKActions:
- !ImportValue lambda-resources:SlackAlertsSnsTopicArn

EnrichPrescriptionsErrorsLogsMetricFilter:
Type: AWS::Logs::MetricFilter
Properties:
FilterName: EnrichPrescriptionsErrors
FilterPattern: ERROR
LogGroupName:
Fn::ImportValue: !Sub ${StackName}:functions:${EnrichPrescriptionsFunctionName}:LambdaLogGroupName
MetricTransformations:
- MetricNamespace: LambdaLogFilterMetrics
MetricName: !Sub ${StackName}EnrichPrescriptionsErrorCount
MetricValue: 1
Unit: Count

EnrichPrescriptionsErrorsAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: Count of EnrichPrescriptions errors
AlarmName: !Sub ${StackName}_EnrichPrescriptions_Errors
Namespace: LambdaLogFilterMetrics
MetricName: !Sub ${StackName}EnrichPrescriptionsErrorCount
Period: 60 #seconds
EvaluationPeriods: 1
Statistic: Sum
ComparisonOperator: GreaterThanOrEqualToThreshold
Threshold: 1
Unit: Count
TreatMissingData: notBreaching
ActionsEnabled: !Ref EnableAlerts
AlarmActions:
- !ImportValue lambda-resources:SlackAlertsSnsTopicArn
InsufficientDataActions:
- !ImportValue lambda-resources:SlackAlertsSnsTopicArn
OKActions:
- !ImportValue lambda-resources:SlackAlertsSnsTopicArn
1 change: 1 addition & 0 deletions SAMtemplates/main_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,6 @@ Resources:
Parameters:
StackName: !Ref AWS::StackName
GetMyPrescriptionsFunctionName: !GetAtt Functions.Outputs.GetMyPrescriptionsFunctionName
EnrichPrescriptionsFunctionName: !GetAtt Functions.Outputs.EnrichPrescriptionsFunctionName
EnableAlerts: !Ref EnableAlerts
ConcurrencyThreshold: 10000 #FIXME: Set appropriate threshold based on load tests.

0 comments on commit 9bfb428

Please sign in to comment.