Skip to content

Commit

Permalink
feat: added method and server name to gateway alarms; (#34)
Browse files Browse the repository at this point in the history
Added `method` and `server_name` to http server metrics.

Co-authored-by: Jan Kamieth <[email protected]>
  • Loading branch information
j4k4 and Jan Kamieth authored Feb 13, 2024
1 parent 8ad0d05 commit f87cdbc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
| <a name="input_label_orders"></a> [label\_orders](#input\_label\_orders) | Overrides the `labels_order` for the different labels to modify ID elements appear in the `id` | <pre>object({<br> cloudwatch = optional(list(string))<br> })</pre> | `{}` | no |
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
| <a name="input_method"></a> [method](#input\_method) | Http method of the handler for which success rate alarm should be created | `string` | n/a | yes |
| <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_organizational_unit"></a> [organizational\_unit](#input\_organizational\_unit) | Usually used to indicate the AWS organizational unit, e.g. 'prod', 'sdlc' | `string` | `null` | no |
| <a name="input_path"></a> [path](#input\_path) | Path for which success rate alarm should be created | `string` | n/a | yes |
| <a name="input_path"></a> [path](#input\_path) | Path for which the success rate alarm should be created | `string` | n/a | yes |
| <a name="input_period"></a> [period](#input\_period) | The period in seconds over which the specified statistic is applied | `number` | `60` | no |
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
| <a name="input_server_name"></a> [server\_name](#input\_server\_name) | Name of the gosoline http server for which the alarm should get created | `string` | n/a | yes |
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br>Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
Expand Down
2 changes: 2 additions & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module "example" {
source = "../../"

alarm_description = "Alarm when path success rate drops below threshold"
method = "GET"
path = "/api/v1/users"
server_name = "default"
datapoints_to_alarm = 2
evaluation_periods = 2
threshold = 95
Expand Down
12 changes: 8 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ resource "aws_cloudwatch_metric_alarm" "default" {
return_data = false

metric {
metric_name = "ApiRequestCount"
metric_name = "HttpRequestCount"
namespace = module.cloudwatch_label.id
dimensions = {
"path" = var.path
"Method" = var.method
"Path" = var.path
"ServerName" = var.server_name
}
period = var.period
stat = "Sum"
Expand All @@ -43,10 +45,12 @@ resource "aws_cloudwatch_metric_alarm" "default" {
return_data = false

metric {
metric_name = "ApiStatus5XX"
metric_name = "HttpStatus5XX"
namespace = module.cloudwatch_label.id
dimensions = {
"path" = var.path
"Method" = var.method
"Path" = var.path
"ServerName" = var.server_name
}
period = var.period
stat = "Sum"
Expand Down
12 changes: 11 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ variable "label_orders" {
description = "Overrides the `labels_order` for the different labels to modify ID elements appear in the `id`"
}

variable "method" {
type = string
description = "Http method of the handler for which success rate alarm should be created"
}

variable "path" {
type = string
description = "Path for which success rate alarm should be created"
description = "Path for which the success rate alarm should be created"
}

variable "period" {
Expand All @@ -41,6 +46,11 @@ variable "period" {
description = "The period in seconds over which the specified statistic is applied"
}

variable "server_name" {
type = string
description = "Name of the gosoline http server for which the alarm should get created"
}

variable "threshold" {
type = number
default = 99
Expand Down

0 comments on commit f87cdbc

Please sign in to comment.