Skip to content

Commit d75ba4a

Browse files
Merge pull request #18 from sparkfabrik/task/1549_monitoring
Add new functionality for monitoring
2 parents 4ad898b + aa461f9 commit d75ba4a

File tree

2 files changed

+127
-103
lines changed

2 files changed

+127
-103
lines changed

main.tf

Lines changed: 111 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ provider "google-beta" {
2424

2525
locals {
2626
# Postgres DB Name
27-
gitlab_db_name = var.postgresql_db_random_suffix ? "${var.gitlab_db_name}-${random_id.suffix[0].hex}" : var.gitlab_db_name
27+
gitlab_db_name = var.postgresql_db_random_suffix ? "${var.gitlab_db_name}-${random_id.suffix[0].hex}" : var.gitlab_db_name
2828
# Gitlab Bucket Names
2929
gitlab_backups_bucket_name = var.gcs_bucket_random_suffix ? "${var.project_id}-gitlab-backups-${random_id.bucket_suffix[0].hex}" : "${var.project_id}-gitlab-backups"
3030
gitlab_tmp_backups_bucket_name = var.gcs_bucket_random_suffix ? "${var.project_id}-gitlab-tmp-backups-${random_id.bucket_suffix[0].hex}" : "${var.project_id}-gitlab-tmp-backups"
@@ -41,12 +41,12 @@ locals {
4141
}
4242

4343
resource "random_id" "suffix" {
44-
count = var.postgresql_db_random_suffix ? 2 : 1
44+
count = var.postgresql_db_random_suffix ? 2 : 1
4545
byte_length = 4
4646
}
4747

4848
resource "random_id" "bucket_suffix" {
49-
count = var.gcs_bucket_random_suffix ? 1 : 0
49+
count = var.gcs_bucket_random_suffix ? 1 : 0
5050
byte_length = 4
5151
}
5252

@@ -138,15 +138,15 @@ resource "google_compute_address" "gitlab" {
138138
}
139139

140140
module "cloud_nat" {
141-
source = "terraform-google-modules/cloud-nat/google"
142-
version = "~> 2.2.0"
143-
project_id = var.project_id
144-
region = var.region
145-
router = format("%s-router", var.project_id)
146-
name = "${var.project_id}-cloud-nat-${random_id.suffix[1].hex}"
147-
network = google_compute_network.gitlab.self_link
148-
create_router = true
149-
min_ports_per_vm = "2048"
141+
source = "terraform-google-modules/cloud-nat/google"
142+
version = "~> 2.2.0"
143+
project_id = var.project_id
144+
region = var.region
145+
router = format("%s-router", var.project_id)
146+
name = "${var.project_id}-cloud-nat-${random_id.suffix[1].hex}"
147+
network = google_compute_network.gitlab.self_link
148+
create_router = true
149+
min_ports_per_vm = "2048"
150150
}
151151

152152
resource "google_compute_firewall" "admission_webhook" {
@@ -181,18 +181,18 @@ resource "google_service_networking_connection" "private_vpc_connection" {
181181
}
182182

183183
resource "google_sql_database_instance" "gitlab_db" {
184-
depends_on = [google_service_networking_connection.private_vpc_connection]
185-
name = local.gitlab_db_name
186-
region = var.region
187-
database_version = var.postgresql_version
188-
deletion_protection = var.postgresql_del_protection
184+
depends_on = [google_service_networking_connection.private_vpc_connection]
185+
name = local.gitlab_db_name
186+
region = var.region
187+
database_version = var.postgresql_version
188+
deletion_protection = var.postgresql_del_protection
189189

190190
settings {
191-
tier = var.postgresql_tier
192-
availability_type = var.postgresql_availability_type
193-
disk_size = var.postgresql_disk_size
194-
disk_type = var.postgresql_disk_type
195-
disk_autoresize = true
191+
tier = var.postgresql_tier
192+
availability_type = var.postgresql_availability_type
193+
disk_size = var.postgresql_disk_size
194+
disk_type = var.postgresql_disk_type
195+
disk_autoresize = true
196196

197197
ip_configuration {
198198
ipv4_enabled = "false"
@@ -204,9 +204,9 @@ resource "google_sql_database_instance" "gitlab_db" {
204204
enabled = var.postgresql_enable_backup
205205
start_time = var.postgresql_backup_start_time
206206
point_in_time_recovery_enabled = true
207-
backup_retention_settings {
208-
retained_backups = var. postgresql_backup_retained_count
209-
}
207+
backup_retention_settings {
208+
retained_backups = var.postgresql_backup_retained_count
209+
}
210210
}
211211

212212
maintenance_window {
@@ -230,8 +230,8 @@ resource "google_sql_user" "gitlab" {
230230
}
231231

232232
resource "google_sql_database" "gitlabhq_production" {
233-
name = "gitlabhq_production"
234-
instance = google_sql_database_instance.gitlab_db.name
233+
name = "gitlabhq_production"
234+
instance = google_sql_database_instance.gitlab_db.name
235235
}
236236

237237
# Redis
@@ -340,35 +340,35 @@ module "gke" {
340340
# Create an implicit dependency on service activation
341341
project_id = module.project_services.project_id
342342

343-
name = "gitlab"
344-
region = var.region
345-
regional = true
346-
kubernetes_version = var.gke_version
347-
348-
network = google_compute_network.gitlab.name
349-
subnetwork = google_compute_subnetwork.subnetwork.name
350-
ip_range_pods = "gitlab-cluster-pod-cidr"
351-
ip_range_services = "gitlab-cluster-service-cidr"
352-
353-
enable_private_endpoint = false
354-
enable_private_nodes = true
355-
release_channel = "STABLE"
356-
maintenance_start_time = "03:00"
357-
network_policy = false
358-
enable_shielded_nodes = true
359-
dns_cache = true
360-
361-
remove_default_node_pool = true
362-
343+
name = "gitlab"
344+
region = var.region
345+
regional = true
346+
kubernetes_version = var.gke_version
347+
348+
network = google_compute_network.gitlab.name
349+
subnetwork = google_compute_subnetwork.subnetwork.name
350+
ip_range_pods = "gitlab-cluster-pod-cidr"
351+
ip_range_services = "gitlab-cluster-service-cidr"
352+
353+
enable_private_endpoint = false
354+
enable_private_nodes = true
355+
release_channel = "STABLE"
356+
maintenance_start_time = "03:00"
357+
network_policy = false
358+
enable_shielded_nodes = true
359+
dns_cache = true
360+
361+
remove_default_node_pool = true
362+
363363
# Kube-proxy - eBPF setting
364-
datapath_provider = var.gke_datapath
364+
datapath_provider = var.gke_datapath
365365
# Google Group for RBAC
366-
authenticator_security_group = var.gke_google_group_rbac_mail
366+
authenticator_security_group = var.gke_google_group_rbac_mail
367367
# Backup for GKE
368-
gke_backup_agent_config = var.gke_enable_backup_agent
368+
gke_backup_agent_config = var.gke_enable_backup_agent
369369
# Istio
370-
istio = var.gke_enable_istio_addon
371-
istio_auth = var.gke_istio_auth
370+
istio = var.gke_enable_istio_addon
371+
istio_auth = var.gke_istio_auth
372372

373373
node_pools = [
374374
{
@@ -386,10 +386,10 @@ module "gke" {
386386
cloudrun = var.gke_enable_cloudrun
387387
enable_pod_security_policy = false
388388
preemptible = false
389-
autoscaling = true
390-
389+
autoscaling = true
390+
391391
#Image Streaming
392-
enable_gcfs = var.gke_enable_image_stream
392+
enable_gcfs = var.gke_enable_image_stream
393393
},
394394
]
395395

@@ -411,21 +411,21 @@ resource "kubernetes_storage_class" "storage_class" {
411411
}
412412
storage_provisioner = "kubernetes.io/gce-pd"
413413
parameters = {
414-
type = var.gke_storage_class
414+
type = var.gke_storage_class
415415
replication-type = var.gke_disk_replication
416416
}
417417
depends_on = [time_sleep.sleep_for_cluster_fix_helm_6361]
418418
}
419419

420420
# Secret for Postgres DB Pass
421421
module "gitlab_db_pass" {
422-
source = "./modules/secret_manager"
423-
project = var.project_id
424-
region = var.region
425-
secret_id = var.gcp_existing_db_secret_name
426-
k8s_namespace = var.gitlab_namespace
427-
k8s_secret_name = "gitlab-postgres-secret"
428-
k8s_secret_key = "password"
422+
source = "./modules/secret_manager"
423+
project = var.project_id
424+
region = var.region
425+
secret_id = var.gcp_existing_db_secret_name
426+
k8s_namespace = var.gitlab_namespace
427+
k8s_secret_name = "gitlab-postgres-secret"
428+
k8s_secret_key = "password"
429429

430430
depends_on = [kubernetes_namespace.gitlab_namespace]
431431
}
@@ -491,39 +491,39 @@ resource "kubernetes_secret" "postgresql_mtls_secret" {
491491
}
492492

493493
data = {
494-
cert = google_sql_ssl_cert.postgres_client_cert.cert
495-
private_key = google_sql_ssl_cert.postgres_client_cert.private_key
496-
server_ca_cert = google_sql_ssl_cert.postgres_client_cert.server_ca_cert
494+
cert = google_sql_ssl_cert.postgres_client_cert.cert
495+
private_key = google_sql_ssl_cert.postgres_client_cert.private_key
496+
server_ca_cert = google_sql_ssl_cert.postgres_client_cert.server_ca_cert
497497
}
498498
depends_on = [kubernetes_namespace.gitlab_namespace]
499499
}
500500

501501
#Secret for SMTP Pass
502502
module "gitlab_smtp_pass" {
503-
source = "./modules/secret_manager"
504-
project = var.project_id
505-
region = var.region
506-
secret_id = var.gcp_existing_smtp_secret_name
507-
k8s_namespace = var.gitlab_namespace
508-
k8s_secret_name = "gitlab-smtp-secret"
509-
k8s_secret_key = "password"
510-
511-
count = var.gitlab_enable_smtp ? 1 : 0
503+
source = "./modules/secret_manager"
504+
project = var.project_id
505+
region = var.region
506+
secret_id = var.gcp_existing_smtp_secret_name
507+
k8s_namespace = var.gitlab_namespace
508+
k8s_secret_name = "gitlab-smtp-secret"
509+
k8s_secret_key = "password"
510+
511+
count = var.gitlab_enable_smtp ? 1 : 0
512512
depends_on = [kubernetes_namespace.gitlab_namespace]
513513
}
514514

515515
#Secret for Omniauth Pass
516516
module "gitlab_omniauth_pass" {
517-
source = "./modules/secret_manager"
518-
project = var.project_id
519-
region = var.region
520-
secret_id = var.gcp_existing_omniauth_secret_name
521-
k8s_namespace = var.gitlab_namespace
522-
k8s_secret_name = "gitlab-omniauth-secret"
523-
k8s_secret_key = "provider"
524-
525-
count = var.gitlab_enable_omniauth ? 1 : 0
526-
depends_on = [kubernetes_namespace.gitlab_namespace]
517+
source = "./modules/secret_manager"
518+
project = var.project_id
519+
region = var.region
520+
secret_id = var.gcp_existing_omniauth_secret_name
521+
k8s_namespace = var.gitlab_namespace
522+
k8s_secret_name = "gitlab-omniauth-secret"
523+
k8s_secret_key = "provider"
524+
525+
count = var.gitlab_enable_omniauth ? 1 : 0
526+
depends_on = [kubernetes_namespace.gitlab_namespace]
527527
}
528528

529529
data "google_compute_address" "gitlab" {
@@ -535,9 +535,9 @@ data "google_compute_address" "gitlab" {
535535
}
536536

537537
locals {
538-
gitlab_address = var.gitlab_address_name == "" ? google_compute_address.gitlab[0].address : data.google_compute_address.gitlab[0].address
539-
domain = var.domain != "" ? var.domain : "${local.gitlab_address}.xip.io"
540-
gitlab_smtp_user = var.gitlab_enable_smtp != false ? var.gitlab_smtp_user : ""
538+
gitlab_address = var.gitlab_address_name == "" ? google_compute_address.gitlab[0].address : data.google_compute_address.gitlab[0].address
539+
domain = var.domain != "" ? var.domain : "${local.gitlab_address}.xip.io"
540+
gitlab_smtp_user = var.gitlab_enable_smtp != false ? var.gitlab_smtp_user : ""
541541
}
542542

543543
data "template_file" "helm_values" {
@@ -560,9 +560,9 @@ data "template_file" "helm_values" {
560560
ENABLE_CRON_BACKUP = var.gitlab_enable_cron_backup
561561
SCHEDULE_CRON_BACKUP = var.gitlab_schedule_cron_backup
562562
GITALY_PV_SIZE = var.gitlab_gitaly_disk_size
563-
PV_STORAGE_CLASS = var.gke_storage_class
563+
PV_STORAGE_CLASS = var.gke_storage_class
564564
ENABLE_SMTP = var.gitlab_enable_smtp
565-
SMTP_USER = local.gitlab_smtp_user
565+
SMTP_USER = local.gitlab_smtp_user
566566
BACKUP_EXTRA = var.gitlab_backup_extra_args
567567
TIMEZONE = var.gitlab_time_zone
568568
ENABLE_OMNIAUTH = var.gitlab_enable_omniauth
@@ -574,17 +574,17 @@ data "template_file" "helm_values" {
574574
RESTORE_PV_SC = var.gke_sc_gitlab_restore_disk
575575

576576
#Bucket Names
577-
LFS_BCKT = local.git_lfs_bucket_name
578-
ARTIFACTS_BCKT = local.gitlab_artifacts_bucket_name
579-
UPLOADS_BCKT = local.gitlab_uploads_bucket_name
580-
PACKAGES_BCKT = local.gitlab_packages_bucket_name
581-
EXT_DIFF_BCKT = local.gitlab_external_diffs_bucket_name
582-
TERRAFORM_BCKT = local.gitlab_terraform_state_bucket_name
583-
DEP_PROXY_BCKT = local.gitlab_dependency_proxy_bucket_name
584-
BACKUP_BCKT = local.gitlab_backups_bucket_name
585-
BACKUP_TMP_BCKT = local.gitlab_tmp_backups_bucket_name
586-
REGISTRY_BCKT = local.gitlab_registry_bucket_name
587-
RUNNER_CACHE_BCKT = local.gitlab_runner_cache_bucket_name
577+
LFS_BCKT = local.git_lfs_bucket_name
578+
ARTIFACTS_BCKT = local.gitlab_artifacts_bucket_name
579+
UPLOADS_BCKT = local.gitlab_uploads_bucket_name
580+
PACKAGES_BCKT = local.gitlab_packages_bucket_name
581+
EXT_DIFF_BCKT = local.gitlab_external_diffs_bucket_name
582+
TERRAFORM_BCKT = local.gitlab_terraform_state_bucket_name
583+
DEP_PROXY_BCKT = local.gitlab_dependency_proxy_bucket_name
584+
BACKUP_BCKT = local.gitlab_backups_bucket_name
585+
BACKUP_TMP_BCKT = local.gitlab_tmp_backups_bucket_name
586+
REGISTRY_BCKT = local.gitlab_registry_bucket_name
587+
RUNNER_CACHE_BCKT = local.gitlab_runner_cache_bucket_name
588588

589589
# HPA settings for cost/performance optimization
590590
HPA_MIN_REPLICAS_REGISTRY = var.gitlab_hpa_min_replicas_registry
@@ -631,3 +631,13 @@ resource "helm_release" "gitlab" {
631631
module.gitlab_db_pass,
632632
]
633633
}
634+
635+
module "monitoring" {
636+
source = "sparkfabrik/gcp-http-monitoring/sparkfabrik"
637+
version = "~> 0.4.0"
638+
count = var.notification_channels != "" ? 1 : 0
639+
gcp_project = var.project_id
640+
uptime_monitoring_host = var.domain
641+
uptime_monitoring_path = var.uptime_monitoring_path
642+
alert_notification_channels = var.notification_channels
643+
}

variables.tf

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ variable "gitlab_namespace" {
360360
variable "gitlab_backup_extra_args" {
361361
type = string
362362
description = "Add a string of extra arguments for the gitlab backup-utility."
363-
default = ""
363+
default = ""
364364
}
365365

366366
variable "gitlab_enable_registry" {
@@ -477,4 +477,18 @@ variable "gitlab_hpa_max_replicas_webservice" {
477477
description = "Set the maximum hpa pod replicas for the Gitlab webservice."
478478
default = 10
479479
}
480-
480+
481+
######################
482+
# MONITORING SECTION #
483+
######################
484+
485+
variable "uptime_monitoring_path" {
486+
type = string
487+
description = "The path to the page to run the check against."
488+
default = "/-/liveness"
489+
}
490+
491+
variable "notification_channels" {
492+
type = list(string)
493+
description = "Identifies the notification channels to which notifications should be sent when incidents are opened or closed. The syntax of the entries in this field is projects/[PROJECT_ID]/notificationChannels/[CHANNEL_ID]"
494+
}

0 commit comments

Comments
 (0)