Skip to content

Commit

Permalink
feat: add variable to set resources with default values
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lentidas committed Apr 16, 2024
1 parent 19a0098 commit b736ecb
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 2 deletions.
1 change: 1 addition & 0 deletions aks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions kind/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 43 additions & 2 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,15 +48,22 @@ 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
}
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 = {
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions sks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
144 changes: 144 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit b736ecb

Please sign in to comment.