provisioning-catalog/components/loki/cluster/vars.nu

103 lines
3.1 KiB
Text
Raw Normal View History

#!/usr/bin/env nu
# Derived variables for loki bundle rendering.
# Generates loki_config_yaml from params.storage_backend and params.retention_days.
def main [component_json: string]: nothing -> nothing {
let d = ($component_json | from json)
let backend = ($d | get -o params.storage_backend.kind | default "filesystem")
let bucket = ($d | get -o params.storage_backend.bucket | default "loki-chunks")
let region = ($d | get -o params.storage_backend.region | default "us-east-1")
let endpoint = ($d | get -o params.storage_backend.endpoint | default "")
# insecure=true disables HTTPS on the S3 connection (plain HTTP). Required for
# in-cluster object stores served over HTTP (e.g. Garage at garage.svc:3900,
# TLS terminated at the ingress, not the store). Defaults false for real AWS/HTTPS.
let insecure = ($d | get -o params.storage_backend.insecure | default false)
let retention = ($d | get -o params.retention_days | default 90)
let replication = ($d | get -o params.replication | default 1)
# Resolve S3 endpoint: use explicit endpoint if set, fall back to AWS regional URL.
let s3_endpoint = if ($endpoint | is-not-empty) { $endpoint } else { $"s3.($region).amazonaws.com" }
let object_store = if $backend == "s3" { "s3" } else { "filesystem" }
let delete_store = if $backend == "s3" { "s3" } else { "filesystem" }
# Loki 3.x: S3 config lives under common.storage.s3.
# filesystem fallback uses common.storage.filesystem paths only.
let common_storage = if $backend == "s3" {
$" storage:
s3:
endpoint: ($s3_endpoint)
region: ($region)
bucketnames: ($bucket)
access_key_id: $\{LOKI_S3_ACCESS_KEY}
secret_access_key: $\{LOKI_S3_SECRET_KEY}
insecure: ($insecure)
s3forcepathstyle: true
http_config:
idle_conn_timeout: 90s
insecure_skip_verify: false"
} else {
$" storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules"
}
let loki_config_yaml = $"auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
common:
instance_addr: 127.0.0.1
path_prefix: /loki
($common_storage)
replication_factor: ($replication)
ring:
kvstore:
store: inmemory
query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100
schema_config:
configs:
- from: 2024-01-01
store: tsdb
object_store: ($object_store)
schema: v13
index:
prefix: index_
period: 24h
storage_config:
tsdb_shipper:
active_index_directory: /loki/index
cache_location: /loki/index_cache
cache_ttl: 24h
ruler:
alertmanager_url: http://localhost:9093
limits_config:
retention_period: ($retention)d
compactor:
working_directory: /loki/compactor
retention_enabled: true
retention_delete_delay: 2h
retention_delete_worker_count: 150
delete_request_store: ($delete_store)
analytics:
reporting_enabled: false"
{ loki_config_yaml: $loki_config_yaml } | to json --raw | print
}