Skip to content

Commit

Permalink
[CES-197] Add Gate 0 profile for auth functions (#1242)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrea Grillo <[email protected]>
  • Loading branch information
mamu0 and Krusty93 authored Oct 14, 2024
1 parent 4a9b45e commit 4dabc71
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 180 deletions.
140 changes: 10 additions & 130 deletions src/domains/citizen-auth-app/04_function_lollipop.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -191,7 +191,7 @@ resource "azurerm_monitor_autoscale_setting" "function_lollipop_itn" {

capacity {
default = 10
minimum = 5
minimum = 4
maximum = 20
}

Expand Down Expand Up @@ -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\"}"

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -637,6 +515,8 @@ resource "azurerm_monitor_autoscale_setting" "function_lollipop_itn" {
}
}
}

tags = var.tags
}

# ---------------------------------
Expand Down
15 changes: 1 addition & 14 deletions src/domains/citizen-auth-app/07_function_fast_login.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
149 changes: 113 additions & 36 deletions src/domains/citizen-auth-app/09_function_profile.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
},
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4dabc71

Please sign in to comment.