From dce28cb65fa96ac2a7bb0d599605cc0044ab4ce1 Mon Sep 17 00:00:00 2001 From: sophon Date: Wed, 25 Dec 2024 19:21:31 +0800 Subject: [PATCH] chore: support parameters api for loki --- addons-cluster/loki/templates/_helpers.tpl | 510 +----------------- addons-cluster/loki/templates/cluster.yaml | 15 +- .../loki/templates/configmap-gateway.yaml | 10 - addons-cluster/loki/templates/configmap.yaml | 9 - .../loki/templates/runtime-configmap.yaml | 10 - addons-cluster/loki/values.yaml | 256 +-------- addons/loki/configs/loki-config.tpl | 129 +++++ addons/loki/configs/loki-gateway-config.tpl | 161 ++++++ addons/loki/configs/loki-runtime-config.tpl | 1 + addons/loki/templates/_helpers.tpl | 318 +---------- addons/loki/templates/clusterdefinition.yaml | 3 +- addons/loki/templates/cmpd-backend.yaml | 63 +-- addons/loki/templates/cmpd-gateway.yaml | 20 +- addons/loki/templates/cmpd-read.yaml | 52 +- addons/loki/templates/cmpd-write.yaml | 42 +- addons/loki/templates/cmpv.yaml | 6 +- addons/loki/templates/configmap.yaml | 31 ++ addons/loki/templates/pcr-backend.yaml | 13 + addons/loki/templates/pcr-read.yaml | 13 + addons/loki/templates/pcr-write.yaml | 13 + addons/loki/values.yaml | 43 +- 21 files changed, 535 insertions(+), 1183 deletions(-) delete mode 100644 addons-cluster/loki/templates/configmap-gateway.yaml delete mode 100644 addons-cluster/loki/templates/configmap.yaml delete mode 100644 addons-cluster/loki/templates/runtime-configmap.yaml create mode 100644 addons/loki/configs/loki-config.tpl create mode 100644 addons/loki/configs/loki-gateway-config.tpl create mode 100644 addons/loki/configs/loki-runtime-config.tpl create mode 100644 addons/loki/templates/configmap.yaml create mode 100644 addons/loki/templates/pcr-backend.yaml create mode 100644 addons/loki/templates/pcr-read.yaml create mode 100644 addons/loki/templates/pcr-write.yaml diff --git a/addons-cluster/loki/templates/_helpers.tpl b/addons-cluster/loki/templates/_helpers.tpl index e999ddfa9..a0905e520 100644 --- a/addons-cluster/loki/templates/_helpers.tpl +++ b/addons-cluster/loki/templates/_helpers.tpl @@ -23,6 +23,10 @@ If release name contains chart name it will be used as a full name. {{- end }} {{- end }} +{{- define "clustername" -}} +{{ include "loki-cluster.fullname" .}} +{{- end}} + {{/* Create chart name and version as used by the chart label. */}} @@ -46,465 +50,10 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} Selector labels */}} {{- define "loki-cluster.selectorLabels" -}} -app.kubernetes.io/name: {{ include "loki-cluster.name" . }} +{{/*app.kubernetes.io/name: {{ include "loki-cluster.name" . }}*/}} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} -{{/* -Create the name of the service account to use -*/}} -{{- define "loki-cluster.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "loki-cluster.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} - -{{- define "clustername" -}} -{{ include "loki-cluster.fullname" .}} -{{- end}} - - - -{{/* Create a default storage config that uses filesystem storage -This is required for CI, but Loki will not be queryable with this default -applied, thus it is encouraged that users override this. -*/}} -{{- define "loki-cluster.storageConfig" -}} -{{- if .Values.loki.storageConfig -}} -{{- .Values.loki.storageConfig | toYaml | nindent 4 -}} -{{- else }} -{{- .Values.loki.defaultStorageConfig | toYaml | nindent 4 }} -{{- end}} -{{- end}} - - -{{/* -Base template for building docker image reference -*/}} -{{- define "loki-cluster.baseImage" }} -{{- $registry := .global.registry | default .service.registry -}} -{{- $repository := .service.repository -}} -{{- $tag := .service.tag | default .defaultVersion | toString -}} -{{- printf "%s/%s:%s" $registry $repository $tag -}} -{{- end -}} - - -{{/* -Generated storage config for loki-cluster common config -*/}} -{{- define "loki-cluster.commonStorageConfig" -}} -{{- if .Values.minio.enabled -}} -s3: - endpoint: {{ include "loki-cluster.minio" $ }} - bucketnames: {{ $.Values.loki.storage.bucketNames.chunks }} - secret_access_key: supersecret - access_key_id: enterprise-logs - s3forcepathstyle: true - insecure: true -{{- else if eq .Values.loki.storage.type "s3" -}} -{{- with .Values.loki.storage.s3 }} -s3: - {{- with .s3 }} - s3: {{ . }} - {{- end }} - {{- with .endpoint }} - endpoint: {{ . }} - {{- end }} - {{- with .region }} - region: {{ . }} - {{- end}} - bucketnames: {{ $.Values.loki.storage.bucketNames.chunks }} - {{- with .secretAccessKey }} - secret_access_key: {{ . }} - {{- end }} - {{- with .accessKeyId }} - access_key_id: {{ . }} - {{- end }} - s3forcepathstyle: {{ .s3ForcePathStyle }} - insecure: {{ .insecure }} -{{- end -}} -{{- else if eq .Values.loki.storage.type "gcs" -}} -{{- with .Values.loki.storage.gcs }} -gcs: - bucket_name: {{ $.Values.loki.storage.bucketNames.chunks }} - chunk_buffer_size: {{ .chunkBufferSize }} - request_timeout: {{ .requestTimeout }} - enable_http2: {{ .enableHttp2}} -{{- end -}} -{{- else -}} -{{- with .Values.loki.storage.local }} -filesystem: - chunks_directory: {{ .chunks_directory }} - rules_directory: {{ .rules_directory }} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Storage config for ruler -*/}} -{{- define "loki-cluster.rulerStorageConfig" -}} -{{- if or .Values.minio.enabled (eq .Values.loki.storage.type "s3") -}} -s3: - bucketnames: {{ $.Values.loki.storage.bucketNames.ruler }} -{{- else if eq .Values.loki.storage.type "gcs" -}} -gcs: - bucket_name: {{ $.Values.loki.storage.bucketNames.ruler }} -{{- end -}} -{{- end -}} - -{{/* -Memcached Docker image -*/}} -{{- define "loki.memcachedImage" -}} -{{- $dict := dict "service" .Values.memcached.image "global" .Values.global.image -}} -{{- include "loki-cluster.image" $dict -}} -{{- end }} - -{{/* -Memcached Exporter Docker image -*/}} -{{- define "loki-cluster.memcachedExporterImage" -}} -{{- $dict := dict "service" .Values.memcachedExporter.image "global" .Values.global.image -}} -{{- include "loki-cluster.image" $dict -}} -{{- end }} - -{{/* -Return the appropriate apiVersion for ingress. -*/}} -{{- define "loki-cluster.ingress.apiVersion" -}} - {{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) -}} - {{- print "networking.k8s.io/v1" -}} - {{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}} - {{- print "networking.k8s.io/v1beta1" -}} - {{- else -}} - {{- print "extensions/v1beta1" -}} - {{- end -}} -{{- end -}} - -{{/* -Return if ingress is stable. -*/}} -{{- define "loki-cluster.ingress.isStable" -}} - {{- eq (include "loki-cluster.ingress.apiVersion" .) "networking.k8s.io/v1" -}} -{{- end -}} - -{{/* -Return if ingress supports ingressClassName. -*/}} -{{- define "loki-cluster.ingress.supportsIngressClassName" -}} - {{- or (eq (include "loki-cluster.ingress.isStable" .) "true") (and (eq (include "loki-cluster.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}} -{{- end -}} - -{{/* -Return if ingress supports pathType. -*/}} -{{- define "loki-cluster.ingress.supportsPathType" -}} - {{- or (eq (include "loki-cluster.ingress.isStable" .) "true") (and (eq (include "loki-cluster.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}} -{{- end -}} - -{{/* -Create the service endpoint including port for MinIO. -*/}} -{{- define "loki-cluster.minio" -}} -{{- if .Values.minio.enabled -}} -{{- printf "%s-%s.%s.svc:%s" .Release.Name "minio" .Release.Namespace (.Values.minio.service.port | toString) -}} -{{- end -}} -{{- end -}} - -{{/* Return the appropriate apiVersion for PodDisruptionBudget. */}} -{{- define "loki-cluster.podDisruptionBudget.apiVersion" -}} - {{- if and (.Capabilities.APIVersions.Has "policy/v1") (semverCompare ">= 1.21-0" .Capabilities.KubeVersion.Version) -}} - {{- print "policy/v1" -}} - {{- else -}} - {{- print "policy/v1beta1" -}} - {{- end -}} -{{- end -}} - -{{/* Snippet for the nginx file used by gateway */}} -{{- define "loki-cluster.nginxFile" }} -worker_processes 5; ## Default: 1 -error_log /dev/stderr; -pid /tmp/nginx.pid; -worker_rlimit_nofile 8192; - -events { - worker_connections 4096; ## Default: 1024 -} - -http { - client_body_temp_path /tmp/client_temp; - proxy_temp_path /tmp/proxy_temp_path; - fastcgi_temp_path /tmp/fastcgi_temp; - uwsgi_temp_path /tmp/uwsgi_temp; - scgi_temp_path /tmp/scgi_temp; - - client_max_body_size 4M; - - proxy_read_timeout 600; ## 10 minutes - proxy_send_timeout 600; - proxy_connect_timeout 600; - - proxy_http_version 1.1; - - default_type application/octet-stream; - log_format {{ .Values.gateway.nginxConfig.logFormat }} - - {{- if .Values.gateway.verboseLogging }} - access_log /dev/stderr main; - {{- else }} - - map $status $loggable { - ~^[23] 0; - default 1; - } - access_log /dev/stderr main if=$loggable; - {{- end }} - - sendfile on; - tcp_nopush on; - {{- if .Values.gateway.nginxConfig.resolver }} - resolver {{ .Values.gateway.nginxConfig.resolver }}; - {{- else }} - resolver {{ .Values.global.dnsService }}.{{ .Values.global.dnsNamespace }}.svc.{{ .Values.global.clusterDomain }}.; - {{- end }} - - {{- with .Values.gateway.nginxConfig.httpSnippet }} - {{- tpl . $ | nindent 2 }} - {{- end }} - - server { - {{- if (.Values.gateway.nginxConfig.ssl) }} - listen 8080 ssl; - {{- if .Values.gateway.nginxConfig.enableIPv6 }} - listen [::]:8080 ssl; - {{- end }} - {{- else }} - listen 8080; - {{- if .Values.gateway.nginxConfig.enableIPv6 }} - listen [::]:8080; - {{- end }} - {{- end }} - - {{- if .Values.gateway.basicAuth.enabled }} - auth_basic "Loki"; - auth_basic_user_file /etc/nginx/secrets/.htpasswd; - {{- end }} - - location = / { - return 200 'OK'; - auth_basic off; - } - - ######################################################## - # Configure backend targets - - {{- $backendHost := include "loki-cluster.backendFullname" .}} - {{- $readHost := include "loki-cluster.readFullname" .}} - {{- $writeHost := include "loki-cluster.writeFullname" .}} - - {{- if .Values.read.legacyReadTarget }} - {{- $backendHost = include "loki-cluster.readFullname" . }} - {{- end }} - - {{- $httpSchema := .Values.gateway.nginxConfig.schema }} - - {{- $writeUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $writeHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $readUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $readHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $backendUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $backendHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - - {{- if .Values.gateway.nginxConfig.customWriteUrl }} - {{- $writeUrl = .Values.gateway.nginxConfig.customWriteUrl }} - {{- end }} - {{- if .Values.gateway.nginxConfig.customReadUrl }} - {{- $readUrl = .Values.gateway.nginxConfig.customReadUrl }} - {{- end }} - {{- if .Values.gateway.nginxConfig.customBackendUrl }} - {{- $backendUrl = .Values.gateway.nginxConfig.customBackendUrl }} - {{- end }} - - {{- $singleBinaryHost := include "loki-cluster.singleBinaryFullname" . }} - {{- $singleBinaryUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $singleBinaryHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - - {{- $distributorHost := include "loki-cluster.distributorFullname" .}} - {{- $ingesterHost := include "loki-cluster.ingesterFullname" .}} - {{- $queryFrontendHost := include "loki-cluster.queryFrontendFullname" .}} - {{- $indexGatewayHost := include "loki-cluster.indexGatewayFullname" .}} - {{- $rulerHost := include "loki-cluster.rulerFullname" .}} - {{- $compactorHost := include "loki-cluster.compactorFullname" .}} - {{- $schedulerHost := include "loki-cluster.querySchedulerFullname" .}} - - - {{- $distributorUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $distributorHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) -}} - {{- $ingesterUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $ingesterHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $queryFrontendUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $queryFrontendHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $indexGatewayUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $indexGatewayHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $rulerUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $rulerHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $compactorUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $compactorHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $schedulerUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $schedulerHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - - {{- if eq (include "loki-cluster.deployment.isSingleBinary" .) "true"}} - {{- $distributorUrl = $singleBinaryUrl }} - {{- $ingesterUrl = $singleBinaryUrl }} - {{- $queryFrontendUrl = $singleBinaryUrl }} - {{- $indexGatewayUrl = $singleBinaryUrl }} - {{- $rulerUrl = $singleBinaryUrl }} - {{- $compactorUrl = $singleBinaryUrl }} - {{- $schedulerUrl = $singleBinaryUrl }} - {{- else if eq (include "loki-cluster.deployment.isScalable" .) "true"}} - {{- $distributorUrl = $writeUrl }} - {{- $ingesterUrl = $writeUrl }} - {{- $queryFrontendUrl = $readUrl }} - {{- $indexGatewayUrl = $backendUrl }} - {{- $rulerUrl = $backendUrl }} - {{- $compactorUrl = $backendUrl }} - {{- $schedulerUrl = $backendUrl }} - {{- end -}} - - # Distributor - location = /api/prom/push { - proxy_pass {{ $distributorUrl }}$request_uri; - } - location = /loki-cluster/api/v1/push { - proxy_pass {{ $distributorUrl }}$request_uri; - } - location = /distributor/ring { - proxy_pass {{ $distributorUrl }}$request_uri; - } - location = /otlp/v1/logs { - proxy_pass {{ $distributorUrl }}$request_uri; - } - - # Ingester - location = /flush { - proxy_pass {{ $ingesterUrl }}$request_uri; - } - location ^~ /ingester/ { - proxy_pass {{ $ingesterUrl }}$request_uri; - } - location = /ingester { - internal; # to suppress 301 - } - - # Ring - location = /ring { - proxy_pass {{ $ingesterUrl }}$request_uri; - } - - # MemberListKV - location = /memberlist { - proxy_pass {{ $ingesterUrl }}$request_uri; - } - - # Ruler - location = /ruler/ring { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location = /api/prom/rules { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location ^~ /api/prom/rules/ { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location = /loki-cluster/api/v1/rules { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location ^~ /loki-cluster/api/v1/rules/ { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location = /prometheus/api/v1/alerts { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location = /prometheus/api/v1/rules { - proxy_pass {{ $rulerUrl }}$request_uri; - } - - # Compactor - location = /compactor/ring { - proxy_pass {{ $compactorUrl }}$request_uri; - } - location = /loki-cluster/api/v1/delete { - proxy_pass {{ $compactorUrl }}$request_uri; - } - location = /loki-cluster/api/v1/cache/generation_numbers { - proxy_pass {{ $compactorUrl }}$request_uri; - } - - # IndexGateway - location = /indexgateway/ring { - proxy_pass {{ $indexGatewayUrl }}$request_uri; - } - - # QueryScheduler - location = /scheduler/ring { - proxy_pass {{ $schedulerUrl }}$request_uri; - } - - # Config - location = /config { - proxy_pass {{ $ingesterUrl }}$request_uri; - } - - {{- if and .Values.enterprise.enabled .Values.enterprise.adminApi.enabled }} - # Admin API - location ^~ /admin/api/ { - proxy_pass {{ $backendUrl }}$request_uri; - } - location = /admin/api { - internal; # to suppress 301 - } - {{- end }} - - - # QueryFrontend, Querier - location = /api/prom/tail { - proxy_pass {{ $queryFrontendUrl }}$request_uri; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - } - location = /loki-cluster/api/v1/tail { - proxy_pass {{ $queryFrontendUrl }}$request_uri; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - } - location ^~ /api/prom/ { - proxy_pass {{ $queryFrontendUrl }}$request_uri; - } - location = /api/prom { - internal; # to suppress 301 - } - location ^~ /loki-cluster/api/v1/ { - proxy_pass {{ $queryFrontendUrl }}$request_uri; - } - location = /loki-cluster/api/v1 { - internal; # to suppress 301 - } - - {{- with .Values.gateway.nginxConfig.serverSnippet }} - {{ . | nindent 4 }} - {{- end }} - } -} -{{- end }} - -{{/* -singleBinary fullname -*/}} -{{- define "loki-cluster.singleBinaryFullname" -}} -{{- if .Values.fullnameOverride -}} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- if contains $name .Release.Name -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - {{/* write fullname */}} @@ -616,34 +165,6 @@ query-scheduler fullname {{ include "loki-cluster.fullname" . }}-query-scheduler {{- end }} -{{/* -Return if deployment mode is simple scalable -*/}} -{{- define "loki-cluster.deployment.isScalable" -}} - {{- and (eq (include "loki-cluster.isUsingObjectStorage" . ) "true") (or (eq .Values.deploymentMode "SingleBinary<->SimpleScalable") (eq .Values.deploymentMode "SimpleScalable") (eq .Values.deploymentMode "SimpleScalable<->Distributed")) }} -{{- end -}} - -{{/* -Return if deployment mode is single binary -*/}} -{{- define "loki-cluster.deployment.isSingleBinary" -}} - {{- or (eq .Values.deploymentMode "SingleBinary") (eq .Values.deploymentMode "SingleBinary<->SimpleScalable") }} -{{- end -}} - -{{/* -Return if deployment mode is distributed -*/}} -{{- define "loki-cluster.deployment.isDistributed" -}} - {{- and (eq (include "loki-cluster.isUsingObjectStorage" . ) "true") (or (eq .Values.deploymentMode "Distributed") (eq .Values.deploymentMode "SimpleScalable<->Distributed")) }} -{{- end -}} - -{{/* Determine if deployment is using object storage */}} -{{- define "loki-cluster.isUsingObjectStorage" -}} -{{- or (eq .Values.loki.storage.type "gcs") (eq .Values.loki.storage.type "s3") (eq .Values.loki.storage.type "azure") (eq .Values.loki.storage.type "swift") (eq .Values.loki.storage.type "alibabacloud") -}} -{{- end -}} - - - {{/* gateway common labels */}} @@ -651,3 +172,24 @@ gateway common labels {{ include "loki-cluster.labels" . }} app.kubernetes.io/component: gateway {{- end }} + +{{- define "loki-cluster.s3storage" }} +env: + - name: STORAGE_TYPE + value: "local" +{{- end -}} + +{{- define "loki-cluster.memberlist" }} +services: + - name: default + serviceName: memberlist + spec: + ports: + - name: tcp + port: 7946 + targetPort: http-memberlist + protocol: TCP + selector: + {{- include "loki-cluster.selectorLabels" . | nindent 8 }} + app.kubernetes.io/part-of: memberlist +{{- end -}} \ No newline at end of file diff --git a/addons-cluster/loki/templates/cluster.yaml b/addons-cluster/loki/templates/cluster.yaml index 728ba7b21..cd7c03257 100644 --- a/addons-cluster/loki/templates/cluster.yaml +++ b/addons-cluster/loki/templates/cluster.yaml @@ -1,23 +1,19 @@ -apiVersion: apps.kubeblocks.io/v1 -kind: Cluster -metadata: - name: {{ include "clustername" . }} - namespace: {{ .Release.Namespace }} - labels: - {{- include "loki-cluster.labels" . | nindent 4 }} -spec: +{{- include "kblib.clusterCommon" . }} clusterDef: loki - terminationPolicy: {{ .Values.terminationPolicy }} topology: loki-cluster + terminationPolicy: {{ .Values.terminationPolicy }} + {{- include "loki-cluster.memberlist" . | indent 2 }} componentSpecs: - name: backend {{- include "kblib.componentMonitor" . | indent 6 }} + {{- include "loki-cluster.s3storage" . | indent 6 }} replicas: {{ .Values.replicas }} {{- include "kblib.componentResources" . | indent 6 }} {{- include "kblib.componentStorages" . | indent 6 }} - name: write {{- include "kblib.componentMonitor" . | indent 6 }} replicas: {{ .Values.write.replicas }} + {{- include "loki-cluster.s3storage" . | indent 6 }} {{- with .Values.write.resources }} resources: {{- with .limits }} @@ -34,6 +30,7 @@ spec: - name: read {{- include "kblib.componentMonitor" . | indent 6 }} replicas: {{ .Values.read.replicas | default 1 }} + {{- include "loki-cluster.s3storage" . | indent 6 }} {{- with .Values.read.resources }} resources: {{- with .limits }} diff --git a/addons-cluster/loki/templates/configmap-gateway.yaml b/addons-cluster/loki/templates/configmap-gateway.yaml deleted file mode 100644 index d9e97fa85..000000000 --- a/addons-cluster/loki/templates/configmap-gateway.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ include "loki-cluster.gatewayFullname" . }} - namespace: {{ $.Release.Namespace }} - labels: - {{- include "loki-cluster.gatewayLabels" . | nindent 4 }} -data: - nginx.conf: | - {{- tpl .Values.gateway.nginxConfig.file . | indent 2 }} diff --git a/addons-cluster/loki/templates/configmap.yaml b/addons-cluster/loki/templates/configmap.yaml deleted file mode 100644 index 81f6d7930..000000000 --- a/addons-cluster/loki/templates/configmap.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ include "loki-cluster.name" . }} - labels: - {{- include "loki-cluster.labels" . | nindent 4 }} -data: - config.yaml: | - {{- tpl (mergeOverwrite (tpl .Values.loki.config . | fromYaml) .Values.loki.structuredConfig | toYaml) . | nindent 4 }} diff --git a/addons-cluster/loki/templates/runtime-configmap.yaml b/addons-cluster/loki/templates/runtime-configmap.yaml deleted file mode 100644 index 0a32b567c..000000000 --- a/addons-cluster/loki/templates/runtime-configmap.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ include "loki-cluster.name" . }}-runtime - namespace: {{ $.Release.Namespace }} - labels: - {{- include "loki-cluster.labels" . | nindent 4 }} -data: - runtime-config.yaml: | - {{- tpl (toYaml .Values.loki.runtimeConfig) . | nindent 4 }} diff --git a/addons-cluster/loki/values.yaml b/addons-cluster/loki/values.yaml index 82691b205..3a3c76f60 100644 --- a/addons-cluster/loki/values.yaml +++ b/addons-cluster/loki/values.yaml @@ -1,208 +1,6 @@ # Default values for loki-cluster. # This is a YAML-formatted file. # Declare variables to be passed into your templates. -loki: - server: - http_listen_port: 3100 - grpc_listen_port: 9095 - http_server_read_timeout: 600s - http_server_write_timeout: 600s - - config: | - {{- if .Values.enterprise.enabled}} - {{- tpl .Values.enterprise.config . }} - {{- else }} - auth_enabled: {{ .Values.loki.auth_enabled }} - {{- end }} - - server: - http_listen_port: 3100 - grpc_listen_port: 9095 - {{- with .Values.loki.extraServerConfig }} - {{- toYaml . | nindent 2 }} - {{- end }} - - memberlist: - join_members: - - {{ include "loki-cluster.name" . }}-memberlist - - {{- if .Values.loki.commonConfig}} - common: - {{- toYaml .Values.loki.commonConfig | nindent 2}} - storage: - {{- include "loki-cluster.commonStorageConfig" . | nindent 4}} - {{- end}} - - limits_config: - reject_old_samples: true - reject_old_samples_max_age: 168h - max_cache_freshness_per_query: 10m - split_queries_by_interval: 15m - query_timeout: 300s - volume_enabled: true - - {{- with .Values.loki.memcached.chunk_cache }} - {{- if and .enabled .host }} - chunk_store_config: - chunk_cache_config: - memcached: - batch_size: {{ .batch_size }} - parallelism: {{ .parallelism }} - memcached_client: - host: {{ .host }} - service: {{ .service }} - {{- end }} - {{- end }} - - {{- if .Values.loki.schemaConfig}} - schema_config: - {{- toYaml .Values.loki.schemaConfig | nindent 2}} - {{- else }} - schema_config: - configs: - - from: 2022-01-11 - store: boltdb-shipper - {{- if eq .Values.loki.storage.type "s3" }} - object_store: s3 - {{- else if eq .Values.loki.storage.type "gcs" }} - object_store: gcs - {{- else }} - object_store: filesystem - {{- end }} - schema: v12 - index: - prefix: loki_index_ - period: 24h - {{- end }} - - {{- if or .Values.minio.enabled (eq .Values.loki.storage.type "s3") (eq .Values.loki.storage.type "gcs") }} - ruler: - storage: - {{- include "loki-cluster.rulerStorageConfig" . | nindent 4}} - {{- end -}} - - {{- with .Values.loki.memcached.results_cache }} - query_range: - align_queries_with_step: true - {{- if and .enabled .host }} - cache_results: {{ .enabled }} - results_cache: - cache: - default_validity: {{ .default_validity }} - memcached_client: - host: {{ .host }} - service: {{ .service }} - timeout: {{ .timeout }} - {{- end }} - {{- end }} - - {{- with .Values.loki.storage_config }} - storage_config: - {{- tpl (. | toYaml) $ | nindent 4 }} - {{- end }} - - {{- with .Values.loki.query_scheduler }} - query_scheduler: - {{- tpl (. | toYaml) $ | nindent 4 }} - {{- end }} - - - - auth_enabled: false - - commonConfig: - path_prefix: /var/loki - replication_factor: 3 - - storage: - bucketNames: - chunks: chunks - ruler: ruler - admin: admin - type: null - s3: - s3: null - endpoint: null - region: null - secretAccessKey: null - accessKeyId: null - s3ForcePathStyle: true - insecure: false - gcs: - chunkBufferSize: 0 - requestTimeout: "0s" - enableHttp2: true - azure: - accountName: null - accountKey: null - connectionString: null - useManagedIdentity: false - useFederatedToken: false - userAssignedId: null - requestTimeout: null - endpointSuffix: null - swift: - auth_version: null - auth_url: null - internal: null - username: null - user_domain_name: null - user_domain_id: null - user_id: null - password: null - domain_id: null - domain_name: null - project_id: null - project_name: null - project_domain_id: null - project_domain_name: null - region_name: null - container_name: null - max_retries: null - connect_timeout: null - request_timeout: null - local: - chunks_directory: /var/loki/chunks - rules_directory: /var/loki/rules - - memcached: - chunk_cache: - enabled: false - host: "" - service: "memcached-client" - batch_size: 256 - parallelism: 10 - results_cache: - enabled: false - host: "" - service: "memcached-client" - timeout: "500ms" - default_validity: "12h" - - schemaConfig: - configs: - - from: 2024-04-01 - store: tsdb - object_store: null - schema: v13 - index: - prefix: loki_index_ - period: 24h - - storage_config: - hedging: - at: "250ms" - max_per_second: 20 - up_to: 3 - - querier: - # Default is 4, if you have enough memory and CPU you can increase, reduce if OOMing - max_concurrent: 4 - - query_scheduler: {} - structuredConfig: {} - runtimeConfig: {} - tenants: [] global: # -- configures cluster domain ("cluster.local" by default) clusterDomain: "cluster.local" @@ -214,75 +12,26 @@ global: enterprise: enabled: false - read: replicas: 1 httpMetricsPort: 3100 grpcPort: 9095 httpMemberlistPort: 7946 - resources: {} - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. - - # limits: - # cpu: 500m - # memory: 512Mi - # requests: - # cpu: 500m - # memory: 512Mi write: replicas: 1 httpMetricsPort: 3100 grpcPort: 9095 httpMemberlistPort: 7946 - resources: {} - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. - - # limits: - # cpu: 500m - # memory: 512Mi - # requests: - # cpu: 500m - # memory: 512Mi backend: replicas: 1 httpMetricsPort: 3100 grpcPort: 9095 httpMemberlistPort: 7946 - resources: {} - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. - - # limits: - # cpu: 500m - # memory: 512Mi - # requests: - # cpu: 500m - # memory: 512Mi gateway: replicas: 1 - resources: {} - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. - - # limits: - # cpu: 500m - # memory: 512Mi - # requests: - # cpu: 500m - # memory: 512Mi basicAuth: # -- Enables basic authentication for the gateway enabled: false @@ -349,4 +98,9 @@ requests: ## storage: 20 +s3: + ## "s3", "local" or "oss" + storageType: "" + secret: "" + diff --git a/addons/loki/configs/loki-config.tpl b/addons/loki/configs/loki-config.tpl new file mode 100644 index 000000000..bf918fd74 --- /dev/null +++ b/addons/loki/configs/loki-config.tpl @@ -0,0 +1,129 @@ +auth_enabled: false + +{{ $storageType := getEnvByName ( index $.podSpec.containers 0 ) "STORAGE_TYPE" }} + +server: + grpc_listen_port: ${SERVER_GRPC_PORT} + http_listen_port: ${SERVER_HTTP_PORT} + grpc_server_max_recv_msg_size: 52428800 + +memberlist: + join_members: + - {{ $.cluster.metadata.name }}-memberlist + +common: + compactor_address: '{{ $.cluster.metadata.name }}-backend' + {{/* compactor_grpc_address: '{{ printf "%s-backend.%s.svc.%s:9095" $.cluster.metadata.name $.cluster.metadata.namespace .clusterDomain }}' */}} + path_prefix: /var/loki + replication_factor: 1 + storage: + {{- if eq $storageType "oss" }} + alibabacloud: + endpoint: ${ENDPOINT} + access_key_id: ${ACCESS_KEY_ID} + secret_access_key: ${SECRET_ACCESS_KEY} + bucket: ${BUCKETNAMES} + {{- else if eq $storageType "local" }} + filesystem: + chunks_directory: ${LOCAL_CHUNKS_DIR} + rules_directory: ${LOCAL_RULES_DIR} + {{- else }} + s3: + endpoint: ${ENDPOINT} + region: ${REGION} + access_key_id: ${ACCESS_KEY_ID} + secret_access_key: ${SECRET_ACCESS_KEY} + bucketnames: ${BUCKETNAMES} + insecure: true + s3forcepathstyle: true + {{- end }} + +storage_config: + {{- if eq $storageType "oss" }} + alibabacloud: + endpoint: ${ENDPOINT} + access_key_id: ${ACCESS_KEY_ID} + secret_access_key: ${SECRET_ACCESS_KEY} + bucket: ${BUCKETNAMES} + {{- else if eq $storageType "local" }} + filesystem: + directory: ${LOCAL_CHUNKS_DIR} + {{- else }} + aws: + endpoint: ${ENDPOINT} + region: ${REGION} + access_key_id: ${ACCESS_KEY_ID} + secret_access_key: ${SECRET_ACCESS_KEY} + bucketnames: ${BUCKETNAMES} + insecure: true + s3forcepathstyle: true + {{- end }} + +limits_config: + ingestion_burst_size_mb: 100 + max_cache_freshness_per_query: 10m + reject_old_samples: true + reject_old_samples_max_age: 168h + retention_period: 48h + split_queries_by_interval: 2h + +{{/* runtime_config: */}} +{{/* file: {{ getVolumePathByName ( index $.podSpec.containers 0 ) "runtime-config" }}/runtime-config.yaml */}} + +schema_config: + configs: + - from: "2022-01-11" + index: + period: 24h + prefix: loki_index_ + {{- if eq $storageType "oss" }} + object_store: alibabacloud + {{- else if eq $storageType "local" }} + object_store: filesystem + {{- else }} + object_store: s3 + {{- end }} + schema: v12 + store: boltdb-shipper + +ruler: + storage: + {{- if eq $storageType "oss" }} + alibabacloud: + bucket: ${RULER_BUCKETNAMES} + {{- else if eq $storageType "local" }} + local: + directory: ${LOCAL_RULES_DIR} + {{- else }} + s3: + bucketnames: ${RULER_BUCKETNAMES} + {{- end }} + {{- if eq $storageType "oss" }} + type: alibabacloud + {{- else if eq $storageType "local" }} + type: local + {{- else }} + type: s3 + {{- end }} + +compactor: + apply_retention_interval: 1h + compaction_interval: 5m + retention_delete_worker_count: 500 + retention_enabled: true + {{- if eq $storageType "oss" }} + shared_store: alibabacloud + {{- else if eq $storageType "local" }} + shared_store: filesystem + {{- else }} + shared_store: s3 + {{- end }} + +index_gateway: + mode: ring + +query_range: + align_queries_with_step: true + +tracing: + enabled: false \ No newline at end of file diff --git a/addons/loki/configs/loki-gateway-config.tpl b/addons/loki/configs/loki-gateway-config.tpl new file mode 100644 index 000000000..1eaa6e999 --- /dev/null +++ b/addons/loki/configs/loki-gateway-config.tpl @@ -0,0 +1,161 @@ +worker_processes 5; ## Default: 1 +error_log /dev/stderr; +pid /tmp/nginx.pid; +worker_rlimit_nofile 8192; + +events { + worker_connections 4096; ## Default: 1024 +} + +http { + client_body_temp_path /tmp/client_temp; + proxy_temp_path /tmp/proxy_temp_path; + fastcgi_temp_path /tmp/fastcgi_temp; + uwsgi_temp_path /tmp/uwsgi_temp; + scgi_temp_path /tmp/scgi_temp; + + client_max_body_size 4M; + + proxy_read_timeout 600; ## 10 minutes + proxy_send_timeout 600; + proxy_connect_timeout 600; + + proxy_http_version 1.1; + + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] $status ' + '"$request" $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + access_log /dev/stderr main; + + sendfile on; + tcp_nopush on; + resolver {{ .DNS_SERVICE }}.{{ .DNS_NAMESPACE }}.svc.{{ .clusterDomain }}.; + + server { + listen 8080; + {{- if eq .ENABLE_IPV6 "true" }} + listen [::]:8080; + {{- end }} + + location = / { + return 200 'OK'; + auth_basic off; + } + + {{- $backendHost := printf "%s-backend" $.cluster.metadata.name }} + {{- $readHost := printf "%s-read" $.cluster.metadata.name }} + {{- $writeHost := printf "%s-write" $.cluster.metadata.name }} + + {{- $writeUrl := printf "http://%s.%s.svc.%s:3100" $writeHost $.cluster.metadata.namespace .clusterDomain }} + {{- $readUrl := printf "http://%s.%s.svc.%s:3100" $readHost $.cluster.metadata.namespace .clusterDomain }} + {{- $backendUrl := printf "http://%s.%s.svc.%s:3100" $backendHost $.cluster.metadata.namespace .clusterDomain }} + + # Distributor + location = /api/prom/push { + proxy_pass {{ $writeUrl }}$request_uri; + } + location = /loki/api/v1/push { + proxy_pass {{ $writeUrl }}$request_uri; + } + location = /distributor/ring { + proxy_pass {{ $writeUrl }}$request_uri; + } + + # Ingester + location = /flush { + proxy_pass {{ $writeUrl }}$request_uri; + } + location ^~ /ingester/ { + proxy_pass {{ $writeUrl }}$request_uri; + } + location = /ingester { + internal; # to suppress 301 + } + + # Ring + location = /ring { + proxy_pass {{ $writeUrl }}$request_uri; + } + + # MemberListKV + location = /memberlist { + proxy_pass {{ $writeUrl }}$request_uri; + } + + + # Ruler + location = /ruler/ring { + proxy_pass {{ $backendUrl }}$request_uri; + } + location = /api/prom/rules { + proxy_pass {{ $backendUrl }}$request_uri; + } + location ^~ /api/prom/rules/ { + proxy_pass {{ $backendUrl }}$request_uri; + } + location = /loki/api/v1/rules { + proxy_pass {{ $backendUrl }}$request_uri; + } + location ^~ /loki/api/v1/rules/ { + proxy_pass {{ $backendUrl }}$request_uri; + } + location = /prometheus/api/v1/alerts { + proxy_pass {{ $backendUrl }}$request_uri; + } + location = /prometheus/api/v1/rules { + proxy_pass {{ $backendUrl }}$request_uri; + } + + # Compactor + location = /compactor/ring { + proxy_pass {{ $backendUrl }}$request_uri; + } + location = /loki/api/v1/delete { + proxy_pass {{ $backendUrl }}$request_uri; + } + location = /loki/api/v1/cache/generation_numbers { + proxy_pass {{ $backendUrl }}$request_uri; + } + + # IndexGateway + location = /indexgateway/ring { + proxy_pass {{ $backendUrl }}$request_uri; + } + + # QueryScheduler + location = /scheduler/ring { + proxy_pass {{ $backendUrl }}$request_uri; + } + + # Config + location = /config { + proxy_pass {{ $backendUrl }}$request_uri; + } + + # QueryFrontend, Querier + location = /api/prom/tail { + proxy_pass {{ $readUrl }}$request_uri; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + location = /loki/api/v1/tail { + proxy_pass {{ $readUrl }}$request_uri; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + location ^~ /api/prom/ { + proxy_pass {{ $readUrl }}$request_uri; + } + location = /api/prom { + internal; # to suppress 301 + } + location ^~ /loki/api/v1/ { + proxy_pass {{ $readUrl }}$request_uri; + } + location = /loki/api/v1 { + internal; # to suppress 301 + } + + } +} \ No newline at end of file diff --git a/addons/loki/configs/loki-runtime-config.tpl b/addons/loki/configs/loki-runtime-config.tpl new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/addons/loki/configs/loki-runtime-config.tpl @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/addons/loki/templates/_helpers.tpl b/addons/loki/templates/_helpers.tpl index faf505659..b6ce33dbc 100644 --- a/addons/loki/templates/_helpers.tpl +++ b/addons/loki/templates/_helpers.tpl @@ -100,303 +100,6 @@ Docker image name {{- if .Values.enterprise.enabled -}}{{- include "loki.enterpriseImage" . -}}{{- else -}}{{- include "loki.lokiImage" . -}}{{- end -}} {{- end -}} - -{{/* -Memcached Docker image -*/}} -{{- define "loki.memcachedImage" -}} -{{- $dict := dict "service" .Values.memcached.image "global" .Values.global.image -}} -{{- include "loki.image" $dict -}} -{{- end }} - -{{/* -Memcached Exporter Docker image -*/}} -{{- define "loki.memcachedExporterImage" -}} -{{- $dict := dict "service" .Values.memcachedExporter.image "global" .Values.global.image -}} -{{- include "loki.image" $dict -}} -{{- end }} -{{/* Snippet for the nginx file used by gateway */}} -{{- define "loki.nginxFile" }} -worker_processes 5; ## Default: 1 -error_log /dev/stderr; -pid /tmp/nginx.pid; -worker_rlimit_nofile 8192; - -events { - worker_connections 4096; ## Default: 1024 -} - -http { - client_body_temp_path /tmp/client_temp; - proxy_temp_path /tmp/proxy_temp_path; - fastcgi_temp_path /tmp/fastcgi_temp; - uwsgi_temp_path /tmp/uwsgi_temp; - scgi_temp_path /tmp/scgi_temp; - - client_max_body_size 4M; - - proxy_read_timeout 600; ## 10 minutes - proxy_send_timeout 600; - proxy_connect_timeout 600; - - proxy_http_version 1.1; - - default_type application/octet-stream; - log_format {{ .Values.gateway.nginxConfig.logFormat }} - - {{- if .Values.gateway.verboseLogging }} - access_log /dev/stderr main; - {{- else }} - - map $status $loggable { - ~^[23] 0; - default 1; - } - access_log /dev/stderr main if=$loggable; - {{- end }} - - sendfile on; - tcp_nopush on; - {{- if .Values.gateway.nginxConfig.resolver }} - resolver {{ .Values.gateway.nginxConfig.resolver }}; - {{- else }} - resolver {{ .Values.global.dnsService }}.{{ .Values.global.dnsNamespace }}.svc.{{ .Values.global.clusterDomain }}.; - {{- end }} - - {{- with .Values.gateway.nginxConfig.httpSnippet }} - {{- tpl . $ | nindent 2 }} - {{- end }} - - server { - {{- if (.Values.gateway.nginxConfig.ssl) }} - listen 8080 ssl; - {{- if .Values.gateway.nginxConfig.enableIPv6 }} - listen [::]:8080 ssl; - {{- end }} - {{- else }} - listen 8080; - {{- if .Values.gateway.nginxConfig.enableIPv6 }} - listen [::]:8080; - {{- end }} - {{- end }} - - {{- if .Values.gateway.basicAuth.enabled }} - auth_basic "Loki"; - auth_basic_user_file /etc/nginx/secrets/.htpasswd; - {{- end }} - - location = / { - return 200 'OK'; - auth_basic off; - } - ######################################################## - # Configure backend targets - - {{- $backendHost := include "loki.backendFullname" .}} - {{- $readHost := include "loki.readFullname" .}} - {{- $writeHost := include "loki.writeFullname" .}} - - {{- if .Values.read.legacyReadTarget }} - {{- $backendHost = include "loki.readFullname" . }} - {{- end }} - - {{- $httpSchema := .Values.gateway.nginxConfig.schema }} - - {{- $writeUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $writeHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $readUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $readHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $backendUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $backendHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - - {{- if .Values.gateway.nginxConfig.customWriteUrl }} - {{- $writeUrl = .Values.gateway.nginxConfig.customWriteUrl }} - {{- end }} - {{- if .Values.gateway.nginxConfig.customReadUrl }} - {{- $readUrl = .Values.gateway.nginxConfig.customReadUrl }} - {{- end }} - {{- if .Values.gateway.nginxConfig.customBackendUrl }} - {{- $backendUrl = .Values.gateway.nginxConfig.customBackendUrl }} - {{- end }} - - {{- $singleBinaryHost := include "loki.singleBinaryFullname" . }} - {{- $singleBinaryUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $singleBinaryHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - - {{- $distributorHost := include "loki.distributorFullname" .}} - {{- $ingesterHost := include "loki.ingesterFullname" .}} - {{- $queryFrontendHost := include "loki.queryFrontendFullname" .}} - {{- $indexGatewayHost := include "loki.indexGatewayFullname" .}} - {{- $rulerHost := include "loki.rulerFullname" .}} - {{- $compactorHost := include "loki.compactorFullname" .}} - {{- $schedulerHost := include "loki.querySchedulerFullname" .}} - - - {{- $distributorUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $distributorHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) -}} - {{- $ingesterUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $ingesterHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $queryFrontendUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $queryFrontendHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $indexGatewayUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $indexGatewayHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $rulerUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $rulerHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $compactorUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $compactorHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - {{- $schedulerUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $schedulerHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }} - - {{- if eq (include "loki.deployment.isSingleBinary" .) "true"}} - {{- $distributorUrl = $singleBinaryUrl }} - {{- $ingesterUrl = $singleBinaryUrl }} - {{- $queryFrontendUrl = $singleBinaryUrl }} - {{- $indexGatewayUrl = $singleBinaryUrl }} - {{- $rulerUrl = $singleBinaryUrl }} - {{- $compactorUrl = $singleBinaryUrl }} - {{- $schedulerUrl = $singleBinaryUrl }} - {{- else if eq (include "loki.deployment.isScalable" .) "true"}} - {{- $distributorUrl = $writeUrl }} - {{- $ingesterUrl = $writeUrl }} - {{- $queryFrontendUrl = $readUrl }} - {{- $indexGatewayUrl = $backendUrl }} - {{- $rulerUrl = $backendUrl }} - {{- $compactorUrl = $backendUrl }} - {{- $schedulerUrl = $backendUrl }} - {{- end -}} - - # Distributor - location = /api/prom/push { - proxy_pass {{ $distributorUrl }}$request_uri; - } - location = /loki/api/v1/push { - proxy_pass {{ $distributorUrl }}$request_uri; - } - location = /distributor/ring { - proxy_pass {{ $distributorUrl }}$request_uri; - } - location = /otlp/v1/logs { - proxy_pass {{ $distributorUrl }}$request_uri; - } - - # Ingester - location = /flush { - proxy_pass {{ $ingesterUrl }}$request_uri; - } - location ^~ /ingester/ { - proxy_pass {{ $ingesterUrl }}$request_uri; - } - location = /ingester { - internal; # to suppress 301 - } - - # Ring - location = /ring { - proxy_pass {{ $ingesterUrl }}$request_uri; - } - - # MemberListKV - location = /memberlist { - proxy_pass {{ $ingesterUrl }}$request_uri; - } - - # Ruler - location = /ruler/ring { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location = /api/prom/rules { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location ^~ /api/prom/rules/ { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location = /loki/api/v1/rules { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location ^~ /loki/api/v1/rules/ { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location = /prometheus/api/v1/alerts { - proxy_pass {{ $rulerUrl }}$request_uri; - } - location = /prometheus/api/v1/rules { - proxy_pass {{ $rulerUrl }}$request_uri; - } - - # Compactor - location = /compactor/ring { - proxy_pass {{ $compactorUrl }}$request_uri; - } - location = /loki/api/v1/delete { - proxy_pass {{ $compactorUrl }}$request_uri; - } - location = /loki/api/v1/cache/generation_numbers { - proxy_pass {{ $compactorUrl }}$request_uri; - } - - # IndexGateway - location = /indexgateway/ring { - proxy_pass {{ $indexGatewayUrl }}$request_uri; - } - - # QueryScheduler - location = /scheduler/ring { - proxy_pass {{ $schedulerUrl }}$request_uri; - } - - # Config - location = /config { - proxy_pass {{ $ingesterUrl }}$request_uri; - } - - {{- if and .Values.enterprise.enabled .Values.enterprise.adminApi.enabled }} - # Admin API - location ^~ /admin/api/ { - proxy_pass {{ $backendUrl }}$request_uri; - } - location = /admin/api { - internal; # to suppress 301 - } - {{- end }} - - - # QueryFrontend, Querier - location = /api/prom/tail { - proxy_pass {{ $queryFrontendUrl }}$request_uri; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - } - location = /loki/api/v1/tail { - proxy_pass {{ $queryFrontendUrl }}$request_uri; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - } - location ^~ /api/prom/ { - proxy_pass {{ $queryFrontendUrl }}$request_uri; - } - location = /api/prom { - internal; # to suppress 301 - } - location ^~ /loki/api/v1/ { - proxy_pass {{ $queryFrontendUrl }}$request_uri; - } - location = /loki/api/v1 { - internal; # to suppress 301 - } - - {{- with .Values.gateway.nginxConfig.serverSnippet }} - {{ . | nindent 4 }} - {{- end }} - } -} -{{- end }} - -{{/* -singleBinary fullname -*/}} -{{- define "loki.singleBinaryFullname" -}} -{{- if .Values.fullnameOverride -}} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- if contains $name .Release.Name -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- else -}} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} -{{- end -}} -{{- end -}} -{{- end -}} - {{/* write fullname */}} @@ -571,3 +274,24 @@ Define loki write component definition regular expression name prefix {{- define "loki.writeCmpdRegexpPattern" -}} ^loki-write- {{- end -}} + +{{/* +Define loki write parameter config renderer name +*/}} +{{- define "loki.writePCRName" -}} +loki-write-pcr-{{ .Chart.Version }} +{{- end -}} + +{{/* +Define loki backend parameter config renderer name +*/}} +{{- define "loki.backendPCRName" -}} +loki-backend-pcr-{{ .Chart.Version }} +{{- end -}} + +{{/* +Define loki read parameter config renderer name +*/}} +{{- define "loki.readPCRName" -}} +loki-read-pcr-{{ .Chart.Version }} +{{- end -}} \ No newline at end of file diff --git a/addons/loki/templates/clusterdefinition.yaml b/addons/loki/templates/clusterdefinition.yaml index 18c118837..8da6e24db 100644 --- a/addons/loki/templates/clusterdefinition.yaml +++ b/addons/loki/templates/clusterdefinition.yaml @@ -21,4 +21,5 @@ spec: orders: provision: - backend - - write,read,gateway + - write,read + - gateway diff --git a/addons/loki/templates/cmpd-backend.yaml b/addons/loki/templates/cmpd-backend.yaml index db379b2bc..20d97d75e 100644 --- a/addons/loki/templates/cmpd-backend.yaml +++ b/addons/loki/templates/cmpd-backend.yaml @@ -17,24 +17,14 @@ spec: - name: loki-backend spec: ports: - - port: {{ .Values.backend.httpMetricsPort }} + - port: {{ .Values.server.httpMetricsPort }} protocol: TCP name: http-metrics targetPort: http-metrics - - port: {{ .Values.backend.grpcPort }} + - port: {{ .Values.server.grpcPort }} protocol: TCP name: grpc targetPort: grpc - configs: - - name: loki-config - ## TODO: this cmpd is currently unavailable. It requires adding configuration templates. - templateRef: loki - volumeName: config - namespace: {{ .Release.Namespace }} - - name: loki-runtime-config - templateRef: loki-runtime - volumeName: runtime-config - namespace: {{ .Release.Namespace }} updateStrategy: BestEffortParallel runtime: automountServiceAccountToken: true @@ -46,29 +36,8 @@ spec: app.kubernetes.io/component: backend topologyKey: kubernetes.io/hostname containers: - - name: loki-sc-rules - image: {{ .Values.images.registry | default "docker.io"}}/{{ .Values.images.sidecar.repository }}:{{ .Values.images.sidecar.tag }} - imagePullPolicy: IfNotPresent - env: - - name: METHOD - value: WATCH - - name: LABEL - value: loki_rule - - name: FOLDER - value: /rules - - name: RESOURCE - value: both - - name: WATCH_SERVER_TIMEOUT - value: "60" - - name: WATCH_CLIENT_TIMEOUT - value: "60" - - name: LOG_LEVEL - value: INFO - volumeMounts: - - mountPath: /rules - name: sc-rules-volume - name: backend - imagePullPolicy: {{ .Values.images.backend.pullPolicy }} + imagePullPolicy: {{ .Values.images.pullPolicy }} securityContext: allowPrivilegeEscalation: false capabilities: @@ -76,16 +45,18 @@ spec: - ALL args: - -config.file=/etc/loki/config/config.yaml + - -runtime-config.file=/etc/loki/runtime-config/runtime-config.yaml - -target=backend - -legacy-read-mode=false + - -config.expand-env=true ports: - - containerPort: {{ .Values.backend.httpMetricsPort }} + - containerPort: {{ .Values.server.httpMetricsPort }} name: http-metrics protocol: TCP - - containerPort: {{ .Values.backend.grpcPort }} + - containerPort: {{ .Values.server.grpcPort }} name: grpc protocol: TCP - - containerPort: {{ .Values.backend.httpMemberlistPort }} + - containerPort: {{ .Values.server.httpMemberlistPort }} name: http-memberlist protocol: TCP readinessProbe: @@ -109,3 +80,21 @@ spec: name: data - mountPath: /rules name: sc-rules-volume + configs: + - name: loki-config + templateRef: loki-tpl + volumeName: config + namespace: {{ .Release.Namespace }} + - name: loki-runtime-config + templateRef: loki-runtime-tpl + volumeName: runtime-config + namespace: {{ .Release.Namespace }} + vars: + - name: SERVER_HTTP_PORT + value: {{ .Values.server.httpMetricsPort | quote }} + - name: SERVER_GRPC_PORT + value: {{ .Values.server.grpcPort | quote }} + - name: LOCAL_RULES_DIR + value: /rules/rules_data + - name: LOCAL_CHUNKS_DIR + value: /var/loki/chunks_data diff --git a/addons/loki/templates/cmpd-gateway.yaml b/addons/loki/templates/cmpd-gateway.yaml index b341fe0f6..89782243d 100644 --- a/addons/loki/templates/cmpd-gateway.yaml +++ b/addons/loki/templates/cmpd-gateway.yaml @@ -19,12 +19,6 @@ spec: protocol: TCP name: http-metrics targetPort: http-metrics - configs: - - name: config-gateway - ## TODO: this cmpd is currently unavailable. It requires adding configuration templates. - templateRef: loki-gateway - volumeName: config - namespace: {{ .Release.Namespace }} updateStrategy: BestEffortParallel runtime: automountServiceAccountToken: true @@ -64,3 +58,17 @@ spec: name: tmp - mountPath: /docker-entrypoint.d name: docker-entrypoint-d-override + configs: + - name: config-gateway + templateRef: loki-gateway-tpl + volumeName: config + namespace: {{ .Release.Namespace }} + vars: + - name: DNS_SERVICE + value: {{ .Values.global.dnsService }} + - name: DNS_NAMESPACE + value: {{ .Values.global.dnsNamespace}} + - name: CLUSTER_DOMAIN + value: {{ .Values.global.clusterDomain}} + - name: ENABLE_IPV6 + value: {{ .Values.gateway.nginxConfig.enableIPv6 | quote }} diff --git a/addons/loki/templates/cmpd-read.yaml b/addons/loki/templates/cmpd-read.yaml index 3c75d1ad5..8c61e356b 100644 --- a/addons/loki/templates/cmpd-read.yaml +++ b/addons/loki/templates/cmpd-read.yaml @@ -17,24 +17,14 @@ spec: - name: loki-read spec: ports: - - port: {{ .Values.read.httpMetricsPort }} + - port: {{ .Values.server.httpMetricsPort }} protocol: TCP name: http-metrics targetPort: http-metrics - - port: {{ .Values.read.grpcPort }} + - port: {{ .Values.server.grpcPort }} protocol: TCP name: grpc targetPort: grpc - configs: - - name: loki-config - ## TODO: this cmpd is currently unavailable. It requires adding configuration templates. - templateRef: loki - volumeName: config - namespace: {{ .Release.Namespace }} - - name: loki-runtime-config - templateRef: loki-runtime - volumeName: runtime-config - namespace: {{ .Release.Namespace }} updateStrategy: BestEffortParallel runtime: automountServiceAccountToken: true @@ -47,7 +37,7 @@ spec: topologyKey: kubernetes.io/hostname containers: - name: read - imagePullPolicy: {{ .Values.images.read.pullPolicy }} + imagePullPolicy: {{ .Values.images.pullPolicy }} securityContext: allowPrivilegeEscalation: false capabilities: @@ -55,18 +45,20 @@ spec: - ALL args: - -config.file=/etc/loki/config/config.yaml + - -runtime-config.file=/etc/loki/runtime-config/runtime-config.yaml - -target=read - -legacy-read-mode=false - -query-scheduler.use-scheduler-ring=false - - -common.compactor-grpc-address=loki-backend.default.svc.cluster.local:9095 + - -config.expand-env=true + - -common.compactor-grpc-address=$(KB_CLUSTER_NAME)-backend.$(KB_NAMESPACE).svc.{{ .Values.global.clusterDomain }}:{{ .Values.server.grpcPort }} ports: - - containerPort: {{ .Values.read.httpMetricsPort }} + - containerPort: {{ .Values.server.httpMetricsPort }} name: http-metrics protocol: TCP - - containerPort: {{ .Values.read.grpcPort }} + - containerPort: {{ .Values.server.grpcPort }} name: grpc protocol: TCP - - containerPort: {{ .Values.read.httpMemberlistPort }} + - containerPort: {{ .Values.server.httpMemberlistPort }} name: http-memberlist protocol: TCP readinessProbe: @@ -88,3 +80,29 @@ spec: name: tmp - mountPath: /var/loki name: data + configs: + - name: loki-config + templateRef: loki-tpl + volumeName: config + namespace: {{ .Release.Namespace }} + - name: loki-runtime-config + templateRef: loki-runtime-tpl + volumeName: runtime-config + namespace: {{ .Release.Namespace }} + vars: + - name: SERVER_HTTP_PORT + value: {{ .Values.server.httpMetricsPort | quote }} + - name: SERVER_GRPC_PORT + value: {{ .Values.server.grpcPort | quote }} + - name: LOCAL_RULES_DIR + value: /var/loki/rules + - name: LOCAL_CHUNKS_DIR + value: /var/loki/chunks + - name: KB_NAMESPACE + valueFrom: + clusterVarRef: + namespace: Required + - name: KB_CLUSTER_NAME + valueFrom: + clusterVarRef: + clusterName: Required diff --git a/addons/loki/templates/cmpd-write.yaml b/addons/loki/templates/cmpd-write.yaml index 18f0e3e79..ddfa32661 100644 --- a/addons/loki/templates/cmpd-write.yaml +++ b/addons/loki/templates/cmpd-write.yaml @@ -17,24 +17,14 @@ spec: - name: loki-write spec: ports: - - port: {{ .Values.write.httpMetricsPort }} + - port: {{ .Values.server.httpMetricsPort }} protocol: TCP name: http-metrics targetPort: http-metrics - - port: {{ .Values.write.grpcPort }} + - port: {{ .Values.server.grpcPort }} protocol: TCP name: grpc targetPort: grpc - configs: - - name: loki-config - ## TODO: this cmpd is currently unavailable. It requires adding configuration templates. - templateRef: loki - volumeName: config - namespace: {{ .Release.Namespace }} - - name: loki-runtime-config - templateRef: loki-runtime - volumeName: runtime-config - namespace: {{ .Release.Namespace }} updateStrategy: BestEffortParallel runtime: automountServiceAccountToken: true @@ -47,7 +37,7 @@ spec: topologyKey: kubernetes.io/hostname containers: - name: write - imagePullPolicy: {{ .Values.images.write.pullPolicy }} + imagePullPolicy: {{ .Values.images.pullPolicy }} securityContext: allowPrivilegeEscalation: false capabilities: @@ -55,15 +45,17 @@ spec: - ALL args: - -config.file=/etc/loki/config/config.yaml + - -runtime-config.file=/etc/loki/runtime-config/runtime-config.yaml - -target=write + - -config.expand-env=true ports: - - containerPort: {{ .Values.write.httpMetricsPort }} + - containerPort: {{ .Values.server.httpMetricsPort }} name: http-metrics protocol: TCP - - containerPort: {{ .Values.write.grpcPort }} + - containerPort: {{ .Values.server.grpcPort }} name: grpc protocol: TCP - - containerPort: {{ .Values.write.httpMemberlistPort }} + - containerPort: {{ .Values.server.httpMemberlistPort }} name: http-memberlist protocol: TCP readinessProbe: @@ -85,3 +77,21 @@ spec: name: tmp - mountPath: /var/loki name: data + configs: + - name: loki-config + templateRef: loki-tpl + volumeName: config + namespace: {{ .Release.Namespace }} + - name: loki-runtime-config + templateRef: loki-runtime-tpl + volumeName: runtime-config + namespace: {{ .Release.Namespace }} + vars: + - name: SERVER_HTTP_PORT + value: {{ .Values.server.httpMetricsPort | quote }} + - name: SERVER_GRPC_PORT + value: {{ .Values.server.grpcPort | quote }} + - name: LOCAL_RULES_DIR + value: /var/loki/rules + - name: LOCAL_CHUNKS_DIR + value: /var/loki/chunks diff --git a/addons/loki/templates/cmpv.yaml b/addons/loki/templates/cmpv.yaml index ebf69cecd..b8ff86f48 100644 --- a/addons/loki/templates/cmpv.yaml +++ b/addons/loki/templates/cmpv.yaml @@ -28,15 +28,15 @@ spec: - name: write-1.0.0 serviceVersion: 1.0.0 images: - write: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.write.repository }}:{{ .Values.images.write.tag }} + write: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.repository }}:{{ .Values.images.tag }} - name: read-1.0.0 serviceVersion: 1.0.0 images: - read: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.read.repository }}:{{ .Values.images.read.tag }} + read: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.repository }}:{{ .Values.images.tag }} - name: backend-1.0.0 serviceVersion: 1.0.0 images: - backend: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.backend.repository }}:{{ .Values.images.backend.tag }} + backend: {{ .Values.images.registry | default "docker.io" }}/{{ .Values.images.repository }}:{{ .Values.images.tag }} - name: gateway-1.0.0 serviceVersion: 1.0.0 images: diff --git a/addons/loki/templates/configmap.yaml b/addons/loki/templates/configmap.yaml new file mode 100644 index 000000000..70922bf3a --- /dev/null +++ b/addons/loki/templates/configmap.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: loki-tpl + labels: + {{- include "loki.labels" . | nindent 4 }} +data: + config.yaml: | + {{- .Files.Get "configs/loki-config.tpl" | nindent 4 }} +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + name: loki-runtime-tpl + labels: + {{- include "loki.labels" . | nindent 4 }} +data: + runtime-config.yaml: | + {{- .Files.Get "configs/loki-runtime-config.tpl" | nindent 4 }} +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + name: loki-gateway-tpl + labels: + {{- include "loki.labels" . | nindent 4 }} +data: + nginx.conf: | + {{- .Files.Get "configs/loki-gateway-config.tpl" | nindent 4 }} \ No newline at end of file diff --git a/addons/loki/templates/pcr-backend.yaml b/addons/loki/templates/pcr-backend.yaml new file mode 100644 index 000000000..aef500fcd --- /dev/null +++ b/addons/loki/templates/pcr-backend.yaml @@ -0,0 +1,13 @@ +apiVersion: parameters.kubeblocks.io/v1alpha1 +kind: ParamConfigRenderer +metadata: + name: {{ include "loki.backendPCRName" . }} + labels: + {{- include "loki.labels" . | nindent 4 }} +spec: + componentDef: {{ include "loki.backendCmpdName" . }} + serviceVersion: 1.0.0 + configs: + - name: config.yaml + fileFormatConfig: + format: yaml \ No newline at end of file diff --git a/addons/loki/templates/pcr-read.yaml b/addons/loki/templates/pcr-read.yaml new file mode 100644 index 000000000..772b71564 --- /dev/null +++ b/addons/loki/templates/pcr-read.yaml @@ -0,0 +1,13 @@ +apiVersion: parameters.kubeblocks.io/v1alpha1 +kind: ParamConfigRenderer +metadata: + name: {{ include "loki.readPCRName" . }} + labels: + {{- include "loki.labels" . | nindent 4 }} +spec: + componentDef: {{ include "loki.readCmpdName" . }} + serviceVersion: 1.0.0 + configs: + - name: config.yaml + fileFormatConfig: + format: yaml \ No newline at end of file diff --git a/addons/loki/templates/pcr-write.yaml b/addons/loki/templates/pcr-write.yaml new file mode 100644 index 000000000..385d77f7a --- /dev/null +++ b/addons/loki/templates/pcr-write.yaml @@ -0,0 +1,13 @@ +apiVersion: parameters.kubeblocks.io/v1alpha1 +kind: ParamConfigRenderer +metadata: + name: {{ include "loki.writePCRName" . }} + labels: + {{- include "loki.labels" . | nindent 4 }} +spec: + componentDef: {{ include "loki.writeCmpdName" . }} + serviceVersion: 1.0.0 + configs: + - name: config.yaml + fileFormatConfig: + format: yaml \ No newline at end of file diff --git a/addons/loki/values.yaml b/addons/loki/values.yaml index 1242e5cf7..2195bd38f 100644 --- a/addons/loki/values.yaml +++ b/addons/loki/values.yaml @@ -3,37 +3,25 @@ # Declare variables to be passed into your templates. images: registry: apecloud-registry.cn-zhangjiakou.cr.aliyuncs.com + tag: 2.9.4 + repository: apecloud/loki + pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - write: - tag: 3.0.0 - repository: apecloud/loki - pullPolicy: IfNotPresent - read: - tag: 3.0.0 - repository: apecloud/loki - pullPolicy: IfNotPresent - backend: - tag: 3.0.0 - repository: apecloud/loki - pullPolicy: IfNotPresent gateway: tag: 1.24-alpine repository: apecloud/nginx-unprivileged pullPolicy: IfNotPresent - sidecar: - tag: 1.24.3 - repository: apecloud/k8s-sidecar - pullPolicy: IfNotPresent -sidecarImage: - registry: "" - repository: kiwigrid/k8s-sidecar - pullPolicy: IfNotPresent - tag: 1.24.3 nameOverride: "" fullnameOverride: "" clusterVersionOverride: "" +## @param resourceNamePrefix Prefix for all resources name created by this chart, that can avoid name conflict +## if you install multiple releases of this chart. +## If specified, the cluster definition will use it as name. +resourceNamePrefix: "" + + global: # -- configures cluster domain ("cluster.local" by default) clusterDomain: "cluster.local" @@ -45,18 +33,7 @@ global: enterprise: enabled: false - -read: - httpMetricsPort: 3100 - grpcPort: 9095 - httpMemberlistPort: 7946 - -write: - httpMetricsPort: 3100 - grpcPort: 9095 - httpMemberlistPort: 7946 - -backend: +server: httpMetricsPort: 3100 grpcPort: 9095 httpMemberlistPort: 7946