From b736ecb94eea7f9338da0309d2e1e895d74e6cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Heleno?= Date: Wed, 3 Apr 2024 11:41:37 +0200 Subject: [PATCH] feat: add variable to set resources with default values Having default values is good practice to prevent that our components could eventually starve other workloads on the cluster. However, these should probably be adapted in production clusters and are only a safeguard in case someone forgets to set them. --- aks/main.tf | 1 + eks/main.tf | 1 + kind/main.tf | 1 + locals.tf | 45 +++++++++++++++- sks/main.tf | 1 + variables.tf | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 191 insertions(+), 2 deletions(-) diff --git a/aks/main.tf b/aks/main.tf index ae8096e0..75e5ee69 100644 --- a/aks/main.tf +++ b/aks/main.tf @@ -62,6 +62,7 @@ module "loki-stack" { app_autosync = var.app_autosync dependency_ids = var.dependency_ids + resources = var.resources retention = var.retention ingress = var.ingress diff --git a/eks/main.tf b/eks/main.tf index d50df732..c60c4d05 100644 --- a/eks/main.tf +++ b/eks/main.tf @@ -8,6 +8,7 @@ module "loki-stack" { app_autosync = var.app_autosync dependency_ids = var.dependency_ids + resources = var.resources retention = var.retention ingress = var.ingress diff --git a/kind/main.tf b/kind/main.tf index d50df732..c60c4d05 100644 --- a/kind/main.tf +++ b/kind/main.tf @@ -8,6 +8,7 @@ module "loki-stack" { app_autosync = var.app_autosync dependency_ids = var.dependency_ids + resources = var.resources retention = var.retention ingress = var.ingress diff --git a/locals.tf b/locals.tf index 0ddd7126..6f6e3f27 100644 --- a/locals.tf +++ b/locals.tf @@ -29,6 +29,16 @@ locals { persistence = { enabled = true } + resources = { + requests = { for k, v in var.resources.compactor.requests : k => v if v != null } + limits = { for k, v in var.resources.compactor.limits : k => v if v != null } + } + } + distributor = { + resources = { + requests = { for k, v in var.resources.distributor.requests : k => v if v != null } + limits = { for k, v in var.resources.distributor.limits : k => v if v != null } + } } gateway = { enabled = false @@ -38,8 +48,11 @@ locals { persistence = { enabled = true } + resources = { + requests = { for k, v in var.resources.index_gateway.requests : k => v if v != null } + limits = { for k, v in var.resources.index_gateway.limits : k => v if v != null } + } } - # TODO ingester HA ingester = { persistence = { enabled = true @@ -47,6 +60,10 @@ locals { replicas = 3 maxUnavailable = 1 affinity = "" + resources = { + requests = { for k, v in var.resources.ingester.requests : k => v if v != null } + limits = { for k, v in var.resources.ingester.limits : k => v if v != null } + } } loki = { structuredConfig = { @@ -136,21 +153,41 @@ locals { } memcachedChunks = { enabled = true + resources = { + requests = { for k, v in var.resources.memcached_chunks.requests : k => v if v != null } + limits = { for k, v in var.resources.memcached_chunks.limits : k => v if v != null } + } } memcachedFrontend = { enabled = true + resources = { + requests = { for k, v in var.resources.memcached_frontend.requests : k => v if v != null } + limits = { for k, v in var.resources.memcached_frontend.limits : k => v if v != null } + } } memcachedIndexQueries = { enabled = true + resources = { + requests = { for k, v in var.resources.memcached_index_queries.requests : k => v if v != null } + limits = { for k, v in var.resources.memcached_index_queries.limits : k => v if v != null } + } } queryScheduler = { enabled = true affinity = "" + resources = { + requests = { for k, v in var.resources.query_scheduler.requests : k => v if v != null } + limits = { for k, v in var.resources.query_scheduler.limits : k => v if v != null } + } } querier = { - affinity = "" replicas = 4 maxUnavailable = 2 + affinity = "" + resources = { + requests = { for k, v in var.resources.querier.requests : k => v if v != null } + limits = { for k, v in var.resources.querier.limits : k => v if v != null } + } } ruler = { directories = {} @@ -159,6 +196,10 @@ locals { } promtail = { + resources = { + requests = { for k, v in var.resources.promtail.requests : k => v if v != null } + limits = { for k, v in var.resources.promtail.limits : k => v if v != null } + } tolerations = [ { operator = "Exists" diff --git a/sks/main.tf b/sks/main.tf index d50df732..c60c4d05 100644 --- a/sks/main.tf +++ b/sks/main.tf @@ -8,6 +8,7 @@ module "loki-stack" { app_autosync = var.app_autosync dependency_ids = var.dependency_ids + resources = var.resources retention = var.retention ingress = var.ingress diff --git a/variables.tf b/variables.tf index d9bc014e..7957e925 100644 --- a/variables.tf +++ b/variables.tf @@ -56,6 +56,150 @@ variable "dependency_ids" { ## Module variables ####################### +variable "resources" { + description = <<-EOT + Resource limits and requests for Loki's components. Follow the style on https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/[official documentation] to understand the format of the values. + + IMPORTANT: These are not production values. You should always adjust them to your needs. + EOT + type = object({ + + ingester = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "256Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "512Mi") + }), {}) + }), {}) + + distributor = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "256Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "512Mi") + }), {}) + }), {}) + + querier = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "256Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "512Mi") + }), {}) + }), {}) + + query_frontend = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "256Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "512Mi") + }), {}) + }), {}) + + query_scheduler = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "256Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "512Mi") + }), {}) + }), {}) + + compactor = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "512Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "1Gi") + }), {}) + }), {}) + + index_gateway = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "256Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "1Gi") + }), {}) + }), {}) + + memcached_chunks = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "256Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "512Mi") + }), {}) + }), {}) + + memcached_frontend = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "256Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "512Mi") + }), {}) + }), {}) + + memcached_index_queries = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "256Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "512Mi") + }), {}) + }), {}) + + promtail = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "256Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "512Mi") + }), {}) + }), {}) + + grafana_eventhandler = optional(object({ + requests = optional(object({ + cpu = optional(string, "100m") + memory = optional(string, "128Mi") + }), {}) + limits = optional(object({ + cpu = optional(string) + memory = optional(string, "256Mi") + }), {}) + }), {}) + + }) + default = {} +} + variable "ingress" { description = "Loki frontend ingress configuration." type = object({