Skip to content

Commit

Permalink
Add feature toggle for enabling/disabling Grafana in kube-prometheus-…
Browse files Browse the repository at this point in the history
…stack (#1674)

* Add feature toggle for enabling/disabling Grafana in kube-prometheus-stack

* Disable Grafana in QA for kube-prometheus-stack
  • Loading branch information
avnes authored Jan 8, 2025
1 parent 2314438 commit 8a76af7
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 10 deletions.
6 changes: 6 additions & 0 deletions _sub/compute/helm-kube-prometheus-stack/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ resource "helm_release" "kube_prometheus_stack" {
}),

templatefile("${path.module}/values/grafana.yaml", {
grafana_enabled = var.grafana_enabled
grafana_admin_password = var.grafana_admin_password != "" ? var.grafana_admin_password : random_password.grafana_password.result
grafana_priorityclass = var.priority_class
grafana_ingress_path = var.grafana_ingress_path
Expand Down Expand Up @@ -114,6 +115,7 @@ resource "helm_release" "kube_prometheus_stack" {
}

resource "github_repository_file" "grafana_config_path" {
count = var.grafana_enabled ? 1 : 0
repository = var.repo_name
branch = local.repo_branch
file = "${local.cluster_repo_path}/${local.grafana_platform_apps_name}-config.yaml"
Expand All @@ -122,6 +124,7 @@ resource "github_repository_file" "grafana_config_path" {
}

resource "github_repository_file" "grafana_config_middleware" {
count = var.grafana_enabled ? 1 : 0
repository = var.repo_name
branch = local.repo_branch
file = "${local.config_repo_path}/middleware.yaml"
Expand All @@ -130,6 +133,7 @@ resource "github_repository_file" "grafana_config_middleware" {
}

resource "github_repository_file" "grafana_config_ingressroute" {
count = var.grafana_enabled ? 1 : 0
repository = var.repo_name
branch = local.repo_branch
file = "${local.config_repo_path}/ingressroute.yaml"
Expand All @@ -138,6 +142,7 @@ resource "github_repository_file" "grafana_config_ingressroute" {
}

resource "github_repository_file" "grafana_config_alert_config" {
count = var.grafana_enabled ? 1 : 0
repository = var.repo_name
branch = local.repo_branch
file = "${local.config_repo_path}/alert-config.yaml"
Expand All @@ -146,6 +151,7 @@ resource "github_repository_file" "grafana_config_alert_config" {
}

resource "github_repository_file" "grafana_config_init" {
count = var.grafana_enabled ? 1 : 0
repository = var.repo_name
branch = local.repo_branch
file = "${local.config_repo_path}/kustomization.yaml"
Expand Down
2 changes: 1 addition & 1 deletion _sub/compute/helm-kube-prometheus-stack/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "grafana_admin_password" {
value = "This value is stored in the AWS SSM Parameter Store at ${aws_ssm_parameter.param_grafana_password.name}"
value = var.grafana_enabled ? "This value is stored in the AWS SSM Parameter Store at ${aws_ssm_parameter.param_grafana_password.name}" : ""
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
etcd:
enabled: true
grafana:
enabled: ${grafana_enabled}
%{ if length(grafana_slack_webhook) > 0 ~}
alerting:
contactpoints.yaml:
Expand Down
6 changes: 6 additions & 0 deletions _sub/compute/helm-kube-prometheus-stack/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ variable "priority_class" {
description = "Name of priority class to apply"
}

variable "grafana_enabled" {
type = bool
description = "Feature toogle for Grafana deployment or not"
default = true
}

variable "grafana_admin_password" {
type = string
description = "Grafana admin password"
Expand Down
1 change: 1 addition & 0 deletions compute/k8s-services/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ module "monitoring_kube_prometheus_stack" {
chart_version = var.monitoring_kube_prometheus_stack_chart_version
namespace = module.monitoring_namespace[0].name
priority_class = var.monitoring_kube_prometheus_stack_priority_class
grafana_enabled = var.monitoring_kube_prometheus_stack_grafana_enabled
grafana_admin_password = var.monitoring_kube_prometheus_stack_grafana_admin_password
grafana_ingress_path = var.monitoring_kube_prometheus_stack_grafana_ingress_path
grafana_host = "grafana.${var.eks_cluster_name}.${var.workload_dns_zone_name}"
Expand Down
13 changes: 7 additions & 6 deletions compute/k8s-services/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
# Prometheus Stack
# --------------------------------------------------

output "prometheus_grafana_admin_password" {
value = try(module.monitoring_kube_prometheus_stack[0].grafana_admin_password, "")
output "grafana_admin_password" {
value = var.monitoring_kube_prometheus_stack_deploy && var.monitoring_kube_prometheus_stack_grafana_enabled ? try(module.monitoring_kube_prometheus_stack[0].grafana_admin_password, "") : "Not enabled in service configuration."
}

output "grafana_url" {
value = var.monitoring_kube_prometheus_stack_deploy && var.monitoring_kube_prometheus_stack_grafana_enabled ? "https://grafana.${var.eks_cluster_name}.${var.workload_dns_zone_name}${var.monitoring_kube_prometheus_stack_grafana_ingress_path}" : "Not enabled in service configuration."
}


# --------------------------------------------------
# Traefik
# --------------------------------------------------
Expand All @@ -21,7 +26,3 @@ output "traefik_blue_variant_dashboard_url" {
output "traefik_green_variant_dashboard_url" {
value = var.traefik_green_variant_deploy ? "https://traefik-green-variant.${var.eks_cluster_name}.${var.workload_dns_zone_name}/dashboard/" : "Not enabled in service configuration."
}

output "grafana_url" {
value = var.monitoring_kube_prometheus_stack_deploy ? "https://grafana.${var.eks_cluster_name}.${var.workload_dns_zone_name}${var.monitoring_kube_prometheus_stack_grafana_ingress_path}" : "Not enabled in service configuration."
}
12 changes: 9 additions & 3 deletions compute/k8s-services/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ variable "monitoring_kube_prometheus_stack_priority_class" {
default = "cluster-monitoring"
}

variable "monitoring_kube_prometheus_stack_grafana_enabled" {
type = bool
description = "Feature toogle for Grafana deployment or not"
default = true
}

variable "monitoring_kube_prometheus_stack_grafana_admin_password" {
type = string
description = "Grafana admin password"
Expand Down Expand Up @@ -1480,7 +1486,7 @@ variable "falco_stream_channel_name" {
}

variable "falco_custom_rules" {
type = string
default = ""
type = string
default = ""
description = "Custom rules to be added to the falco config"
}
}
1 change: 1 addition & 0 deletions test/integration/eu-west-1/k8s-qa/services/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ inputs = {
monitoring_kube_prometheus_stack_prometheus_request_cpu = "500m"
monitoring_kube_prometheus_stack_prometheus_limit_memory = "2Gi"
monitoring_kube_prometheus_stack_prometheus_limit_cpu = "1000m"
monitoring_kube_prometheus_stack_grafana_enabled = false
monitoring_kube_prometheus_stack_grafana_storage_enabled = false
monitoring_kube_prometheus_stack_grafana_storage_size = "5Gi"
monitoring_kube_prometheus_stack_grafana_storageclass = "gp2"
Expand Down

0 comments on commit 8a76af7

Please sign in to comment.