Commit c71e0dc0 authored by John Jarvis's avatar John Jarvis Committed by Ahmad Sherif

Add redundancy to alerts.

parent 300a6d72
......@@ -849,7 +849,7 @@ module "prometheus" {
environment = "${var.environment}"
machine_type = "${var.machine_types["monitoring"]}"
name = "prometheus"
node_count = 1
node_count = "${var.node_count["prometheus"]}"
oauth2_client_id = "${var.oauth2_client_id_monitoring}"
oauth2_client_secret = "${var.oauth2_client_secret_monitoring}"
persistent_disk_path = "/opt/prometheus"
......@@ -875,7 +875,7 @@ module "prometheus-app" {
environment = "${var.environment}"
machine_type = "${var.machine_types["monitoring"]}"
name = "prometheus-app"
node_count = 1
node_count = "${var.node_count["prometheus-app"]}"
oauth2_client_id = "${var.oauth2_client_id_monitoring}"
oauth2_client_secret = "${var.oauth2_client_secret_monitoring}"
persistent_disk_path = "/opt/prometheus"
......@@ -891,7 +891,7 @@ module "prometheus-app" {
}
module "alerts" {
node_count = 1
node_count = "${var.node_count["alerts"]}"
bootstrap_version = 5
subnetwork_name = "${google_compute_subnetwork.monitoring.name}"
attach_data_disk = true
......
......@@ -285,6 +285,9 @@ variable "node_count" {
"sidekiq-traces" = 2
"stor" = 20
"web" = 14
"alerts" = 3
"prometheus" = 3
"prometheus-app" = 3
}
}
......
......@@ -5,23 +5,7 @@
resource "google_compute_url_map" "monitoring-lb" {
name = "${format("%v-monitoring-lb", var.environment)}"
default_service = "${module.performance.google_compute_backend_service_self_link}"
###################################
host_rule {
hosts = ["performance.gstg.gitlab.net"]
path_matcher = "performance"
}
path_matcher {
name = "performance"
default_service = "${module.performance.google_compute_backend_service_self_link}"
path_rule {
paths = ["/*"]
service = "${module.performance.google_compute_backend_service_self_link}"
}
}
default_service = "${module.prometheus.google_compute_backend_service_self_link}"
###################################
......
......@@ -642,6 +642,12 @@ module "gcp-tcp-lb" {
instances = ["${module.fe-lb.instances_self_link}"]
}
##################################
#
# GCP Internal TCP LoadBalancers
#
##################################
### The regional backend service that is required for the internal
### load balancer. Unlike global backend services every instance
### group _must_ contain at least one instance. Also you cannot
......@@ -840,33 +846,6 @@ module "monitoring-lb" {
targets = ["${keys(var.monitoring_hosts)}"]
}
module "performance" {
attach_data_disk = true
bootstrap_version = 6
chef_provision = "${var.chef_provision}"
chef_run_list = "\"role[${var.environment}-private-grafana]\""
data_disk_size = 100
data_disk_type = "pd-standard"
dns_zone_name = "${var.dns_zone_name}"
environment = "${var.environment}"
machine_type = "${var.machine_types["monitoring"]}"
name = "performance"
node_count = 1
oauth2_client_id = "${var.oauth2_client_id_monitoring}"
oauth2_client_secret = "${var.oauth2_client_secret_monitoring}"
persistent_disk_path = "/opt"
project = "${var.project}"
region = "${var.region}"
service_account_email = "${var.service_account_email}"
service_path = "/login"
service_port = "${var.monitoring_hosts["performance"]}"
source = "../../modules/google/monitoring-with-count"
subnetwork_name = "${google_compute_subnetwork.monitoring.name}"
tier = "inf"
use_new_node_name = true
kernel_version = "${var.default_kernel_version}"
}
module "prometheus" {
attach_data_disk = true
bootstrap_version = 6
......@@ -878,7 +857,7 @@ module "prometheus" {
environment = "${var.environment}"
machine_type = "${var.machine_types["monitoring"]}"
name = "prometheus"
node_count = 1
node_count = "${var.node_count["prometheus"]}"
oauth2_client_id = "${var.oauth2_client_id_monitoring}"
oauth2_client_secret = "${var.oauth2_client_secret_monitoring}"
persistent_disk_path = "/opt/prometheus"
......@@ -905,7 +884,7 @@ module "prometheus-app" {
environment = "${var.environment}"
machine_type = "${var.machine_types["monitoring"]}"
name = "prometheus-app"
node_count = 1
node_count = "${var.node_count["prometheus-app"]}"
oauth2_client_id = "${var.oauth2_client_id_monitoring}"
oauth2_client_secret = "${var.oauth2_client_secret_monitoring}"
persistent_disk_path = "/opt/prometheus"
......@@ -933,7 +912,7 @@ module "alerts" {
health_check = "tcp"
machine_type = "${var.machine_types["monitoring"]}"
name = "alerts"
node_count = 1
node_count = "${var.node_count["alerts"]}"
oauth2_client_id = "${var.oauth2_client_id_monitoring}"
oauth2_client_secret = "${var.oauth2_client_secret_monitoring}"
persistent_disk_path = "/opt"
......
......@@ -287,6 +287,9 @@ variable "node_count" {
"sidekiq-traces" = 1
"stor" = 2
"web" = 1
"prometheus" = 3
"prometheus-app" = 3
"alerts" = 3
}
}
......
resource "google_compute_backend_service" "default" {
resource "google_compute_region_backend_service" "default" {
count = "${var.backend_service == "regional" ? 1 : 0}"
name = "${format("%v-%v-regional", var.environment, var.name)}"
protocol = "TCP"
backend {
group = "${google_compute_instance_group.default.*.self_link[0]}"
}
backend {
group = "${google_compute_instance_group.default.*.self_link[1]}"
}
backend {
group = "${google_compute_instance_group.default.*.self_link[2]}"
}
health_checks = ["${var.health_check == "http" ? google_compute_health_check.http.self_link : google_compute_health_check.tcp.self_link }"]
}
resource "google_compute_backend_service" "iap" {
count = "${var.backend_service == "regional" ? 0 : 1}"
name = "${format("%v-%v", var.environment, var.name)}"
protocol = "${var.backend_protocol}"
port_name = "${var.name}"
backend {
group = "${google_compute_instance_group.default.self_link}"
group = "${google_compute_instance_group.default.*.self_link[0]}"
}
backend {
group = "${google_compute_instance_group.default.*.self_link[1]}"
}
backend {
group = "${google_compute_instance_group.default.*.self_link[2]}"
}
health_checks = ["${var.health_check == "http" ? google_compute_health_check.http.self_link : google_compute_health_check.tcp.self_link }"]
......@@ -16,7 +45,6 @@ resource "google_compute_backend_service" "default" {
}
resource "google_compute_health_check" "tcp" {
# count = "${var.health_check == "tcp" ? 1 : 0}"
name = "${format("%v-%v-tcp", var.environment, var.name)}"
tcp_health_check {
......@@ -25,7 +53,6 @@ resource "google_compute_health_check" "tcp" {
}
resource "google_compute_health_check" "http" {
# count = "${var.health_check == "http" ? 1 : 0}"
name = "${format("%v-%v-http", var.environment, var.name)}"
http_health_check {
......@@ -34,24 +61,45 @@ resource "google_compute_health_check" "http" {
}
}
# Add one instance group per zone
# and only select the appropriate instances
# for each one
resource "google_compute_instance_group" "default" {
name = "${format("%v-%v", var.environment, var.name)}"
count = "${length(data.google_compute_zones.available.names)}"
name = "${format("%v-%v-%v", var.environment, var.name, data.google_compute_zones.available.names[count.index])}"
description = "Instance group for monitoring VM."
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[0]}"
zone = "${data.google_compute_zones.available.names[count.index]}"
named_port {
name = "${var.name}"
port = "${var.service_port}"
}
named_port {
name = "http"
port = "80"
}
named_port {
name = "https"
port = "443"
}
named_port {
name = "${var.name}"
port = "${var.service_port}"
}
instances = ["${google_compute_instance.default.*.self_link}"]
# This filters the full set of instances to only ones for the appropriate zone.
instances = ["${matchkeys(google_compute_instance.default.*.self_link, google_compute_instance.default.*.zone, list(data.google_compute_zones.available.names[count.index]))}"]
}
resource "google_compute_disk" "default" {
count = "${var.node_count}"
project = "${var.project}"
name = "${format("%v-%02d-%v-%v-data", var.name, count.index + 1, var.tier, var.environment)}"
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[0]}"
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[(count.index + 1) % length(data.google_compute_zones.available.names)]}"
size = "${var.data_disk_size}"
type = "${var.data_disk_type}"
......@@ -65,7 +113,7 @@ resource "google_compute_disk" "log_disk" {
project = "${var.project}"
count = "${var.node_count}"
name = "${format("%v-%02d-%v-%v-log", var.name, count.index + 1, var.tier, var.environment)}"
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[0]}"
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[(count.index + 1) % length(data.google_compute_zones.available.names)]}"
size = "${var.log_disk_size}"
type = "${var.log_disk_type}"
......@@ -100,7 +148,9 @@ resource "google_compute_instance" "default" {
metadata_startup_script = "${file("${path.module}/../../../scripts/google/bootstrap-v${var.bootstrap_version}.sh")}"
project = "${var.project}"
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[0]}"
// zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[0]}"
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[(count.index + 1) % length(data.google_compute_zones.available.names)]}"
service_account {
// this should be the instance under which the instance should be running, rather than the one creating it...
......@@ -136,7 +186,7 @@ resource "google_compute_instance" "default" {
}
attached_disk {
source = "${google_compute_disk.default.self_link}"
source = "${google_compute_disk.default.*.self_link[count.index]}"
}
attached_disk {
......
......@@ -2,10 +2,24 @@ output "instances_self_link" {
value = "${google_compute_instance.default.*.self_link}"
}
output "instance_group_self_link" {
value = "${google_compute_instance_group.default.self_link}"
output "instance_groups_self_link" {
value = "${google_compute_instance_group.default.*.self_link}"
}
# this is idiomatic for how to have outputs that may have a count of zero
# https://www.terraform.io/upgrade-guides/0-11.html#referencing-attributes-from-resources-with-count-0
output "google_compute_backend_service_self_link" {
value = "${google_compute_backend_service.default.self_link}"
value = "${element(concat(google_compute_backend_service.iap.*.self_link, list("")), 0)}"
}
output "google_compute_region_backend_service_self_link" {
value = "${element(concat(google_compute_region_backend_service.default.*.self_link, list("")), 0)}"
}
output "http_health_check_self_link" {
value = "${google_compute_health_check.http.self_link}"
}
output "tcp_health_check_self_link" {
value = "${google_compute_health_check.tcp.self_link}"
}
variable "backend_service" {
default = "regular"
}
variable "kernel_version" {
default = ""
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment