# =====================================================================
# Loki + Grafana Alloy — log aggregation
#
# Loki:
#   helm repo add grafana https://grafana.github.io/helm-charts
#   helm repo update
#   helm install loki grafana/loki -n monitoring -f loki-values.yaml
#
# Alloy (raccolta log, DaemonSet su ogni nodo RKE2):
#   helm install alloy grafana/alloy -n monitoring -f alloy-values.yaml
#
# Questo file contiene ENTRAMBI i set di values, separati da "---";
# salvali in due file distinti se preferisci due comandi helm separati.
# =====================================================================

# ---------------------------------------------------------------------
# loki-values.yaml (modalità single-binary, adatta a partire in piccolo;
# per HA/produzione a lungo termine valutare la modalità "simple scalable"
# con backend object storage S3-compatibile, es. MinIO)
# ---------------------------------------------------------------------
deploymentMode: SingleBinary

loki:
  auth_enabled: false
  commonConfig:
    replication_factor: 1
  storage:
    type: filesystem

singleBinary:
  replicas: 1
  persistence:
    enabled: true
    storageClass: longhorn   # <-- CAMBIA con la tua storageClass
    size: 50Gi
  resources:
    requests:
      cpu: 200m
      memory: 512Mi
    limits:
      memory: 1Gi

# Disabilita i componenti "scalable" non necessari in modalità SingleBinary
read:
  replicas: 0
write:
  replicas: 0
backend:
  replicas: 0

gateway:
  enabled: false

test:
  enabled: false

---
# ---------------------------------------------------------------------
# alloy-values.yaml (DaemonSet che raccoglie log da tutti i nodi/pod
# e li invia a Loki)
# ---------------------------------------------------------------------
alloy:
  configMap:
    content: |
      discovery.kubernetes "pods" {
        role = "pod"
      }

      discovery.relabel "pods" {
        targets = discovery.kubernetes.pods.targets

        rule {
          source_labels = ["__meta_kubernetes_namespace"]
          target_label  = "namespace"
        }
        rule {
          source_labels = ["__meta_kubernetes_pod_name"]
          target_label  = "pod"
        }
        rule {
          source_labels = ["__meta_kubernetes_pod_container_name"]
          target_label  = "container"
        }
      }

      loki.source.kubernetes "pods" {
        targets    = discovery.relabel.pods.output
        forward_to = [loki.write.default.receiver]
      }

      loki.write "default" {
        endpoint {
          url = "http://loki.monitoring.svc.cluster.local:3100/loki/api/v1/push"
        }
      }

controller:
  type: daemonset

resources:
  requests:
    cpu: 100m
    memory: 128Mi
  limits:
    memory: 256Mi
