Skip to content

Commit 0c43ffc

Browse files
npalmgertjanmaasjonico
authored
feat(log): groups per type of logging (#476)
* Refactor to loggroup per tuype of logging * Update modules/runners/variables.tf Co-authored-by: Gertjan Maas <[email protected]> * fix: Queue visibility time has to be >= lambda timeout (#467) * AWS SQS queue visibility times have to be >= the timeout of the associated lambda * error to do so will result in a terraform provisioning error during initial resource creation (apparently not a modification) * hence, setting module.runners.aws_sqs_queue.queued_builds.visibility_timeout_seconds to module.runners.module.runners.aws_lambda_function.scale_up.timeout * Typo Co-authored-by: Gertjan Maas <[email protected]> Co-authored-by: Johannes Nicolai <[email protected]>
1 parent 48fedc5 commit 0c43ffc

File tree

5 files changed

+48
-24
lines changed

5 files changed

+48
-24
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ No requirements.
325325
| lambda\_s3\_bucket | S3 bucket from which to specify lambda functions. This is an alternative to providing local files directly. | `any` | `null` | no |
326326
| lambda\_security\_group\_ids | List of subnets in which the action runners will be launched, the subnets needs to be subnets in the `vpc_id`. | `list(string)` | `[]` | no |
327327
| lambda\_subnet\_ids | List of subnets in which the action runners will be launched, the subnets needs to be subnets in the `vpc_id`. | `list(string)` | `[]` | no |
328-
| logging\_retention\_in\_days | Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653. | `number` | `7` | no |
328+
| logging\_retention\_in\_days | Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653. | `number` | `180` | no |
329329
| manage\_kms\_key | Let the module manage the KMS key. | `bool` | `true` | no |
330330
| minimum\_running\_time\_in\_minutes | The time an ec2 action runner should be running at minimum before terminated if non busy. | `number` | `5` | no |
331331
| role\_path | The path that will be added to role path for created roles, if not set the environment name will be used. | `string` | `null` | no |
@@ -337,13 +337,13 @@ No requirements.
337337
| runner\_binaries\_syncer\_lambda\_zip | File location of the binaries sync lambda zip file. | `string` | `null` | no |
338338
| runner\_extra\_labels | Extra labels for the runners (GitHub). Separate each label by a comma | `string` | `""` | no |
339339
| runner\_iam\_role\_managed\_policy\_arns | Attach AWS or customer-managed IAM policies (by ARN) to the runner IAM role | `list(string)` | `[]` | no |
340-
| runner\_log\_files | (optional) List of logfiles to send to cloudwatch. | <pre>list(object({<br> file_path = string<br> log_stream_name = string<br> }))</pre> | <pre>[<br> {<br> "file_path": "/var/log/messages",<br> "log_stream_name": "{instance_id}/messages"<br> },<br> {<br> "file_path": "/var/log/user-data.log",<br> "log_stream_name": "{instance_id}/user_data"<br> },<br> {<br> "file_path": "/home/ec2-user/actions-runner/_diag/Runner_**.log",<br> "log_stream_name": "{instance_id}/runner"<br> }<br>]</pre> | no |
340+
| runner\_log\_files | (optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details. | <pre>list(object({<br> log_group_name = string<br> prefix_log_group = bool<br> file_path = string<br> log_stream_name = string<br> }))</pre> | <pre>[<br> {<br> "file_path": "/var/log/messages",<br> "log_group_name": "messages",<br> "log_stream_name": "{instance_id}",<br> "prefix_log_group": true<br> },<br> {<br> "file_path": "/var/log/user-data.log",<br> "log_group_name": "user_data",<br> "log_stream_name": "{instance_id}",<br> "prefix_log_group": true<br> },<br> {<br> "file_path": "/home/ec2-user/actions-runner/_diag/Runner_**.log",<br> "log_group_name": "runner",<br> "log_stream_name": "{instance_id}",<br> "prefix_log_group": true<br> }<br>]</pre> | no |
341341
| runners\_lambda\_s3\_key | S3 key for runners lambda function. Required if using S3 bucket to specify lambdas. | `any` | `null` | no |
342342
| runners\_lambda\_s3\_object\_version | S3 object version for runners lambda function. Useful if S3 versioning is enabled on source bucket. | `any` | `null` | no |
343343
| runners\_lambda\_zip | File location of the lambda zip file for scaling runners. | `string` | `null` | no |
344344
| runners\_maximum\_count | The maximum number of runners that will be created. | `number` | `3` | no |
345-
| runners\_scale\_down\_lambda\_timeout | Time out for the scale up lambda in seconds. | `number` | `60` | no |
346-
| runners\_scale\_up\_lambda\_timeout | Time out for the scale down lambda in seconds. | `number` | `180` | no |
345+
| runners\_scale\_down\_lambda\_timeout | Time out for the scale down lambda in seconds. | `number` | `60` | no |
346+
| runners\_scale\_up\_lambda\_timeout | Time out for the scale up lambda in seconds. | `number` | `180` | no |
347347
| scale\_down\_schedule\_expression | Scheduler expression to check every x for scale down. | `string` | `"cron(*/5 * * * ? *)"` | no |
348348
| subnet\_ids | List of subnets in which the action runners will be launched, the subnets needs to be subnets in the `vpc_id`. | `list(string)` | n/a | yes |
349349
| syncer\_lambda\_s3\_key | S3 key for syncer lambda function. Required if using S3 bucket to specify lambdas. | `any` | `null` | no |

modules/runners/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ No requirements.
8585
| lambda\_timeout\_scale\_down | Time out for the scale down lambda in seconds. | `number` | `60` | no |
8686
| lambda\_timeout\_scale\_up | Time out for the scale up lambda in seconds. | `number` | `60` | no |
8787
| lambda\_zip | File location of the lambda zip file. | `string` | `null` | no |
88-
| logging\_retention\_in\_days | Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653. | `number` | `7` | no |
88+
| logging\_retention\_in\_days | Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653. | `number` | `180` | no |
8989
| market\_options | Market options for the action runner instances. | `string` | `"spot"` | no |
9090
| minimum\_running\_time\_in\_minutes | The time an ec2 action runner should be running at minimum before terminated if non busy. | `number` | `5` | no |
9191
| overrides | This maps provides the possibility to override some defaults. The following attributes are supported: `name_sg` overwrite the `Name` tag for all security groups created by this module. `name_runner_agent_instance` override the `Name` tag for the ec2 instance defined in the auto launch configuration. `name_docker_machine_runners` override the `Name` tag spot instances created by the runner agent. | `map(string)` | <pre>{<br> "name_runner": "",<br> "name_sg": ""<br>}</pre> | no |
@@ -96,7 +96,7 @@ No requirements.
9696
| runner\_as\_root | Run the action runner under the root user. | `bool` | `false` | no |
9797
| runner\_extra\_labels | Extra labels for the runners (GitHub). Separate each label by a comma | `string` | `""` | no |
9898
| runner\_iam\_role\_managed\_policy\_arns | Attach AWS or customer-managed IAM policies (by ARN) to the runner IAM role | `list(string)` | `[]` | no |
99-
| runner\_log\_files | (optional) List of logfiles to send to cloudwatch. | <pre>list(object({<br> file_path = string<br> log_stream_name = string<br> }))</pre> | <pre>[<br> {<br> "file_path": "/var/log/messages",<br> "log_stream_name": "{instance_id}/messages"<br> },<br> {<br> "file_path": "/var/log/user-data.log",<br> "log_stream_name": "{instance_id}/user_data"<br> },<br> {<br> "file_path": "/home/ec2-user/actions-runner/_diag/Runner_**.log",<br> "log_stream_name": "{instance_id}/runner"<br> }<br>]</pre> | no |
99+
| runner\_log\_files | (optional) List of logfiles to send to cloudwatch, will onlybe usded if `enable_cloudwatch_agent` is set to true. Object description: `log_group_name`: Name of the log group, `prefix_log_group`: module will prefix the log group with `/github-self-hosted-runners/<var.environment>`, `file_path`: path to the log file, `log_stream_name`: name of the log stream. | <pre>list(object({<br> log_group_name = string<br> prefix_log_group = bool<br> file_path = string<br> log_stream_name = string<br> }))</pre> | <pre>[<br> {<br> "file_path": "/var/log/messages",<br> "log_group_name": "messages",<br> "log_stream_name": "{instance_id}",<br> "prefix_log_group": true<br> },<br> {<br> "file_path": "/var/log/user-data.log",<br> "log_group_name": "user_data",<br> "log_stream_name": "{instance_id}",<br> "prefix_log_group": true<br> },<br> {<br> "file_path": "/home/ec2-user/actions-runner/_diag/Runner_**.log",<br> "log_group_name": "runner",<br> "log_stream_name": "{instance_id}",<br> "prefix_log_group": true<br> }<br>]</pre> | no |
100100
| runners\_lambda\_s3\_key | S3 key for runners lambda function. Required if using S3 bucket to specify lambdas. | `any` | `null` | no |
101101
| runners\_lambda\_s3\_object\_version | S3 object version for runners lambda function. Useful if S3 versioning is enabled on source bucket. | `any` | `null` | no |
102102
| runners\_maximum\_count | The maximum number of runners that will be created. | `number` | `3` | no |

modules/runners/logging.tf

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
locals {
2-
logfiles = var.enable_cloudwatch_agent ? [for l in var.runner_log_files : merge(l, { "log_group_name" : aws_cloudwatch_log_group.runners[0].name })] : []
2+
logfiles = var.enable_cloudwatch_agent ? [for l in var.runner_log_files : {
3+
"log_group_name" : l.prefix_log_group ? "/github-self-hosted-runners/${var.environment}/${l.log_group_name}" : "/${l.log_group_name}"
4+
"log_stream_name" : l.log_stream_name
5+
"file_path" : l.file_path
6+
}] : []
7+
8+
loggroups_names = distinct([for l in local.logfiles : l.log_group_name])
9+
310
}
411

12+
513
resource "aws_ssm_parameter" "cloudwatch_agent_config_runner" {
614
count = var.enable_cloudwatch_agent ? 1 : 0
715
name = "${var.environment}-cloudwatch_agent_config_runner"
@@ -12,9 +20,9 @@ resource "aws_ssm_parameter" "cloudwatch_agent_config_runner" {
1220
tags = local.tags
1321
}
1422

15-
resource "aws_cloudwatch_log_group" "runners" {
16-
count = var.enable_cloudwatch_agent ? 1 : 0
17-
name = "${var.environment}/runners"
23+
resource "aws_cloudwatch_log_group" "gh_runners" {
24+
count = length(local.loggroups_names)
25+
name = local.loggroups_names[count.index]
1826
retention_in_days = var.logging_retention_in_days
1927
tags = local.tags
2028
}

modules/runners/variables.tf

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ variable "idle_config" {
210210
variable "logging_retention_in_days" {
211211
description = "Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653."
212212
type = number
213-
default = 7
213+
default = 180
214214
}
215215

216216
variable "enable_ssm_on_runners" {
@@ -258,23 +258,31 @@ variable "cloudwatch_config" {
258258
}
259259

260260
variable "runner_log_files" {
261-
description = "(optional) List of logfiles to send to cloudwatch."
261+
description = "(optional) List of logfiles to send to cloudwatch, will only be used if `enable_cloudwatch_agent` is set to true. Object description: `log_group_name`: Name of the log group, `prefix_log_group`: If true, the log group name will be prefixed with `/github-self-hosted-runners/<var.environment>`, `file_path`: path to the log file, `log_stream_name`: name of the log stream."
262262
type = list(object({
263-
file_path = string
264-
log_stream_name = string
263+
log_group_name = string
264+
prefix_log_group = bool
265+
file_path = string
266+
log_stream_name = string
265267
}))
266268
default = [
267269
{
270+
"log_group_name" : "messages",
271+
"prefix_log_group" : true,
268272
"file_path" : "/var/log/messages",
269-
"log_stream_name" : "{instance_id}/messages"
273+
"log_stream_name" : "{instance_id}"
270274
},
271275
{
276+
"log_group_name" : "user_data",
277+
"prefix_log_group" : true,
272278
"file_path" : "/var/log/user-data.log",
273-
"log_stream_name" : "{instance_id}/user_data"
279+
"log_stream_name" : "{instance_id}"
274280
},
275281
{
282+
"log_group_name" : "runner",
283+
"prefix_log_group" : true,
276284
"file_path" : "/home/ec2-user/actions-runner/_diag/Runner_**.log",
277-
"log_stream_name" : "{instance_id}/runner"
285+
"log_stream_name" : "{instance_id}"
278286
}
279287
]
280288
}

variables.tf

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ variable "enable_ssm_on_runners" {
190190
variable "logging_retention_in_days" {
191191
description = "Specifies the number of days you want to retain log events for the lambda log group. Possible values are: 0, 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653."
192192
type = number
193-
default = 7
193+
default = 180
194194
}
195195

196196
variable "runner_allow_prerelease_binaries" {
@@ -276,23 +276,31 @@ variable "cloudwatch_config" {
276276
}
277277

278278
variable "runner_log_files" {
279-
description = "(optional) List of logfiles to send to cloudwatch."
279+
description = "(optional) Replaces the module default cloudwatch log config. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html for details."
280280
type = list(object({
281-
file_path = string
282-
log_stream_name = string
281+
log_group_name = string
282+
prefix_log_group = bool
283+
file_path = string
284+
log_stream_name = string
283285
}))
284286
default = [
285287
{
288+
"log_group_name" : "messages",
289+
"prefix_log_group" : true,
286290
"file_path" : "/var/log/messages",
287-
"log_stream_name" : "{instance_id}/messages"
291+
"log_stream_name" : "{instance_id}"
288292
},
289293
{
294+
"log_group_name" : "user_data",
295+
"prefix_log_group" : true,
290296
"file_path" : "/var/log/user-data.log",
291-
"log_stream_name" : "{instance_id}/user_data"
297+
"log_stream_name" : "{instance_id}"
292298
},
293299
{
300+
"log_group_name" : "runner",
301+
"prefix_log_group" : true,
294302
"file_path" : "/home/ec2-user/actions-runner/_diag/Runner_**.log",
295-
"log_stream_name" : "{instance_id}/runner"
303+
"log_stream_name" : "{instance_id}"
296304
}
297305
]
298306
}

0 commit comments

Comments
 (0)