blob: 572ef9a5e784640417caefa5aac78f3b43d8242c [file] [log] [blame]
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00001{{/*
2Enforce valid label value.
3See https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
4*/}}
5{{- define "loki.validLabelValue" -}}
6{{- (regexReplaceAllLiteral "[^a-zA-Z0-9._-]" . "-") | trunc 63 | trimSuffix "-" | trimSuffix "_" | trimSuffix "." }}
7{{- end }}
8
9{{/*
10Expand the name of the chart.
11*/}}
12{{- define "loki.name" -}}
13{{- $default := ternary "enterprise-logs" "loki" .Values.enterprise.enabled }}
14{{- coalesce .Values.nameOverride $default | trunc 63 | trimSuffix "-" }}
15{{- end }}
16
17{{/*
18singleBinary fullname
19*/}}
20{{- define "loki.singleBinaryFullname" -}}
21{{- if .Values.fullnameOverride -}}
22{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
23{{- else -}}
24{{- $name := default .Chart.Name .Values.nameOverride -}}
25{{- if contains $name .Release.Name -}}
26{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
27{{- else -}}
28{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
29{{- end -}}
30{{- end -}}
31{{- end -}}
32
33{{/*
34Resource name template
35Params:
36 ctx = . context
37 component = component name (optional)
38 rolloutZoneName = rollout zone name (optional)
39*/}}
40{{- define "loki.resourceName" -}}
41{{- $resourceName := include "loki.fullname" .ctx -}}
42{{- if .component -}}{{- $resourceName = printf "%s-%s" $resourceName .component -}}{{- end -}}
43{{- if and (not .component) .rolloutZoneName -}}{{- printf "Component name cannot be empty if rolloutZoneName (%s) is set" .rolloutZoneName | fail -}}{{- end -}}
44{{- if .rolloutZoneName -}}{{- $resourceName = printf "%s-%s" $resourceName .rolloutZoneName -}}{{- end -}}
45{{- if gt (len $resourceName) 253 -}}{{- printf "Resource name (%s) exceeds kubernetes limit of 253 character. To fix: shorten release name if this will be a fresh install or shorten zone names (e.g. \"a\" instead of \"zone-a\") if using zone-awareness." $resourceName | fail -}}{{- end -}}
46{{- $resourceName -}}
47{{- end -}}
48
49{{/*
50Return if deployment mode is simple scalable
51*/}}
52{{- define "loki.deployment.isScalable" -}}
Mohammed Naser65cda132024-05-02 14:34:08 -040053 {{- and (eq (include "loki.isUsingObjectStorage" . ) "true") (or (eq .Values.deploymentMode "SingleBinary<->SimpleScalable") (eq .Values.deploymentMode "SimpleScalable") (eq .Values.deploymentMode "SimpleScalable<->Distributed")) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000054{{- end -}}
55
56{{/*
57Return if deployment mode is single binary
58*/}}
59{{- define "loki.deployment.isSingleBinary" -}}
Mohammed Naser65cda132024-05-02 14:34:08 -040060 {{- or (eq .Values.deploymentMode "SingleBinary") (eq .Values.deploymentMode "SingleBinary<->SimpleScalable") }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000061{{- end -}}
62
63{{/*
Mohammed Naser65cda132024-05-02 14:34:08 -040064Return if deployment mode is distributed
65*/}}
66{{- define "loki.deployment.isDistributed" -}}
67 {{- and (eq (include "loki.isUsingObjectStorage" . ) "true") (or (eq .Values.deploymentMode "Distributed") (eq .Values.deploymentMode "SimpleScalable<->Distributed")) }}
68{{- end -}}
69
70
71{{/*
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000072Create a default fully qualified app name.
73We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
74If release name contains chart name it will be used as a full name.
75*/}}
76{{- define "loki.fullname" -}}
77{{- if .Values.fullnameOverride }}
78{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
79{{- else }}
80{{- $name := include "loki.name" . }}
81{{- if contains $name .Release.Name }}
82{{- .Release.Name | trunc 63 | trimSuffix "-" }}
83{{- else }}
84{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
85{{- end }}
86{{- end }}
87{{- end }}
88
Giovanni Tirloni59219b62024-04-09 14:50:25 -030089{{/*
90Cluster label for rules and alerts.
91*/}}
92{{- define "loki.clusterLabel" -}}
93{{- if .Values.clusterLabelOverride }}
94{{- .Values.clusterLabelOverride | trunc 63 | trimSuffix "-" }}
95{{- else }}
96{{- if .Values.fullnameOverride }}
97{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
98{{- else }}
99{{- $name := include "loki.name" . }}
100{{- if contains $name .Release.Name }}
101{{- .Release.Name | trunc 63 | trimSuffix "-" }}
102{{- else }}
103{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
104{{- end }}
105{{- end }}
106{{- end }}
107{{- end }}
108
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000109{{/* Create a default storage config that uses filesystem storage
110This is required for CI, but Loki will not be queryable with this default
111applied, thus it is encouraged that users override this.
112*/}}
113{{- define "loki.storageConfig" -}}
114{{- if .Values.loki.storageConfig -}}
115{{- .Values.loki.storageConfig | toYaml | nindent 4 -}}
116{{- else }}
117{{- .Values.loki.defaultStorageConfig | toYaml | nindent 4 }}
118{{- end}}
119{{- end}}
120
121{{/*
122Create chart name and version as used by the chart label.
123*/}}
124{{- define "loki.chart" -}}
125{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
126{{- end }}
127
128{{/*
129Common labels
130*/}}
131{{- define "loki.labels" -}}
132helm.sh/chart: {{ include "loki.chart" . }}
133{{ include "loki.selectorLabels" . }}
134{{- if or (.Chart.AppVersion) (.Values.loki.image.tag) }}
135app.kubernetes.io/version: {{ include "loki.validLabelValue" (.Values.loki.image.tag | default .Chart.AppVersion) | quote }}
136{{- end }}
137app.kubernetes.io/managed-by: {{ .Release.Service }}
138{{- end }}
139
140{{/*
141Selector labels
142*/}}
143{{- define "loki.selectorLabels" -}}
144app.kubernetes.io/name: {{ include "loki.name" . }}
145app.kubernetes.io/instance: {{ .Release.Name }}
146{{- end }}
147
148{{/*
149Create the name of the service account to use
150*/}}
151{{- define "loki.serviceAccountName" -}}
152{{- if .Values.serviceAccount.create -}}
153 {{ default (include "loki.name" .) .Values.serviceAccount.name }}
154{{- else -}}
155 {{ default "default" .Values.serviceAccount.name }}
156{{- end -}}
157{{- end -}}
158
159{{/*
160Base template for building docker image reference
161*/}}
162{{- define "loki.baseImage" }}
163{{- $registry := .global.registry | default .service.registry | default "" -}}
164{{- $repository := .service.repository | default "" -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300165{{- $ref := ternary (printf ":%s" (.service.tag | default .defaultVersion | toString)) (printf "@%s" .service.digest) (empty .service.digest) -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000166{{- if and $registry $repository -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300167 {{- printf "%s/%s%s" $registry $repository $ref -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000168{{- else -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300169 {{- printf "%s%s%s" $registry $repository $ref -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000170{{- end -}}
171{{- end -}}
172
173{{/*
174Docker image name for Loki
175*/}}
176{{- define "loki.lokiImage" -}}
177{{- $dict := dict "service" .Values.loki.image "global" .Values.global.image "defaultVersion" .Chart.AppVersion -}}
178{{- include "loki.baseImage" $dict -}}
179{{- end -}}
180
181{{/*
182Docker image name for enterprise logs
183*/}}
184{{- define "loki.enterpriseImage" -}}
185{{- $dict := dict "service" .Values.enterprise.image "global" .Values.global.image "defaultVersion" .Values.enterprise.version -}}
186{{- include "loki.baseImage" $dict -}}
187{{- end -}}
188
189{{/*
190Docker image name
191*/}}
192{{- define "loki.image" -}}
193{{- if .Values.enterprise.enabled -}}{{- include "loki.enterpriseImage" . -}}{{- else -}}{{- include "loki.lokiImage" . -}}{{- end -}}
194{{- end -}}
195
196{{/*
197Docker image name for kubectl container
198*/}}
199{{- define "loki.kubectlImage" -}}
200{{- $dict := dict "service" .Values.kubectlImage "global" .Values.global.image "defaultVersion" "latest" -}}
201{{- include "loki.baseImage" $dict -}}
202{{- end -}}
203
204{{/*
205Generated storage config for loki common config
206*/}}
207{{- define "loki.commonStorageConfig" -}}
208{{- if .Values.minio.enabled -}}
209s3:
210 endpoint: {{ include "loki.minio" $ }}
Mohammed Naser65cda132024-05-02 14:34:08 -0400211 bucketnames: chunks
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000212 secret_access_key: {{ $.Values.minio.rootPassword }}
213 access_key_id: {{ $.Values.minio.rootUser }}
214 s3forcepathstyle: true
215 insecure: true
216{{- else if eq .Values.loki.storage.type "s3" -}}
217{{- with .Values.loki.storage.s3 }}
218s3:
219 {{- with .s3 }}
220 s3: {{ . }}
221 {{- end }}
222 {{- with .endpoint }}
223 endpoint: {{ . }}
224 {{- end }}
225 {{- with .region }}
226 region: {{ . }}
227 {{- end}}
228 bucketnames: {{ $.Values.loki.storage.bucketNames.chunks }}
229 {{- with .secretAccessKey }}
230 secret_access_key: {{ . }}
231 {{- end }}
232 {{- with .accessKeyId }}
233 access_key_id: {{ . }}
234 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300235 {{- with .signatureVersion }}
236 signature_version: {{ . }}
237 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000238 s3forcepathstyle: {{ .s3ForcePathStyle }}
239 insecure: {{ .insecure }}
240 {{- with .http_config}}
241 http_config:
242 {{- with .idle_conn_timeout }}
243 idle_conn_timeout: {{ . }}
244 {{- end}}
245 {{- with .response_header_timeout }}
246 response_header_timeout: {{ . }}
247 {{- end}}
248 {{- with .insecure_skip_verify }}
249 insecure_skip_verify: {{ . }}
250 {{- end}}
251 {{- with .ca_file}}
252 ca_file: {{ . }}
253 {{- end}}
254 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300255 {{- with .backoff_config}}
256 backoff_config:
257 {{- with .min_period }}
258 min_period: {{ . }}
259 {{- end}}
260 {{- with .max_period }}
261 max_period: {{ . }}
262 {{- end}}
263 {{- with .max_retries }}
264 max_retries: {{ . }}
265 {{- end}}
266 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000267{{- end -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300268
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000269{{- else if eq .Values.loki.storage.type "gcs" -}}
270{{- with .Values.loki.storage.gcs }}
271gcs:
272 bucket_name: {{ $.Values.loki.storage.bucketNames.chunks }}
273 chunk_buffer_size: {{ .chunkBufferSize }}
274 request_timeout: {{ .requestTimeout }}
275 enable_http2: {{ .enableHttp2 }}
276{{- end -}}
277{{- else if eq .Values.loki.storage.type "azure" -}}
278{{- with .Values.loki.storage.azure }}
279azure:
280 account_name: {{ .accountName }}
281 {{- with .accountKey }}
282 account_key: {{ . }}
283 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300284 {{- with .connectionString }}
285 connection_string: {{ . }}
286 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000287 container_name: {{ $.Values.loki.storage.bucketNames.chunks }}
288 use_managed_identity: {{ .useManagedIdentity }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300289 use_federated_token: {{ .useFederatedToken }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000290 {{- with .userAssignedId }}
291 user_assigned_id: {{ . }}
292 {{- end }}
293 {{- with .requestTimeout }}
294 request_timeout: {{ . }}
295 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300296 {{- with .endpointSuffix }}
297 endpoint_suffix: {{ . }}
298 {{- end }}
299{{- end -}}
300{{- else if eq .Values.loki.storage.type "swift" -}}
301{{- with .Values.loki.storage.swift }}
302swift:
303 {{- with .auth_version }}
304 auth_version: {{ . }}
305 {{- end }}
306 auth_url: {{ .auth_url }}
307 {{- with .internal }}
308 internal: {{ . }}
309 {{- end }}
310 username: {{ .username }}
311 user_domain_name: {{ .user_domain_name }}
312 {{- with .user_domain_id }}
313 user_domain_id: {{ . }}
314 {{- end }}
315 {{- with .user_id }}
316 user_id: {{ . }}
317 {{- end }}
318 password: {{ .password }}
319 {{- with .domain_id }}
320 domain_id: {{ . }}
321 {{- end }}
322 domain_name: {{ .domain_name }}
323 project_id: {{ .project_id }}
324 project_name: {{ .project_name }}
325 project_domain_id: {{ .project_domain_id }}
326 project_domain_name: {{ .project_domain_name }}
327 region_name: {{ .region_name }}
328 container_name: {{ .container_name }}
329 max_retries: {{ .max_retries | default 3 }}
330 connect_timeout: {{ .connect_timeout | default "10s" }}
331 request_timeout: {{ .request_timeout | default "5s" }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000332{{- end -}}
333{{- else -}}
334{{- with .Values.loki.storage.filesystem }}
335filesystem:
336 chunks_directory: {{ .chunks_directory }}
337 rules_directory: {{ .rules_directory }}
338{{- end -}}
339{{- end -}}
340{{- end -}}
341
342{{/*
343Storage config for ruler
344*/}}
345{{- define "loki.rulerStorageConfig" -}}
346{{- if .Values.minio.enabled -}}
347type: "s3"
348s3:
Mohammed Naser65cda132024-05-02 14:34:08 -0400349 bucketnames: ruler
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000350{{- else if eq .Values.loki.storage.type "s3" -}}
351{{- with .Values.loki.storage.s3 }}
352type: "s3"
353s3:
354 {{- with .s3 }}
355 s3: {{ . }}
356 {{- end }}
357 {{- with .endpoint }}
358 endpoint: {{ . }}
359 {{- end }}
360 {{- with .region }}
361 region: {{ . }}
362 {{- end}}
363 bucketnames: {{ $.Values.loki.storage.bucketNames.ruler }}
364 {{- with .secretAccessKey }}
365 secret_access_key: {{ . }}
366 {{- end }}
367 {{- with .accessKeyId }}
368 access_key_id: {{ . }}
369 {{- end }}
370 s3forcepathstyle: {{ .s3ForcePathStyle }}
371 insecure: {{ .insecure }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300372 {{- with .http_config }}
373 http_config: {{ toYaml . | nindent 6 }}
374 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000375{{- end -}}
376{{- else if eq .Values.loki.storage.type "gcs" -}}
377{{- with .Values.loki.storage.gcs }}
378type: "gcs"
379gcs:
380 bucket_name: {{ $.Values.loki.storage.bucketNames.ruler }}
381 chunk_buffer_size: {{ .chunkBufferSize }}
382 request_timeout: {{ .requestTimeout }}
383 enable_http2: {{ .enableHttp2 }}
384{{- end -}}
385{{- else if eq .Values.loki.storage.type "azure" -}}
386{{- with .Values.loki.storage.azure }}
387type: "azure"
388azure:
389 account_name: {{ .accountName }}
390 {{- with .accountKey }}
391 account_key: {{ . }}
392 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300393 {{- with .connectionString }}
394 connection_string: {{ . }}
395 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000396 container_name: {{ $.Values.loki.storage.bucketNames.ruler }}
397 use_managed_identity: {{ .useManagedIdentity }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300398 use_federated_token: {{ .useFederatedToken }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000399 {{- with .userAssignedId }}
400 user_assigned_id: {{ . }}
401 {{- end }}
402 {{- with .requestTimeout }}
403 request_timeout: {{ . }}
404 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300405 {{- with .endpointSuffix }}
406 endpoint_suffix: {{ . }}
407 {{- end }}
408{{- end -}}
409{{- else if eq .Values.loki.storage.type "swift" -}}
410{{- with .Values.loki.storage.swift }}
411swift:
412 {{- with .auth_version }}
413 auth_version: {{ . }}
414 {{- end }}
415 auth_url: {{ .auth_url }}
416 {{- with .internal }}
417 internal: {{ . }}
418 {{- end }}
419 username: {{ .username }}
420 user_domain_name: {{ .user_domain_name }}
421 {{- with .user_domain_id }}
422 user_domain_id: {{ . }}
423 {{- end }}
424 {{- with .user_id }}
425 user_id: {{ . }}
426 {{- end }}
427 password: {{ .password }}
428 {{- with .domain_id }}
429 domain_id: {{ . }}
430 {{- end }}
431 domain_name: {{ .domain_name }}
432 project_id: {{ .project_id }}
433 project_name: {{ .project_name }}
434 project_domain_id: {{ .project_domain_id }}
435 project_domain_name: {{ .project_domain_name }}
436 region_name: {{ .region_name }}
437 container_name: {{ .container_name }}
438 max_retries: {{ .max_retries | default 3 }}
439 connect_timeout: {{ .connect_timeout | default "10s" }}
440 request_timeout: {{ .request_timeout | default "5s" }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000441{{- end -}}
442{{- else }}
443type: "local"
444{{- end -}}
445{{- end -}}
446
447{{/* Loki ruler config */}}
448{{- define "loki.rulerConfig" }}
449ruler:
450 storage:
451 {{- include "loki.rulerStorageConfig" . | nindent 4}}
452{{- if (not (empty .Values.loki.rulerConfig)) }}
453{{- toYaml .Values.loki.rulerConfig | nindent 2}}
454{{- end }}
455{{- end }}
456
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400457{{/* Enterprise Logs Admin API storage config */}}
458{{- define "enterprise-logs.adminAPIStorageConfig" }}
459storage:
460 {{- if .Values.minio.enabled }}
461 backend: "s3"
462 s3:
463 bucket_name: admin
464 {{- else if eq .Values.loki.storage.type "s3" -}}
465 {{- with .Values.loki.storage.s3 }}
466 backend: "s3"
467 s3:
468 bucket_name: {{ $.Values.loki.storage.bucketNames.admin }}
469 {{- end -}}
470 {{- else if eq .Values.loki.storage.type "gcs" -}}
471 {{- with .Values.loki.storage.gcs }}
472 backend: "gcs"
473 gcs:
474 bucket_name: {{ $.Values.loki.storage.bucketNames.admin }}
475 {{- end -}}
476 {{- else if eq .Values.loki.storage.type "azure" -}}
477 {{- with .Values.loki.storage.azure }}
478 backend: "azure"
479 azure:
480 account_name: {{ .accountName }}
481 {{- with .accountKey }}
482 account_key: {{ . }}
483 {{- end }}
484 {{- with .connectionString }}
485 connection_string: {{ . }}
486 {{- end }}
487 container_name: {{ $.Values.loki.storage.bucketNames.admin }}
488 {{- with .endpointSuffix }}
489 endpoint_suffix: {{ . }}
490 {{- end }}
491 {{- end -}}
492 {{- else if eq .Values.loki.storage.type "swift" -}}
493 {{- with .Values.loki.storage.swift }}
494 backend: "swift"
495 swift:
496 {{- with .auth_version }}
497 auth_version: {{ . }}
498 {{- end }}
499 auth_url: {{ .auth_url }}
500 {{- with .internal }}
501 internal: {{ . }}
502 {{- end }}
503 username: {{ .username }}
504 user_domain_name: {{ .user_domain_name }}
505 {{- with .user_domain_id }}
506 user_domain_id: {{ . }}
507 {{- end }}
508 {{- with .user_id }}
509 user_id: {{ . }}
510 {{- end }}
511 password: {{ .password }}
512 {{- with .domain_id }}
513 domain_id: {{ . }}
514 {{- end }}
515 domain_name: {{ .domain_name }}
516 project_id: {{ .project_id }}
517 project_name: {{ .project_name }}
518 project_domain_id: {{ .project_domain_id }}
519 project_domain_name: {{ .project_domain_name }}
520 region_name: {{ .region_name }}
521 container_name: {{ .container_name }}
522 max_retries: {{ .max_retries | default 3 }}
523 connect_timeout: {{ .connect_timeout | default "10s" }}
524 request_timeout: {{ .request_timeout | default "5s" }}
525 {{- end -}}
526 {{- else }}
527 backend: "filesystem"
528 filesystem:
529 dir: {{ .Values.loki.storage.filesystem.admin_api_directory }}
530 {{- end -}}
531{{- end }}
532
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000533{{/*
Mohammed Naser65cda132024-05-02 14:34:08 -0400534Calculate the config from structured and unstructured text input
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300535*/}}
536{{- define "loki.calculatedConfig" -}}
537{{ tpl (mergeOverwrite (tpl .Values.loki.config . | fromYaml) .Values.loki.structuredConfig | toYaml) . }}
538{{- end }}
539
540{{/*
541The volume to mount for loki configuration
542*/}}
543{{- define "loki.configVolume" -}}
544{{- if eq .Values.loki.configStorageType "Secret" -}}
545secret:
Mohammed Naser65cda132024-05-02 14:34:08 -0400546 secretName: {{ tpl .Values.loki.configObjectName . }}
547{{- else -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300548configMap:
Mohammed Naser65cda132024-05-02 14:34:08 -0400549 name: {{ tpl .Values.loki.configObjectName . }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300550 items:
551 - key: "config.yaml"
552 path: "config.yaml"
553{{- end -}}
554{{- end -}}
555
556{{/*
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000557Memcached Docker image
558*/}}
559{{- define "loki.memcachedImage" -}}
560{{- $dict := dict "service" .Values.memcached.image "global" .Values.global.image -}}
561{{- include "loki.image" $dict -}}
562{{- end }}
563
564{{/*
565Memcached Exporter Docker image
566*/}}
567{{- define "loki.memcachedExporterImage" -}}
568{{- $dict := dict "service" .Values.memcachedExporter.image "global" .Values.global.image -}}
569{{- include "loki.image" $dict -}}
570{{- end }}
571
572{{/*
573Return the appropriate apiVersion for ingress.
574*/}}
575{{- define "loki.ingress.apiVersion" -}}
576 {{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) -}}
577 {{- print "networking.k8s.io/v1" -}}
578 {{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}}
579 {{- print "networking.k8s.io/v1beta1" -}}
580 {{- else -}}
581 {{- print "extensions/v1beta1" -}}
582 {{- end -}}
583{{- end -}}
584
585{{/*
586Return if ingress is stable.
587*/}}
588{{- define "loki.ingress.isStable" -}}
589 {{- eq (include "loki.ingress.apiVersion" .) "networking.k8s.io/v1" -}}
590{{- end -}}
591
592{{/*
593Return if ingress supports ingressClassName.
594*/}}
595{{- define "loki.ingress.supportsIngressClassName" -}}
596 {{- or (eq (include "loki.ingress.isStable" .) "true") (and (eq (include "loki.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
597{{- end -}}
598
599{{/*
600Return if ingress supports pathType.
601*/}}
602{{- define "loki.ingress.supportsPathType" -}}
603 {{- or (eq (include "loki.ingress.isStable" .) "true") (and (eq (include "loki.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) -}}
604{{- end -}}
605
606{{/*
607Generate list of ingress service paths based on deployment type
608*/}}
609{{- define "loki.ingress.servicePaths" -}}
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400610{{- if (eq (include "loki.deployment.isSingleBinary" .) "true") -}}
611{{- include "loki.ingress.singleBinaryServicePaths" . }}
612{{- else if (eq (include "loki.deployment.isDistributed" .) "true") -}}
613{{- include "loki.ingress.distributedServicePaths" . }}
614{{- else if and (eq (include "loki.deployment.isScalable" .) "true") (not .Values.read.legacyReadTarget ) -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000615{{- include "loki.ingress.scalableServicePaths" . }}
616{{- else -}}
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400617{{- include "loki.ingress.legacyScalableServicePaths" . }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000618{{- end -}}
619{{- end -}}
620
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400621
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000622{{/*
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400623Ingress service paths for distributed deployment
624*/}}
625{{- define "loki.ingress.distributedServicePaths" -}}
626{{- $distributorServiceName := include "loki.distributorFullname" . }}
627{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $distributorServiceName "paths" .Values.ingress.paths.distributor )}}
628{{- $queryFrontendServiceName := include "loki.queryFrontendFullname" . }}
629{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $queryFrontendServiceName "paths" .Values.ingress.paths.queryFrontend )}}
630{{- $rulerServiceName := include "loki.rulerFullname" . }}
631{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $rulerServiceName "paths" .Values.ingress.paths.ruler)}}
632{{- end -}}
633
634{{/*
635Ingress service paths for legacy simple scalable deployment when backend components were part of read component.
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000636*/}}
637{{- define "loki.ingress.scalableServicePaths" -}}
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400638{{- $readServiceName := include "loki.readFullname" . }}
639{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $readServiceName "paths" .Values.ingress.paths.queryFrontend )}}
640{{- $writeServiceName := include "loki.writeFullname" . }}
641{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $writeServiceName "paths" .Values.ingress.paths.distributor )}}
642{{- $backendServiceName := include "loki.backendFullname" . }}
643{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $backendServiceName "paths" .Values.ingress.paths.ruler )}}
644{{- end -}}
645
646{{/*
647Ingress service paths for legacy simple scalable deployment
648*/}}
649{{- define "loki.ingress.legacyScalableServicePaths" -}}
650{{- $readServiceName := include "loki.readFullname" . }}
651{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $readServiceName "paths" .Values.ingress.paths.queryFrontend )}}
652{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $readServiceName "paths" .Values.ingress.paths.ruler )}}
653{{- $writeServiceName := include "loki.writeFullname" . }}
654{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $writeServiceName "paths" .Values.ingress.paths.distributor )}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000655{{- end -}}
656
657{{/*
658Ingress service paths for single binary deployment
659*/}}
660{{- define "loki.ingress.singleBinaryServicePaths" -}}
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400661{{- $serviceName := include "loki.singleBinaryFullname" . }}
662{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $serviceName "paths" .Values.ingress.paths.distributor )}}
663{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $serviceName "paths" .Values.ingress.paths.queryFrontend )}}
664{{- include "loki.ingress.servicePath" (dict "ctx" . "serviceName" $serviceName "paths" .Values.ingress.paths.ruler )}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000665{{- end -}}
666
667{{/*
668Ingress service path helper function
669Params:
670 ctx = . context
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400671 serviceName = fully qualified k8s service name
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000672 paths = list of url paths to allow ingress for
673*/}}
674{{- define "loki.ingress.servicePath" -}}
675{{- $ingressApiIsStable := eq (include "loki.ingress.isStable" .ctx) "true" -}}
676{{- $ingressSupportsPathType := eq (include "loki.ingress.supportsPathType" .ctx) "true" -}}
677{{- range .paths }}
678- path: {{ . }}
679 {{- if $ingressSupportsPathType }}
680 pathType: Prefix
681 {{- end }}
682 backend:
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300683 {{- if $ingressApiIsStable }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000684 service:
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400685 name: {{ $.serviceName }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000686 port:
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300687 number: {{ $.ctx.Values.loki.server.http_listen_port }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000688 {{- else }}
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400689 serviceName: {{ $.serviceName }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300690 servicePort: {{ $.ctx.Values.loki.server.http_listen_port }}
691 {{- end -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000692{{- end -}}
693{{- end -}}
694
695{{/*
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000696Create the service endpoint including port for MinIO.
697*/}}
698{{- define "loki.minio" -}}
699{{- if .Values.minio.enabled -}}
Mohammed Naser65cda132024-05-02 14:34:08 -0400700{{- .Values.minio.address | default (printf "%s-%s.%s.svc:%s" .Release.Name "minio" .Release.Namespace (.Values.minio.service.port | toString)) -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000701{{- end -}}
702{{- end -}}
703
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000704{{/* Determine if deployment is using object storage */}}
705{{- define "loki.isUsingObjectStorage" -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300706{{- 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") -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000707{{- end -}}
708
709{{/* Configure the correct name for the memberlist service */}}
710{{- define "loki.memberlist" -}}
711{{ include "loki.name" . }}-memberlist
712{{- end -}}
713
714{{/* Determine the public host for the Loki cluster */}}
715{{- define "loki.host" -}}
716{{- $isSingleBinary := eq (include "loki.deployment.isSingleBinary" .) "true" -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300717{{- $url := printf "%s.%s.svc.%s.:%s" (include "loki.gatewayFullname" .) .Release.Namespace .Values.global.clusterDomain (.Values.gateway.service.port | toString) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000718{{- if and $isSingleBinary (not .Values.gateway.enabled) }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300719 {{- $url = printf "%s.%s.svc.%s.:%s" (include "loki.singleBinaryFullname" .) .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000720{{- end }}
721{{- printf "%s" $url -}}
722{{- end -}}
723
724{{/* Determine the public endpoint for the Loki cluster */}}
725{{- define "loki.address" -}}
726{{- printf "http://%s" (include "loki.host" . ) -}}
727{{- end -}}
728
729{{/* Name of the cluster */}}
730{{- define "loki.clusterName" -}}
731{{- $name := .Values.enterprise.cluster_name | default .Release.Name }}
732{{- printf "%s" $name -}}
733{{- end -}}
734
735{{/* Name of kubernetes secret to persist GEL admin token to */}}
736{{- define "enterprise-logs.adminTokenSecret" }}
737{{- .Values.enterprise.adminToken.secret | default (printf "%s-admin-token" (include "loki.name" . )) -}}
738{{- end -}}
739
740{{/* Prefix for provisioned secrets created for each provisioned tenant */}}
741{{- define "enterprise-logs.provisionedSecretPrefix" }}
742{{- .Values.enterprise.provisioner.provisionedSecretPrefix | default (printf "%s-provisioned" (include "loki.name" . )) -}}
743{{- end -}}
744
745{{/* Name of kubernetes secret to persist canary credentials in */}}
746{{- define "enterprise-logs.selfMonitoringTenantSecret" }}
747{{- .Values.enterprise.canarySecret | default (printf "%s-%s" (include "enterprise-logs.provisionedSecretPrefix" . ) .Values.monitoring.selfMonitoring.tenant.name) -}}
748{{- end -}}
749
750{{/* Snippet for the nginx file used by gateway */}}
751{{- define "loki.nginxFile" }}
752worker_processes 5; ## Default: 1
753error_log /dev/stderr;
754pid /tmp/nginx.pid;
755worker_rlimit_nofile 8192;
756
757events {
758 worker_connections 4096; ## Default: 1024
759}
760
761http {
762 client_body_temp_path /tmp/client_temp;
763 proxy_temp_path /tmp/proxy_temp_path;
764 fastcgi_temp_path /tmp/fastcgi_temp;
765 uwsgi_temp_path /tmp/uwsgi_temp;
766 scgi_temp_path /tmp/scgi_temp;
767
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300768 client_max_body_size 4M;
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000769
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300770 proxy_read_timeout 600; ## 10 minutes
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000771 proxy_send_timeout 600;
772 proxy_connect_timeout 600;
773
774 proxy_http_version 1.1;
775
776 default_type application/octet-stream;
777 log_format {{ .Values.gateway.nginxConfig.logFormat }}
778
779 {{- if .Values.gateway.verboseLogging }}
780 access_log /dev/stderr main;
781 {{- else }}
782
783 map $status $loggable {
784 ~^[23] 0;
785 default 1;
786 }
787 access_log /dev/stderr main if=$loggable;
788 {{- end }}
789
790 sendfile on;
791 tcp_nopush on;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300792 {{- if .Values.gateway.nginxConfig.resolver }}
793 resolver {{ .Values.gateway.nginxConfig.resolver }};
794 {{- else }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000795 resolver {{ .Values.global.dnsService }}.{{ .Values.global.dnsNamespace }}.svc.{{ .Values.global.clusterDomain }}.;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300796 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000797
798 {{- with .Values.gateway.nginxConfig.httpSnippet }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300799 {{- tpl . $ | nindent 2 }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000800 {{- end }}
801
802 server {
Mohammed Naser65cda132024-05-02 14:34:08 -0400803 {{- if (.Values.gateway.nginxConfig.ssl) }}
804 listen 8080 ssl;
805 {{- if .Values.gateway.nginxConfig.enableIPv6 }}
806 listen [::]:8080 ssl;
807 {{- end }}
808 {{- else }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000809 listen 8080;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300810 {{- if .Values.gateway.nginxConfig.enableIPv6 }}
811 listen [::]:8080;
812 {{- end }}
Mohammed Naser65cda132024-05-02 14:34:08 -0400813 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000814
815 {{- if .Values.gateway.basicAuth.enabled }}
816 auth_basic "Loki";
817 auth_basic_user_file /etc/nginx/secrets/.htpasswd;
818 {{- end }}
819
820 location = / {
821 return 200 'OK';
822 auth_basic off;
823 }
824
Mohammed Naser65cda132024-05-02 14:34:08 -0400825 ########################################################
826 # Configure backend targets
827
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000828 {{- $backendHost := include "loki.backendFullname" .}}
829 {{- $readHost := include "loki.readFullname" .}}
830 {{- $writeHost := include "loki.writeFullname" .}}
831
832 {{- if .Values.read.legacyReadTarget }}
833 {{- $backendHost = include "loki.readFullname" . }}
834 {{- end }}
835
Mohammed Naser65cda132024-05-02 14:34:08 -0400836 {{- $httpSchema := .Values.gateway.nginxConfig.schema }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000837
Mohammed Naser65cda132024-05-02 14:34:08 -0400838 {{- $writeUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $writeHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
839 {{- $readUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $readHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
840 {{- $backendUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $backendHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000841
842 {{- if .Values.gateway.nginxConfig.customWriteUrl }}
843 {{- $writeUrl = .Values.gateway.nginxConfig.customWriteUrl }}
844 {{- end }}
845 {{- if .Values.gateway.nginxConfig.customReadUrl }}
846 {{- $readUrl = .Values.gateway.nginxConfig.customReadUrl }}
847 {{- end }}
848 {{- if .Values.gateway.nginxConfig.customBackendUrl }}
849 {{- $backendUrl = .Values.gateway.nginxConfig.customBackendUrl }}
850 {{- end }}
851
Mohammed Naser65cda132024-05-02 14:34:08 -0400852 {{- $singleBinaryHost := include "loki.singleBinaryFullname" . }}
853 {{- $singleBinaryUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $singleBinaryHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
854
855 {{- $distributorHost := include "loki.distributorFullname" .}}
856 {{- $ingesterHost := include "loki.ingesterFullname" .}}
857 {{- $queryFrontendHost := include "loki.queryFrontendFullname" .}}
858 {{- $indexGatewayHost := include "loki.indexGatewayFullname" .}}
859 {{- $rulerHost := include "loki.rulerFullname" .}}
860 {{- $compactorHost := include "loki.compactorFullname" .}}
861 {{- $schedulerHost := include "loki.querySchedulerFullname" .}}
862
863
864 {{- $distributorUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $distributorHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) -}}
865 {{- $ingesterUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $ingesterHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
866 {{- $queryFrontendUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $queryFrontendHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
867 {{- $indexGatewayUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $indexGatewayHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
868 {{- $rulerUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $rulerHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
869 {{- $compactorUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $compactorHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
870 {{- $schedulerUrl := printf "%s://%s.%s.svc.%s:%s" $httpSchema $schedulerHost .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.http_listen_port | toString) }}
871
872 {{- if eq (include "loki.deployment.isSingleBinary" .) "true"}}
873 {{- $distributorUrl = $singleBinaryUrl }}
874 {{- $ingesterUrl = $singleBinaryUrl }}
875 {{- $queryFrontendUrl = $singleBinaryUrl }}
876 {{- $indexGatewayUrl = $singleBinaryUrl }}
877 {{- $rulerUrl = $singleBinaryUrl }}
878 {{- $compactorUrl = $singleBinaryUrl }}
879 {{- $schedulerUrl = $singleBinaryUrl }}
880 {{- else if eq (include "loki.deployment.isScalable" .) "true"}}
881 {{- $distributorUrl = $writeUrl }}
882 {{- $ingesterUrl = $writeUrl }}
883 {{- $queryFrontendUrl = $readUrl }}
884 {{- $indexGatewayUrl = $backendUrl }}
885 {{- $rulerUrl = $backendUrl }}
886 {{- $compactorUrl = $backendUrl }}
887 {{- $schedulerUrl = $backendUrl }}
888 {{- end -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300889
890 # Distributor
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000891 location = /api/prom/push {
Mohammed Naser65cda132024-05-02 14:34:08 -0400892 proxy_pass {{ $distributorUrl }}$request_uri;
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000893 }
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300894 location = /loki/api/v1/push {
Mohammed Naser65cda132024-05-02 14:34:08 -0400895 proxy_pass {{ $distributorUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300896 }
897 location = /distributor/ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400898 proxy_pass {{ $distributorUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300899 }
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400900 location = /otlp/v1/logs {
901 proxy_pass {{ $distributorUrl }}$request_uri;
902 }
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000903
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300904 # Ingester
905 location = /flush {
Mohammed Naser65cda132024-05-02 14:34:08 -0400906 proxy_pass {{ $ingesterUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300907 }
908 location ^~ /ingester/ {
Mohammed Naser65cda132024-05-02 14:34:08 -0400909 proxy_pass {{ $ingesterUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300910 }
911 location = /ingester {
912 internal; # to suppress 301
913 }
914
915 # Ring
916 location = /ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400917 proxy_pass {{ $ingesterUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300918 }
919
920 # MemberListKV
921 location = /memberlist {
Mohammed Naser65cda132024-05-02 14:34:08 -0400922 proxy_pass {{ $ingesterUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300923 }
924
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300925 # Ruler
926 location = /ruler/ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400927 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300928 }
929 location = /api/prom/rules {
Mohammed Naser65cda132024-05-02 14:34:08 -0400930 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300931 }
932 location ^~ /api/prom/rules/ {
Mohammed Naser65cda132024-05-02 14:34:08 -0400933 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300934 }
935 location = /loki/api/v1/rules {
Mohammed Naser65cda132024-05-02 14:34:08 -0400936 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300937 }
938 location ^~ /loki/api/v1/rules/ {
Mohammed Naser65cda132024-05-02 14:34:08 -0400939 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300940 }
941 location = /prometheus/api/v1/alerts {
Mohammed Naser65cda132024-05-02 14:34:08 -0400942 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300943 }
944 location = /prometheus/api/v1/rules {
Mohammed Naser65cda132024-05-02 14:34:08 -0400945 proxy_pass {{ $rulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300946 }
947
948 # Compactor
949 location = /compactor/ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400950 proxy_pass {{ $compactorUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300951 }
952 location = /loki/api/v1/delete {
Mohammed Naser65cda132024-05-02 14:34:08 -0400953 proxy_pass {{ $compactorUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300954 }
955 location = /loki/api/v1/cache/generation_numbers {
Mohammed Naser65cda132024-05-02 14:34:08 -0400956 proxy_pass {{ $compactorUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300957 }
958
959 # IndexGateway
960 location = /indexgateway/ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400961 proxy_pass {{ $indexGatewayUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300962 }
963
964 # QueryScheduler
965 location = /scheduler/ring {
Mohammed Naser65cda132024-05-02 14:34:08 -0400966 proxy_pass {{ $schedulerUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300967 }
968
969 # Config
970 location = /config {
Mohammed Naser65cda132024-05-02 14:34:08 -0400971 proxy_pass {{ $ingesterUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300972 }
973
974 {{- if and .Values.enterprise.enabled .Values.enterprise.adminApi.enabled }}
975 # Admin API
976 location ^~ /admin/api/ {
977 proxy_pass {{ $backendUrl }}$request_uri;
978 }
979 location = /admin/api {
980 internal; # to suppress 301
981 }
982 {{- end }}
983
984
985 # QueryFrontend, Querier
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000986 location = /api/prom/tail {
Mohammed Naser65cda132024-05-02 14:34:08 -0400987 proxy_pass {{ $queryFrontendUrl }}$request_uri;
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000988 proxy_set_header Upgrade $http_upgrade;
989 proxy_set_header Connection "upgrade";
990 }
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000991 location = /loki/api/v1/tail {
Mohammed Naser65cda132024-05-02 14:34:08 -0400992 proxy_pass {{ $queryFrontendUrl }}$request_uri;
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000993 proxy_set_header Upgrade $http_upgrade;
994 proxy_set_header Connection "upgrade";
995 }
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300996 location ^~ /api/prom/ {
Mohammed Naser65cda132024-05-02 14:34:08 -0400997 proxy_pass {{ $queryFrontendUrl }}$request_uri;
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000998 }
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300999 location = /api/prom {
1000 internal; # to suppress 301
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00001001 }
Giovanni Tirloni59219b62024-04-09 14:50:25 -03001002 location ^~ /loki/api/v1/ {
Mohammed Naser65cda132024-05-02 14:34:08 -04001003 proxy_pass {{ $queryFrontendUrl }}$request_uri;
Giovanni Tirloni59219b62024-04-09 14:50:25 -03001004 }
1005 location = /loki/api/v1 {
1006 internal; # to suppress 301
1007 }
1008
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00001009 {{- with .Values.gateway.nginxConfig.serverSnippet }}
1010 {{ . | nindent 4 }}
1011 {{- end }}
1012 }
1013}
1014{{- end }}
1015
1016{{/* Configure enableServiceLinks in pod */}}
1017{{- define "loki.enableServiceLinks" -}}
1018{{- if semverCompare ">=1.13-0" .Capabilities.KubeVersion.Version -}}
1019{{- if or (.Values.loki.enableServiceLinks) (ne .Values.loki.enableServiceLinks false) -}}
1020enableServiceLinks: true
1021{{- else -}}
1022enableServiceLinks: false
1023{{- end -}}
1024{{- end -}}
1025{{- end -}}
1026
1027{{/* Determine compactor address based on target configuration */}}
1028{{- define "loki.compactorAddress" -}}
1029{{- $isSimpleScalable := eq (include "loki.deployment.isScalable" .) "true" -}}
Mohammed Naser7d1623e2024-06-17 09:12:39 -04001030{{- $isDistributed := eq (include "loki.deployment.isDistributed" .) "true" -}}
1031{{- $isSingleBinary := eq (include "loki.deployment.isSingleBinary" .) "true" -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00001032{{- $compactorAddress := include "loki.backendFullname" . -}}
1033{{- if and $isSimpleScalable .Values.read.legacyReadTarget -}}
1034{{/* 2 target configuration */}}
1035{{- $compactorAddress = include "loki.readFullname" . -}}
Mohammed Naser7d1623e2024-06-17 09:12:39 -04001036{{- else if $isSingleBinary -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00001037{{/* single binary */}}
1038{{- $compactorAddress = include "loki.singleBinaryFullname" . -}}
Mohammed Naser7d1623e2024-06-17 09:12:39 -04001039{{/* distributed */}}
1040{{- else if $isDistributed -}}
1041{{- $compactorAddress = include "loki.compactorFullname" . -}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00001042{{- end -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -03001043{{- printf "http://%s:%s" $compactorAddress (.Values.loki.server.http_listen_port | toString) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00001044{{- end }}
1045
Giovanni Tirloni59219b62024-04-09 14:50:25 -03001046{{/* Determine query-scheduler address */}}
1047{{- define "loki.querySchedulerAddress" -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -03001048{{- $schedulerAddress := ""}}
Mohammed Naser65cda132024-05-02 14:34:08 -04001049{{- $isDistributed := eq (include "loki.deployment.isDistributed" .) "true" -}}
1050{{- if $isDistributed -}}
1051{{- $schedulerAddress = printf "%s.%s.svc.%s:%s" (include "loki.querySchedulerFullname" .) .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.grpc_listen_port | toString) -}}
Giovanni Tirloni59219b62024-04-09 14:50:25 -03001052{{- end -}}
1053{{- printf "%s" $schedulerAddress }}
1054{{- end }}
Mohammed Naser65cda132024-05-02 14:34:08 -04001055
1056{{/* Determine querier address */}}
1057{{- define "loki.querierAddress" -}}
1058{{- $querierAddress := "" }}
1059{{- if "loki.deployment.isDistributed "}}
1060{{- $querierHost := include "loki.querierFullname" .}}
1061{{- $querierUrl := printf "http://%s.%s.svc.%s:3100" $querierHost .Release.Namespace .Values.global.clusterDomain }}
1062{{- $querierAddress = $querierUrl }}
1063{{- end -}}
1064{{- printf "%s" $querierAddress }}
1065{{- end }}
1066
1067{{/* Determine index-gateway address */}}
1068{{- define "loki.indexGatewayAddress" -}}
1069{{- $idxGatewayAddress := ""}}
1070{{- $isDistributed := eq (include "loki.deployment.isDistributed" .) "true" -}}
1071{{- $isScalable := eq (include "loki.deployment.isScalable" .) "true" -}}
1072{{- if $isDistributed -}}
1073{{- $idxGatewayAddress = printf "dns+%s-headless.%s.svc.%s:%s" (include "loki.indexGatewayFullname" .) .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.grpc_listen_port | toString) -}}
1074{{- end -}}
1075{{- if $isScalable -}}
1076{{- $idxGatewayAddress = printf "dns+%s-headless.%s.svc.%s:%s" (include "loki.backendFullname" .) .Release.Namespace .Values.global.clusterDomain (.Values.loki.server.grpc_listen_port | toString) -}}
1077{{- end -}}
1078{{- printf "%s" $idxGatewayAddress }}
1079{{- end }}
1080
1081{{- define "loki.config.checksum" -}}
1082checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }}
1083{{- end -}}
1084
1085{{/*
1086Return the appropriate apiVersion for PodDisruptionBudget.
1087*/}}
1088{{- define "loki.pdb.apiVersion" -}}
1089 {{- if and (.Capabilities.APIVersions.Has "policy/v1") (semverCompare ">=1.21-0" .Capabilities.KubeVersion.Version) -}}
1090 {{- print "policy/v1" -}}
1091 {{- else -}}
1092 {{- print "policy/v1beta1" -}}
1093 {{- end -}}
1094{{- end -}}
1095
1096{{/*
1097Return the object store type for use with the test schema.
1098*/}}
1099{{- define "loki.testSchemaObjectStore" -}}
1100 {{- if .Values.minio.enabled -}}
1101 s3
1102 {{- else -}}
1103 filesystem
1104 {{- end -}}
1105{{- end -}}
Mohammed Naser7d1623e2024-06-17 09:12:39 -04001106
1107{{/*
1108Return the appropriate apiVersion for HorizontalPodAutoscaler.
1109*/}}
1110{{- define "loki.hpa.apiVersion" -}}
1111 {{- if and (.Capabilities.APIVersions.Has "autoscaling/v2") (semverCompare ">= 1.19-0" .Capabilities.KubeVersion.Version) -}}
1112 {{- print "autoscaling/v2" -}}
1113 {{- else if .Capabilities.APIVersions.Has "autoscaling/v2beta2" -}}
1114 {{- print "autoscaling/v2beta2" -}}
1115 {{- else -}}
1116 {{- print "autoscaling/v2beta1" -}}
1117 {{- end -}}
1118{{- end -}}