Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration for the monitor health check. #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ module "newrelic_monitoring" {
source = "vistaprint/monitoring/newrelic"
version = "0.0.6"

newrelic_app_name = "Your app name"
newrelic_fully_qualified_app_name = "Team/PRD/App"
service_healthcheck_url = "https://your-service-url.com"

enable_victorops_notifications = true
victorops_api_key = "Your VictorOps API key"
victorops_urgent_routing_key = "your-team-urgent"
victorops_non_urgent_routing_key = "your-team-non-urgent"
newrelic_fully_qualified_app_name = "Team/PRD/App"
synthetics_monitor_health_endpoint_url = "https://your-service-url.com"

enable_victorops_notifications = true
enable_dashboard = true
victorops_api_key = "Your VictorOps API key"
victorops_urgent_routing_key = "your-team-urgent"
victorops_non_urgent_routing_key = "your-team-non-urgent"
}
```

Expand Down
23 changes: 12 additions & 11 deletions alerts.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@ data "newrelic_application" "app" {
}

resource "newrelic_alert_policy" "non_urgent" {
name = "${var.newrelic_app_name} Non Urgent"
name = "${var.newrelic_fully_qualified_app_name} Non Urgent"
}

resource "newrelic_alert_policy" "urgent" {
name = "${var.newrelic_app_name} Urgent"
name = "${var.newrelic_fully_qualified_app_name} Urgent"
}

# health check monitor

resource "newrelic_synthetics_monitor" "health_check" {
count = var.service_healthcheck_url != null ? 1 : 0

name = "${var.newrelic_app_name} Health check"
type = "SIMPLE"
uri = var.service_healthcheck_url
frequency = 1
status = "ENABLED"
locations = ["AWS_US_EAST_1", "AWS_US_WEST_1", "AWS_EU_WEST_1", "AWS_EU_WEST_3", "AWS_AP_NORTHEAST_1", "AWS_AP_SOUTHEAST_2"]
count = var.synthetics_monitor_health_endpoint_url != null ? 1 : 0

name = "${var.newrelic_fully_qualified_app_name}"
type = "SIMPLE"
uri = var.synthetics_monitor_health_endpoint_url
frequency = var.synthetics_monitor_frequency
status = "ENABLED"
locations = ["AWS_US_EAST_1", "AWS_US_WEST_1", "AWS_EU_WEST_1", "AWS_EU_WEST_3", "AWS_AP_NORTHEAST_1", "AWS_AP_SOUTHEAST_2"]
bypass_head_request = var.synthetics_monitor_bypass_head_request
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not aligned. Easy to solve in VS code: cmd+shift+P then Format Document.

Actually, let's use this to improve locations too. I would place each location on a different line:

locations = [
  "AWS_US_EAST_1",
  "AWS_US_WEST_1",
  ...
]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I was not aware of the Format Document action

}

# urgent conditions

resource "newrelic_synthetics_alert_condition" "health_check" {
count = var.service_healthcheck_url != null ? 1 : 0
count = var.synthetics_monitor_health_endpoint_url != null ? 1 : 0

policy_id = newrelic_alert_policy.urgent.id

Expand Down
2 changes: 1 addition & 1 deletion dashboards.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "newrelic_dashboard" "dashboard" {
count = var.enable_dashboard ? 1 : 0

title = "${var.newrelic_app_name} Dashboard"
title = "${var.newrelic_fully_qualified_app_name}"

widget {
title = "Latency (seconds)"
Expand Down
5 changes: 2 additions & 3 deletions test/test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ provider "newrelic" {
module "newrelic_monitoring" {
source = "../"

newrelic_app_name = var.newrelic_app_name
newrelic_fully_qualified_app_name = var.newrelic_fully_qualified_app_name

service_healthcheck_url = var.service_healthcheck_url
synthetics_monitor_health_endpoint_url = var.synthetics_monitor_health_endpoint_url
enable_dashboard = true

enable_victorops_notifications = true
Expand All @@ -17,4 +16,4 @@ module "newrelic_monitoring" {
victorops_non_urgent_routing_key = var.victorops_non_urgent_routing_key

alert_error_rate_enable = true
}
}
6 changes: 1 addition & 5 deletions test/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ variable "newrelic_api_key" {
type = string
}

variable "newrelic_app_name" {
type = string
}

variable "newrelic_fully_qualified_app_name" {
type = string
}

variable "service_healthcheck_url" {
variable "synthetics_monitor_health_endpoint_url" {
type = string
default = null
}
Expand Down
25 changes: 13 additions & 12 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
variable "newrelic_app_name" {
type = string
description = <<-EOF
The name of the application to monitor.

This field is used to name the resources that will be created by Terraform,
not to filter metrics in New Relic. Use newrelic_fully_qualified_app_name
for that.
EOF
}

variable "newrelic_fully_qualified_app_name" {
type = string
description = "The name that the application was registered in New Relic with."
}

variable "service_healthcheck_url" {
variable "synthetics_monitor_health_endpoint_url" {
type = string
default = null
description = <<-EOF
Expand All @@ -24,6 +13,18 @@ variable "service_healthcheck_url" {
EOF
}

variable "synthetics_monitor_bypass_head_request" {
type = string
default = true
description = "Bypass HEAD request for monitor checks (true/false)."
}

variable "synthetics_monitor_frequency" {
type = string
default = 1
description = "The interval (in minutes) at which this monitor should run."
}

variable "runbook_url" {
type = string
default = null
Expand Down
4 changes: 2 additions & 2 deletions victorops.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "newrelic_alert_channel" "victorops_non_urgent" {
count = var.enable_victorops_notifications ? 1 : 0

name = "${var.newrelic_app_name} Non Urgent"
name = "${var.newrelic_fully_qualified_app_name} Non Urgent"
type = "victorops"

configuration = {
Expand All @@ -13,7 +13,7 @@ resource "newrelic_alert_channel" "victorops_non_urgent" {
resource "newrelic_alert_channel" "victorops_urgent" {
count = var.enable_victorops_notifications ? 1 : 0

name = "${var.newrelic_app_name} Urgent"
name = "${var.newrelic_fully_qualified_app_name} Urgent"
type = "victorops"

configuration = {
Expand Down