Skip to content

Commit

Permalink
New relic terraform alert POC (#1409)
Browse files Browse the repository at this point in the history
* starting new relic stuff

* Successful terragrunt deploy of a NR alert condition

* adding aert condition

* adding workflow vars

* fixing the missing dns files

* Update terragrunt.hcl

just removing an unnecessary line

* Update alert_conditions.tf

adding this for a test

* updating secrets

* updating all environments

* removing uneccessary variable

* atttempting to fix formatting

* formatting

* formatting

* migrating the specific values for the new relic provider to the TF side so we can consume the TFVars while working locally.

* adding back variable
  • Loading branch information
P0NDER0SA authored Jul 4, 2024
1 parent 1d7fb14 commit 71924dd
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/merge_to_main_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ env:
AWS_ACCESS_KEY_ID: ${{ secrets.PRODUCTION_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.PRODUCTION_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ca-central-1
TF_VAR_new_relic_api_key: ${{ secrets.PRODUCTION_NEW_RELIC_API_KEY }}
TF_VAR_new_relic_account_id: ${{ secrets.PRODUCTION_NEW_RELIC_ACCOUNT_ID }}
TF_VAR_base_domain: ${{secrets.PRODUCTION_BASE_DOMAIN}}
TF_VAR_alt_base_domain: ${{secrets.PRODUCTION_ALT_BASE_DOMAIN}}
TF_VAR_dbtools_password: ${{ secrets.PRODUCTION_DBTOOLS_PASSWORD }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/merge_to_main_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ env:
AWS_ACCESS_KEY_ID: ${{ secrets.STAGING_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.STAGING_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ca-central-1
TF_VAR_new_relic_api_key: ${{ secrets.PRODUCTION_NEW_RELIC_API_KEY }}
TF_VAR_new_relic_account_id: ${{ secrets.PRODUCTION_NEW_RELIC_ACCOUNT_ID }}
TF_VAR_base_domain: ${{secrets.STAGING_BASE_DOMAIN}}
TF_VAR_alt_base_domain: ${{secrets.STAGING_ALT_BASE_DOMAIN}}
TF_VAR_dbtools_password: ${{ secrets.STAGING_DBTOOLS_PASSWORD }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/terragrunt_plan_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
AWS_REGION: ca-central-1
TERRAFORM_VERSION: 0.14.4
TERRAGRUNT_VERSION: 0.35.13
TF_VAR_new_relic_api_key: ${{ secrets.PRODUCTION_NEW_RELIC_API_KEY }}
TF_VAR_new_relic_account_id: ${{ secrets.PRODUCTION_NEW_RELIC_ACCOUNT_ID }}
TF_VAR_base_domain: ${{secrets.PRODUCTION_BASE_DOMAIN}}
TF_VAR_alt_base_domain: ${{secrets.PRODUCTION_ALT_BASE_DOMAIN}}
TF_VAR_dbtools_password: ${{ secrets.PRODUCTION_DBTOOLS_PASSWORD }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/terragrunt_plan_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ env:
AWS_REGION: ca-central-1
TERRAFORM_VERSION: 0.14.4
TERRAGRUNT_VERSION: 0.35.13
TF_VAR_new_relic_api_key: ${{ secrets.PRODUCTION_NEW_RELIC_API_KEY }}
TF_VAR_new_relic_account_id: ${{ secrets.PRODUCTION_NEW_RELIC_ACCOUNT_ID }}
TF_VAR_base_domain: ${{secrets.STAGING_BASE_DOMAIN}}
TF_VAR_alt_base_domain: ${{secrets.STAGING_ALT_BASE_DOMAIN}}
TF_VAR_dbtools_password: ${{ secrets.STAGING_DBTOOLS_PASSWORD }}
Expand Down
31 changes: 31 additions & 0 deletions aws/newrelic/alert_conditions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
resource "newrelic_nrql_alert_condition" "tf_lambda_api_errors_count_anomaly_unexpected_errors" {
account_id = var.new_relic_account_id
policy_id = 2801728
type = "baseline"
name = "Staging - Terraform - [Lambda API] Errors count anomaly (Unexpected Errors)"
enabled = true
violation_time_limit_seconds = 86400

nrql {
query = "SELECT count(*) FROM AwsLambdaInvocationError WHERE (`entityGuid`='MjY5MTk3NHxJTkZSQXxOQXwtNzgwNDUyNTc5NzAyODI1NTcyNw') and error.class NOT IN ('app.v2.errors:BadRequestError','jsonschema.exceptions:ValidationError', 'sqlalchemy.exc:NoResultFound', 'app.authentication.auth:AuthError', 'werkzeug.exceptions:MethodNotAllowed') and error.message NOT LIKE '{\\'result\\': \\'error\\', \\'message\\': {\\'password\\': [\\'Incorrect password\\']}}'"
}

critical {
operator = "above"
threshold = 6
threshold_duration = 300
threshold_occurrences = "all"
}

warning {
operator = "above"
threshold = 3
threshold_duration = 300
threshold_occurrences = "all"
}
fill_option = "none"
aggregation_window = 60
aggregation_method = "event_flow"
aggregation_delay = 300
baseline_direction = "upper_and_lower"
}
5 changes: 5 additions & 0 deletions aws/newrelic/alert_policies.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# resource "newrelic_alert_policy" "notify_terraform_policy" {
# name = "Pond Example staging"
# provider = newrelic
# }

7 changes: 7 additions & 0 deletions aws/newrelic/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# data "newrelic_entity" "notification-admin-script-staging" {
# name = "notification-admin-script"
# provider = newrelic
# domain = "BROWSER" # or BROWSER, INFRA, MOBILE, SYNTH, depending on your entity's domain
# type = "APPLICATION"
# }

1 change: 1 addition & 0 deletions aws/newrelic/entities.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

5 changes: 5 additions & 0 deletions aws/newrelic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider "newrelic" {
account_id = var.new_relic_account_id
api_key = var.new_relic_api_key
region = "US"
}
8 changes: 8 additions & 0 deletions aws/newrelic/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "new_relic_account_id" {
type = string
description = "New Relic Account ID"
}
variable "new_relic_api_key" {
type = string
description = "New Relic API Key"
}
70 changes: 70 additions & 0 deletions env/dev/newrelic/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions env/dev/newrelic/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
source = "../../../aws//newrelic"
}

include {
path = find_in_parent_folders()
}
1 change: 0 additions & 1 deletion env/production/env_vars.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ inputs = {
account_budget_limit = 10000
log_retention_period_days = 0
sensitive_log_retention_period_days = 7

}
10 changes: 6 additions & 4 deletions env/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ inputs = {
log_retention_period_days = local.vars.inputs.log_retention_period_days
sensitive_log_retention_period_days = local.vars.inputs.sensitive_log_retention_period_days
account_budget_limit = local.vars.inputs.account_budget_limit


region = "ca-central-1"
# See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-logging-bucket-permissions
elb_account_ids = {
"ca-central-1" = "985666609251"
}
new_relic_account_id = "2691974"

cbs_satellite_bucket_name = "cbs-satellite-${local.vars.inputs.account_id}"
}

Expand Down Expand Up @@ -50,8 +51,11 @@ terraform {
source = "hashicorp/tls"
version = "~> 4.0"
}
newrelic = {
source = "newrelic/newrelic"
version = "~> 2.0"
}
}
}
provider "aws" {
Expand Down Expand Up @@ -84,8 +88,6 @@ provider "aws" {
}
}
EOF
}

Expand Down

0 comments on commit 71924dd

Please sign in to comment.