Skip to content

Commit

Permalink
feat: autoscaling uses the new metric_calculator implemention from go…
Browse files Browse the repository at this point in the history
…soline; (#129)
  • Loading branch information
j4k4 authored Aug 22, 2024
1 parent c370775 commit 2b9cc44
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ Terraform module which creates a ecs app
| <a name="input_log_router_stop_timeout"></a> [log\_router\_stop\_timeout](#input\_log\_router\_stop\_timeout) | Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own | `number` | `60` | no |
| <a name="input_log_router_type"></a> [log\_router\_type](#input\_log\_router\_type) | The log router type to use | `string` | `"fluentbit"` | no |
| <a name="input_metric_based_autoscaling_ignore_changes_min_max_capacity"></a> [metric\_based\_autoscaling\_ignore\_changes\_min\_max\_capacity](#input\_metric\_based\_autoscaling\_ignore\_changes\_min\_max\_capacity) | Whether or not to ignore min\_capacity/max\_capacity changes on the aws\_appautoscaling\_target of the metric based autoscaling module | `bool` | `false` | no |
| <a name="input_metric_calculator_enabled"></a> [metric\_calculator\_enabled](#input\_metric\_calculator\_enabled) | Whether to use the metrics produced by the metric calculator for autoscaling (gosoline feature), see: https://github.com/justtrackio/gosoline | `bool` | `null` | no |
| <a name="input_metric_enabled"></a> [metric\_enabled](#input\_metric\_enabled) | Defines if metrics should be written | `bool` | n/a | yes |
| <a name="input_monitoring_enabled"></a> [monitoring\_enabled](#input\_monitoring\_enabled) | Defines if the monitoring module should be created | `bool` | `true` | no |
| <a name="input_mpr_enabled"></a> [mpr\_enabled](#input\_mpr\_enabled) | Whether to use the StreamMprMessagesPerRunner metric for autoscaling (gosoline feature), see: https://github.com/justtrackio/gosoline | `bool` | `null` | no |
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
| <a name="input_network_mode"></a> [network\_mode](#input\_network\_mode) | The network mode to use for the task. This is required to be `awsvpc` for `FARGATE` `launch_type` or `null` for `EC2` `launch_type` | `string` | `null` | no |
Expand Down
6 changes: 3 additions & 3 deletions autoscaling.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
alb_enabled = length(var.alb_name) > 0
mpr_enabled = var.mpr_enabled == true ? true : (module.this.tags["Type"] == "subscriber" || module.this.tags["Type"] == "consumer") && var.mpr_enabled == null ? true : false
metric_calculator_enabled = var.metric_calculator_enabled == true ? true : (module.this.tags["Type"] == "subscriber" || module.this.tags["Type"] == "consumer") && var.metric_calculator_enabled == null ? true : false
internal_predefined_metric_type = local.alb_enabled ? "ALBRequestCountPerTarget" : "ECSServiceAverageCPUUtilization"
internal_predefined_target_value = local.alb_enabled ? 1000 : 100
internal_customized_target_value = 500
Expand All @@ -11,12 +11,12 @@ locals {
var.autoscaling_enabled &&
!local.customized_autoscaling_enabled
)
autoscaling_customized_metric_name = local.mpr_enabled ? "StreamMprMessagesPerRunner" : var.autoscaling_customized_metric_name
autoscaling_customized_metric_name = local.metric_calculator_enabled ? "PerRunnerStreamMessages" : var.autoscaling_customized_metric_name
customized_autoscaling_enabled = (
var.autoscaling_enabled &&
(
length(var.autoscaling_customized_metric_name) > 0 ||
local.mpr_enabled
local.metric_calculator_enabled
)
)
}
Expand Down
50 changes: 25 additions & 25 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,31 @@ module "container_definition" {
secretOptions = null
}
map_environment = merge({
AWS_DEFAULT_REGION = module.this.aws_region
AWS_SDK_RETRIES = 10
CLOUD_AWS_DEFAULTS_ENDPOINT = ""
CLOUD_AWS_DYNAMODB_CLIENTS_DEFAULT_NAMING_PATTERN = "!nodecode {env}-{group}-{modelId}"
CLOUD_AWS_KINESIS_CLIENTS_DEFAULT_NAMING_PATTERN = "!nodecode {env}-{group}-{streamName}"
CLOUD_AWS_SNS_CLIENTS_DEFAULT_NAMING_PATTERN = "!nodecode {env}-{group}-{topicId}"
CLOUD_AWS_SQS_CLIENTS_DEFAULT_NAMING_PATTERN = "!nodecode {env}-{group}-{queueId}"
ENV = module.this.environment
ENVIRONMENT = module.this.environment
FIXTURE_GROUP_NAME = "$FIXTURE_GROUP_NAME"
LOG_HANDLERS_MAIN_FORMATTER = "json"
LOG_HANDLERS_MAIN_TIMESTAMP_FORMAT = "2006-01-02T15:04:05.999Z07:00"
METRIC_CLOUDWATCH_NAMING_PATTERN = "!nodecode {env}/{group}/{app}"
METRIC_ENABLED = var.metric_enabled
METRIC_WRITER = "cw"
REDIS_DEFAULT_ADDRESS = ""
REDIS_DEFAULT_DIALER = "srv"
REDIS_DEFAULT_NAMING_PATTERN = "!nodecode {name}.{group}.{env}.{family}"
SENTRY_DSN = try(module.sentry[0].dsn, var.sentry_dsn)
SENTRY_ENVIRONMENT = module.this.environment
STREAM_METRICS_MESSAGES_PER_RUNNER_CLOUDWATCH_NAMING_PATTERN = "!nodecode {env}/{group}/{app}"
STREAM_METRICS_MESSAGES_PER_RUNNER_ECS_SERVICE = "{app_group}-{app_name}"
STREAM_METRICS_MESSAGES_PER_RUNNER_DYNAMODB_NAMING_PATTERN = "!nodecode {env}-{modelId}"
TRACING_ADDR_TYPE = "srv"
TRACING_ENABLED = var.tracing_enabled
AWS_DEFAULT_REGION = module.this.aws_region
AWS_SDK_RETRIES = 10
CLOUD_AWS_DEFAULTS_ENDPOINT = ""
CLOUD_AWS_DYNAMODB_CLIENTS_DEFAULT_NAMING_PATTERN = "!nodecode {env}-{group}-{modelId}"
CLOUD_AWS_KINESIS_CLIENTS_DEFAULT_NAMING_PATTERN = "!nodecode {env}-{group}-{streamName}"
CLOUD_AWS_SNS_CLIENTS_DEFAULT_NAMING_PATTERN = "!nodecode {env}-{group}-{topicId}"
CLOUD_AWS_SQS_CLIENTS_DEFAULT_NAMING_PATTERN = "!nodecode {env}-{group}-{queueId}"
ENV = module.this.environment
ENVIRONMENT = module.this.environment
FIXTURE_GROUP_NAME = "$FIXTURE_GROUP_NAME"
LOG_HANDLERS_MAIN_FORMATTER = "json"
LOG_HANDLERS_MAIN_TIMESTAMP_FORMAT = "2006-01-02T15:04:05.999Z07:00"
METRIC_CALCULATOR_ECS_CLUSTER = "{env}"
METRIC_CALCULATOR_ECS_SERVICE = "{app_group}-{app_name}"
METRIC_CALCULATOR_DYNAMODB_NAMING_PATTERN = "!nodecode {env}-{modelId}"
METRIC_CLOUDWATCH_NAMING_PATTERN = "!nodecode {env}/{group}/{app}"
METRIC_ENABLED = var.metric_enabled
METRIC_WRITER = "cw"
REDIS_DEFAULT_ADDRESS = ""
REDIS_DEFAULT_DIALER = "srv"
REDIS_DEFAULT_NAMING_PATTERN = "!nodecode {name}.{group}.{env}.{family}"
SENTRY_DSN = try(module.sentry[0].dsn, var.sentry_dsn)
SENTRY_ENVIRONMENT = module.this.environment
TRACING_ADDR_TYPE = "srv"
TRACING_ENABLED = var.tracing_enabled
}, var.container_map_environment)
map_secrets = var.container_map_secrets
port_mappings = local.port_mappings
Expand Down
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,9 @@ variable "monitoring_enabled" {
description = "Defines if the monitoring module should be created"
}

variable "mpr_enabled" {
variable "metric_calculator_enabled" {
type = bool
description = "Whether to use the StreamMprMessagesPerRunner metric for autoscaling (gosoline feature), see: https://github.com/justtrackio/gosoline"
description = "Whether to use the metrics produced by the metric calculator for autoscaling (gosoline feature), see: https://github.com/justtrackio/gosoline"
default = null
}

Expand Down

0 comments on commit 2b9cc44

Please sign in to comment.