From 4dabc718ea51f6c520d53d80adea969082cf2b2a Mon Sep 17 00:00:00 2001 From: Mario Mupo <43968294+mamu0@users.noreply.github.com> Date: Mon, 14 Oct 2024 23:27:49 +0200 Subject: [PATCH] [CES-197] Add Gate 0 profile for auth functions (#1242) Co-authored-by: Andrea Grillo --- .../citizen-auth-app/04_function_lollipop.tf | 140 ++-------------- .../07_function_fast_login.tf | 15 +- .../citizen-auth-app/09_function_profile.tf | 149 +++++++++++++----- 3 files changed, 124 insertions(+), 180 deletions(-) diff --git a/src/domains/citizen-auth-app/04_function_lollipop.tf b/src/domains/citizen-auth-app/04_function_lollipop.tf index 5bacf10db..bbfab74f4 100644 --- a/src/domains/citizen-auth-app/04_function_lollipop.tf +++ b/src/domains/citizen-auth-app/04_function_lollipop.tf @@ -181,7 +181,7 @@ module "function_lollipop_staging_slot_itn" { } resource "azurerm_monitor_autoscale_setting" "function_lollipop_itn" { - name = "${replace(module.function_lollipop_itn.name, "-fn-", "-as-")}-01" + name = replace(module.function_lollipop_itn.name, "-fn-", "-as-") resource_group_name = azurerm_resource_group.lollipop_rg_itn.name location = local.itn_location target_resource_id = module.function_lollipop_itn.app_service_plan_id @@ -191,7 +191,7 @@ resource "azurerm_monitor_autoscale_setting" "function_lollipop_itn" { capacity { default = 10 - minimum = 5 + minimum = 4 maximum = 20 } @@ -299,119 +299,6 @@ resource "azurerm_monitor_autoscale_setting" "function_lollipop_itn" { } } - profile { - name = "night" - - capacity { - default = 10 - minimum = 3 - maximum = 15 - } - - recurrence { - timezone = "W. Europe Standard Time" - hours = [23] - minutes = [0] - days = [ - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - "Sunday" - ] - } - - rule { - metric_trigger { - metric_name = "Requests" - metric_resource_id = module.function_lollipop_itn.id - metric_namespace = "microsoft.web/sites" - time_grain = "PT1M" - statistic = "Max" - time_window = "PT1M" - time_aggregation = "Maximum" - operator = "GreaterThan" - threshold = 3200 - divide_by_instance_count = true - } - - scale_action { - direction = "Increase" - type = "ChangeCount" - value = "2" - cooldown = "PT1M" - } - } - - rule { - metric_trigger { - metric_name = "CpuPercentage" - metric_resource_id = module.function_lollipop_itn.app_service_plan_id - metric_namespace = "microsoft.web/serverfarms" - time_grain = "PT1M" - statistic = "Max" - time_window = "PT1M" - time_aggregation = "Maximum" - operator = "GreaterThan" - threshold = 45 - divide_by_instance_count = false - } - - scale_action { - direction = "Increase" - type = "ChangeCount" - value = "3" - cooldown = "PT2M" - } - } - - rule { - metric_trigger { - metric_name = "Requests" - metric_resource_id = module.function_lollipop_itn.id - metric_namespace = "microsoft.web/sites" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "LessThan" - threshold = 500 - divide_by_instance_count = true - } - - scale_action { - direction = "Decrease" - type = "ChangeCount" - value = "1" - cooldown = "PT1M" - } - } - - rule { - metric_trigger { - metric_name = "CpuPercentage" - metric_resource_id = module.function_lollipop_itn.app_service_plan_id - metric_namespace = "microsoft.web/serverfarms" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "LessThan" - threshold = 20 - divide_by_instance_count = false - } - - scale_action { - direction = "Decrease" - type = "ChangeCount" - value = "1" - cooldown = "PT2M" - } - } - } - profile { name = "{\"name\":\"default\",\"for\":\"evening\"}" @@ -526,26 +413,17 @@ resource "azurerm_monitor_autoscale_setting" "function_lollipop_itn" { } profile { - name = "{\"name\":\"default\",\"for\":\"night\"}" + name = "wallet_gate0" - recurrence { + fixed_date { timezone = "W. Europe Standard Time" - hours = [5] - minutes = [0] - days = [ - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - "Sunday" - ] + start = "2024-10-15T08:00:00.000Z" + end = "2024-10-15T23:30:00.000Z" } capacity { - default = 10 - minimum = 3 + default = 20 + minimum = 15 maximum = 30 } @@ -637,6 +515,8 @@ resource "azurerm_monitor_autoscale_setting" "function_lollipop_itn" { } } } + + tags = var.tags } # --------------------------------- diff --git a/src/domains/citizen-auth-app/07_function_fast_login.tf b/src/domains/citizen-auth-app/07_function_fast_login.tf index 498daee95..596a306d0 100644 --- a/src/domains/citizen-auth-app/07_function_fast_login.tf +++ b/src/domains/citizen-auth-app/07_function_fast_login.tf @@ -201,23 +201,10 @@ module "function_fast_login_itn_autoscale" { minutes = 59 } }, - low_load = { - name = "night" - minimum = 3 - default = 10 - start = { - hour = 23 - minutes = 00 - } - end = { - hour = 05 - minutes = 00 - } - }, normal_load = { minimum = 3 default = 10 - } + }, maximum = 30 } diff --git a/src/domains/citizen-auth-app/09_function_profile.tf b/src/domains/citizen-auth-app/09_function_profile.tf index 82cb1a2af..3dbf43706 100644 --- a/src/domains/citizen-auth-app/09_function_profile.tf +++ b/src/domains/citizen-auth-app/09_function_profile.tf @@ -220,12 +220,13 @@ module "function_profile_staging_slot" { count = var.function_profile_count source = "git::https://github.com/pagopa/terraform-azurerm-v3.git//function_app_slot?ref=v8.44.0" - name = "staging" - location = local.itn_location - resource_group_name = azurerm_resource_group.function_profile_rg[count.index].name - function_app_id = module.function_profile[count.index].id - app_service_plan_id = module.function_profile[count.index].app_service_plan_id - health_check_path = "/api/v1/info" + name = "staging" + location = local.itn_location + resource_group_name = azurerm_resource_group.function_profile_rg[count.index].name + function_app_id = module.function_profile[count.index].id + app_service_plan_id = module.function_profile[count.index].app_service_plan_id + health_check_path = "/api/v1/info" + health_check_maxpingfailures = 2 storage_account_name = module.function_profile[count.index].storage_account.name storage_account_access_key = module.function_profile[count.index].storage_account.primary_access_key @@ -273,21 +274,7 @@ resource "azurerm_monitor_autoscale_setting" "function_profile" { capacity = { default = 10 - minimum = 5 - maximum = 30 - } - }, - { - name = "{\"name\":\"default\",\"for\":\"night\"}", - - recurrence = { - hours = 5 - minutes = 0 - } - - capacity = { - default = 10 - minimum = 5 + minimum = 3 maximum = 30 } }, @@ -301,21 +288,7 @@ resource "azurerm_monitor_autoscale_setting" "function_profile" { capacity = { default = 10 - minimum = 5 - maximum = 30 - } - }, - { - name = "night" - - recurrence = { - hours = 23 - minutes = 0 - } - - capacity = { - default = 10 - minimum = 5 + minimum = 4 maximum = 30 } } @@ -440,6 +413,110 @@ resource "azurerm_monitor_autoscale_setting" "function_profile" { } } } + + profile { + name = "wallet_gate0" + + fixed_date { + timezone = "W. Europe Standard Time" + start = "2024-10-15T08:00:00.000Z" + end = "2024-10-15T23:30:00.000Z" + } + + capacity { + default = 20 + minimum = 15 + maximum = 30 + } + + rule { + metric_trigger { + metric_name = "Requests" + metric_resource_id = module.function_profile[count.index].id + metric_namespace = "microsoft.web/sites" + time_grain = "PT1M" + statistic = "Max" + time_window = "PT2M" + time_aggregation = "Maximum" + operator = "GreaterThan" + threshold = 2000 + divide_by_instance_count = true + } + + scale_action { + direction = "Increase" + type = "ChangeCount" + value = "2" + cooldown = "PT1M" + } + } + + rule { + metric_trigger { + metric_name = "CpuPercentage" + metric_resource_id = module.function_profile[count.index].app_service_plan_id + metric_namespace = "microsoft.web/serverfarms" + time_grain = "PT1M" + statistic = "Max" + time_window = "PT1M" + time_aggregation = "Maximum" + operator = "GreaterThan" + threshold = 40 + divide_by_instance_count = false + } + + scale_action { + direction = "Increase" + type = "ChangeCount" + value = "4" + cooldown = "PT1M" + } + } + + rule { + metric_trigger { + metric_name = "Requests" + metric_resource_id = module.function_profile[count.index].id + metric_namespace = "microsoft.web/sites" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "LessThan" + threshold = 200 + divide_by_instance_count = true + } + + scale_action { + direction = "Decrease" + type = "ChangeCount" + value = "1" + cooldown = "PT1M" + } + } + + rule { + metric_trigger { + metric_name = "CpuPercentage" + metric_resource_id = module.function_profile[count.index].app_service_plan_id + metric_namespace = "microsoft.web/serverfarms" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "LessThan" + threshold = 15 + divide_by_instance_count = false + } + + scale_action { + direction = "Decrease" + type = "ChangeCount" + value = "1" + cooldown = "PT2M" + } + } + } } ## Alerts