Repository navigation
CCM-24327: sameday letter breaches lambda #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RossFaulds171
wants to merge
70
commits into
main
from
origin/feature/CCM-24327-sameday-letter-breaches-lambda
Open
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
03a813f
add state machine, popluate supplier config, and dummy lambdas
RossFaulds171 729b9e2
add glue definitions
RossFaulds171 2159b29
run SLA lambdas in parallel
RossFaulds171 c51e94c
add logging to config cache lambda
RossFaulds171 a52a1eb
fix lint issues
RossFaulds171 12dae16
amend glue config
RossFaulds171 acb9ce2
amend return information from populate-supplier-config-cache
RossFaulds171 41bfa40
alphabetise entity types
RossFaulds171 a70b984
fix failing test
RossFaulds171 5fb19f5
CCM-24327: parquet catalog (#734)
masl2 1010ed9
follow zod schema pattern for env variables in breach config lambda
RossFaulds171 23ced32
retrieve entity type from internal datastore
RossFaulds171 e43b854
remove entities from return of config cache lambda
RossFaulds171 027236f
missing newlines and terraform restructuring
RossFaulds171 94f18f1
fix lint issue and change S3 bucket used for config cache
RossFaulds171 f0146df
promote status
RossFaulds171 fcb95e2
remove unnecessary export
RossFaulds171 b862888
Create common package
stevebux 89c4dda
add query and flesh out lambda to produce count
RossFaulds171 d5dd597
fix package-lock.json
RossFaulds171 2846a0a
setup environment variables
RossFaulds171 b16c359
Merge branch 'main' into origin/feature/CCM-24327-sameday-letter-brea…
RossFaulds171 e74a283
fix predicate and sameday parameter
RossFaulds171 88ef827
fix breach_count error in both breach lambdas
RossFaulds171 77d773f
use passed in date in breach lambdas
RossFaulds171 39dbb99
change transformer to extract clientid and campaignid from groupid
RossFaulds171 c7ad32c
Merge branch 'main' into origin/feature/CCM-24327-sameday-letter-brea…
RossFaulds171 775394b
fix broken terraform
RossFaulds171 937e8b4
use correct eventpub name and introduce count in terraform
RossFaulds171 d49677f
remove moved section
RossFaulds171 4b6158b
amend query
RossFaulds171 43425d1
fix failing test on query
RossFaulds171 5f7cb88
add sameday filtering to query
RossFaulds171 bb90cb5
add sameday filtering to query
RossFaulds171 ba35cdf
Merge branch 'main' into origin/feature/CCM-24327-sameday-letter-brea…
RossFaulds171 8d42559
fix package json
RossFaulds171 76e2343
promote specificationid
RossFaulds171 9c6b8a2
revert standard breach to make merging easier with sameday branch
RossFaulds171 8de6e38
amend package-lock.json for standard breach
RossFaulds171 bcf81b5
Merge branch 'main' into origin/feature/CCM-24327-sameday-letter-brea…
RossFaulds171 f546ef5
fix vulnerabilities
RossFaulds171 c5d5126
Fix dependency vulnerabilities
stevebux c41aa38
fix linting issue
RossFaulds171 bda5910
rename metric
RossFaulds171 512887c
Merge branch 'main' into origin/feature/CCM-24327-sameday-letter-brea…
RossFaulds171 8f6b45d
fix test, and build after pnpm repository change
RossFaulds171 b0b34f3
fix dynamic environment build
RossFaulds171 ad480f5
remove duplicate entry
RossFaulds171 a40b412
add eventbridge scheduler for sla breaches - but turned off
RossFaulds171 0cf0d8f
add alarm for sameday sla breaches
RossFaulds171 df7c9c1
amend emf logging and tests
RossFaulds171 bfb294f
fix alarm
RossFaulds171 b93ab45
amend sameday breach alarm logic
RossFaulds171 739758b
handle date and time in state machine
RossFaulds171 3003d75
Merge branch 'main' into origin/feature/CCM-24327-sameday-letter-brea…
RossFaulds171 c5f72a4
Merge branch 'main' into origin/feature/CCM-24327-sameday-letter-brea…
RossFaulds171 cc004aa
fix pnpm-lock file
RossFaulds171 4193ebc
modify eventbridge schedule
RossFaulds171 072be11
Folloq redirects upgrade
stevebux 202e442
fix vulnerability
RossFaulds171 4bfa103
Bump python version
stevebux e87815d
tidy up pre PR
RossFaulds171 0e8e439
added test coverage
RossFaulds171 dd3a534
add trino and address some PR comments
RossFaulds171 1314a30
Merge branch 'main' into origin/feature/CCM-24327-sameday-letter-brea…
RossFaulds171 828dc90
fix lock file
RossFaulds171 ced6ed1
addressing pr comments
RossFaulds171 aecf7af
add in letter-sla-breaches
RossFaulds171 ae9ffb7
fix pnpm-lock.yaml
RossFaulds171 adfda06
more peer review changes
RossFaulds171 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
infrastructure/terraform/components/api/athena_workgroup_reporting.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| resource "aws_athena_workgroup" "reporting" { | ||
| name = local.csi | ||
| description = "Supplier API Athena Workgroup for ${var.environment}" | ||
| force_destroy = true | ||
|
|
||
| configuration { | ||
| enforce_workgroup_configuration = true | ||
|
|
||
| result_configuration { | ||
| expected_bucket_owner = var.aws_account_id | ||
| output_location = "s3://${module.s3bucket_reporting.bucket}/athena-output/" | ||
|
|
||
| encryption_configuration { | ||
| encryption_option = "SSE_KMS" | ||
| kms_key_arn = module.kms.key_arn | ||
| } | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
infrastructure/terraform/components/api/cloudwatch_log_group_eventpub_parquet_firehose.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| resource "aws_cloudwatch_log_group" "eventpub_parquet_firehose" { | ||
| count = local.eventpub_parquet_enabled ? 1 : 0 | ||
|
|
||
| name = "/aws/firehose/${local.csi}-eventpub-parquet" | ||
| kms_key_id = module.kms.key_arn | ||
| retention_in_days = var.log_retention_in_days | ||
| } |
6 changes: 6 additions & 0 deletions
6
infrastructure/terraform/components/api/cloudwatch_log_stream_eventpub_parquet_firehose.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| resource "aws_cloudwatch_log_stream" "eventpub_parquet_firehose" { | ||
| count = local.eventpub_parquet_enabled ? 1 : 0 | ||
|
|
||
| name = "extended_s3" | ||
| log_group_name = aws_cloudwatch_log_group.eventpub_parquet_firehose[0].name | ||
| } |
23 changes: 23 additions & 0 deletions
23
infrastructure/terraform/components/api/cloudwatch_metric_alarm_sameday_breaches.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| resource "aws_cloudwatch_metric_alarm" "sameday_breaches" { | ||
| count = local.eventpub_parquet_enabled ? 1 : 0 | ||
|
|
||
| alarm_name = "${local.csi}-sameday-breaches" | ||
| alarm_description = "RELIABILITY: Letters have breached the same-day SLA" | ||
|
|
||
| namespace = module.populate_sameday_breaches[0].function_name | ||
| metric_name = "SamedayBreachTotal" | ||
| statistic = "Maximum" | ||
| period = 300 | ||
|
|
||
| evaluation_periods = 1 | ||
| threshold = 0 | ||
| comparison_operator = "GreaterThanThreshold" | ||
| # The total is only published once a day at 7am; hold the last state between runs | ||
| treat_missing_data = "ignore" | ||
|
|
||
| actions_enabled = false | ||
| alarm_actions = [] | ||
| ok_actions = [] | ||
| insufficient_data_actions = [] | ||
|
RossFaulds171 marked this conversation as resolved.
Resolved
|
||
| tags = local.default_tags | ||
| } | ||
60 changes: 60 additions & 0 deletions
60
infrastructure/terraform/components/api/glue_catalog_table_eventpub_parquet.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| resource "aws_glue_catalog_table" "eventpub_parquet" { | ||
| count = local.eventpub_parquet_enabled ? 1 : 0 | ||
| name = "${replace(local.csi, "-", "_")}_eventpub" | ||
| database_name = aws_glue_catalog_database.supplier.name | ||
| table_type = "EXTERNAL_TABLE" | ||
|
|
||
| parameters = { | ||
| EXTERNAL = "TRUE" | ||
| classification = "parquet" | ||
| "parquet.compress" = "SNAPPY" | ||
|
|
||
| # Athena derives partitions from these properties, so none are registered in Glue | ||
| "projection.enabled" = "true" | ||
| "projection.__year.type" = "integer" | ||
| "projection.__year.range" = "2025,2050" | ||
| "projection.__year.digits" = "4" | ||
| "projection.__month.type" = "integer" | ||
| "projection.__month.range" = "1,12" | ||
| "projection.__month.digits" = "2" | ||
| "projection.__day.type" = "integer" | ||
| "projection.__day.range" = "1,31" | ||
| "projection.__day.digits" = "2" | ||
| "storage.location.template" = "s3://${module.s3bucket_reporting.bucket}/parquet/eventpub/__year=$${__year}/__month=$${__month}/__day=$${__day}/" | ||
| } | ||
|
|
||
| storage_descriptor { | ||
| location = "s3://${module.s3bucket_reporting.bucket}/parquet/eventpub/" | ||
| input_format = "org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat" | ||
| output_format = "org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat" | ||
|
|
||
| ser_de_info { | ||
| name = "ParquetHiveSerDe" | ||
| serialization_library = "org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe" | ||
| } | ||
|
|
||
| dynamic "columns" { | ||
| for_each = local.eventpub_parquet_table_columns | ||
|
|
||
| content { | ||
| name = columns.value.name | ||
| type = columns.value.type | ||
| } | ||
| } | ||
| } | ||
|
|
||
| partition_keys { | ||
| name = "__year" | ||
| type = "string" | ||
| } | ||
|
|
||
| partition_keys { | ||
| name = "__month" | ||
| type = "string" | ||
| } | ||
|
|
||
| partition_keys { | ||
| name = "__day" | ||
| type = "string" | ||
| } | ||
| } |
108 changes: 108 additions & 0 deletions
108
infrastructure/terraform/components/api/glue_catalog_tables_supplier_config_cache.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| locals { | ||
| supplier_config_cache_table_columns = { | ||
| supplier = [ | ||
| { name = "pk", type = "string" }, | ||
| { name = "sk", type = "string" }, | ||
| { name = "channelType", type = "string" }, | ||
| { name = "dailyCapacity", type = "bigint" }, | ||
| { name = "id", type = "string" }, | ||
| { name = "name", type = "string" }, | ||
| { name = "status", type = "string" }, | ||
| ] | ||
| volume-group = [ | ||
| { name = "pk", type = "string" }, | ||
| { name = "sk", type = "string" }, | ||
| { name = "description", type = "string" }, | ||
| { name = "endDate", type = "string" }, | ||
| { name = "id", type = "string" }, | ||
| { name = "name", type = "string" }, | ||
| { name = "startDate", type = "string" }, | ||
| { name = "status", type = "string" }, | ||
| ] | ||
| supplier-pack = [ | ||
| { name = "pk", type = "string" }, | ||
| { name = "sk", type = "string" }, | ||
| { name = "approval", type = "string" }, | ||
| { name = "id", type = "string" }, | ||
| { name = "packSpecificationId", type = "string" }, | ||
| { name = "status", type = "string" }, | ||
| { name = "supplierId", type = "string" }, | ||
| ] | ||
| letter-variant = [ | ||
| { name = "pk", type = "string" }, | ||
| { name = "sk", type = "string" }, | ||
| { name = "campaignIds", type = "array<string>" }, | ||
| { name = "clientId", type = "string" }, | ||
| { name = "constraints", type = "struct<blackCoveragePercentage:struct<operator:string,value:double>,colourCoveragePercentage:struct<operator:string,value:double>,deliveryDays:struct<operator:string,value:double>,sheets:struct<operator:string,value:double>,sides:struct<operator:string,value:double>>" }, | ||
| { name = "description", type = "string" }, | ||
| { name = "id", type = "string" }, | ||
| { name = "name", type = "string" }, | ||
| { name = "packSpecificationIds", type = "array<string>" }, | ||
| { name = "priority", type = "bigint" }, | ||
| { name = "status", type = "string" }, | ||
| { name = "supplierId", type = "string" }, | ||
| { name = "type", type = "string" }, | ||
| { name = "volumeGroupId", type = "string" }, | ||
| ] | ||
| pack-specification = [ | ||
| { name = "pk", type = "string" }, | ||
| { name = "sk", type = "string" }, | ||
| { name = "assembly", type = "struct<duplex:boolean,envelopeId:string,features:array<string>,insertIds:array<string>,paper:struct<colour:string,id:string,name:string,recycled:boolean,size:string,weightGSM:double>,printColour:string>" }, | ||
| { name = "billingId", type = "string" }, | ||
| { name = "constraints", type = "struct<blackCoveragePercentage:struct<operator:string,value:double>,colourCoveragePercentage:struct<operator:string,value:double>,deliveryDays:struct<operator:string,value:double>,sheets:struct<operator:string,value:double>,sides:struct<operator:string,value:double>>" }, | ||
| { name = "createdAt", type = "string" }, | ||
| { name = "description", type = "string" }, | ||
| { name = "id", type = "string" }, | ||
| { name = "name", type = "string" }, | ||
| { name = "postage", type = "struct<deliveryDays:double,id:string,maxThicknessMm:double,maxWeightGrams:double,size:string>" }, | ||
| { name = "status", type = "string" }, | ||
| { name = "updatedAt", type = "string" }, | ||
| { name = "version", type = "bigint" }, | ||
| ] | ||
| supplier-allocation = [ | ||
| { name = "pk", type = "string" }, | ||
| { name = "sk", type = "string" }, | ||
| { name = "allocationPercentage", type = "double" }, | ||
| { name = "id", type = "string" }, | ||
| { name = "status", type = "string" }, | ||
| { name = "supplier", type = "string" }, | ||
| { name = "volumeGroup", type = "string" }, | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_glue_catalog_table" "supplier_config_cache" { | ||
| for_each = local.supplier_config_cache_table_columns | ||
| name = "${replace(local.csi, "-", "_")}_${replace(each.key, "-", "_")}" | ||
| database_name = aws_glue_catalog_database.supplier.name | ||
| table_type = "EXTERNAL_TABLE" | ||
|
|
||
| parameters = { | ||
| EXTERNAL = "TRUE" | ||
| classification = "json" | ||
| } | ||
|
|
||
| storage_descriptor { | ||
| location = "s3://${module.s3bucket_reporting.bucket}/supplier_config_cache/${each.key}/" | ||
| input_format = "org.apache.hadoop.mapred.TextInputFormat" | ||
| output_format = "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat" | ||
|
|
||
| ser_de_info { | ||
| name = "OpenXJsonSerDe" | ||
| serialization_library = "org.openx.data.jsonserde.JsonSerDe" | ||
|
|
||
| parameters = { | ||
| "case.insensitive" = "false" | ||
| } | ||
| } | ||
|
|
||
| dynamic "columns" { | ||
| for_each = each.value | ||
|
|
||
| content { | ||
| name = columns.value.name | ||
| type = columns.value.type | ||
| } | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
infrastructure/terraform/components/api/iam_role_eventpub_parquet_firehose.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| resource "aws_iam_role" "eventpub_parquet_firehose" { | ||
| count = local.eventpub_parquet_enabled ? 1 : 0 | ||
|
|
||
| name = "${local.csi}-eventpub-parquet-firehose" | ||
| assume_role_policy = data.aws_iam_policy_document.eventpub_parquet_firehose_assume_role.json | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "eventpub_parquet_firehose_assume_role" { | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["sts:AssumeRole"] | ||
|
|
||
| principals { | ||
| type = "Service" | ||
| identifiers = ["firehose.amazonaws.com"] | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
infrastructure/terraform/components/api/iam_role_eventpub_parquet_sns.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| resource "aws_iam_role" "eventpub_parquet_sns" { | ||
| count = local.eventpub_parquet_enabled ? 1 : 0 | ||
|
|
||
| name = "${local.csi}-eventpub-parquet-sns" | ||
| assume_role_policy = data.aws_iam_policy_document.eventpub_parquet_sns_assume_role.json | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "eventpub_parquet_sns_assume_role" { | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["sts:AssumeRole"] | ||
|
|
||
| principals { | ||
| type = "Service" | ||
| identifiers = ["sns.amazonaws.com"] | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
infrastructure/terraform/components/api/iam_role_letter_sla_breaches.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| resource "aws_iam_role" "letter_sla_breaches" { | ||
| count = local.eventpub_parquet_enabled ? 1 : 0 | ||
| name = "${local.csi}-letter-sla-breaches-sfn" | ||
| description = "Execution role for the letter SLA breaches state machine" | ||
| assume_role_policy = data.aws_iam_policy_document.letter_sla_breaches_trust_policy.json | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "letter_sla_breaches_trust_policy" { | ||
| statement { | ||
| effect = "Allow" | ||
| actions = ["sts:AssumeRole"] | ||
|
|
||
| principals { | ||
| type = "Service" | ||
| identifiers = ["states.amazonaws.com"] | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.