From b512bfbd3238a8792a76ac3c01735d990b8b03dd Mon Sep 17 00:00:00 2001 From: Dylan Guedes Date: Mon, 5 Feb 2024 18:19:36 -0300 Subject: [PATCH] Helm: Add distributed URLs to nginx gateway (#11853) **What this PR does / why we need it**: Modify our nginx proxy pass to redirect to microservices components correctly. Modify index-gateway to run in simple mode by default. Fix distributor svc target port (http-metrics instead of `http`). **Which issue(s) this PR fixes**: N/A --- production/helm/loki/templates/_helpers.tpl | 75 +++++++++++++------ .../distributor/service-distributor.yaml | 2 +- .../templates/ruler/statefulset-ruler.yaml | 2 - production/helm/loki/values.yaml | 5 +- 4 files changed, 57 insertions(+), 27 deletions(-) diff --git a/production/helm/loki/templates/_helpers.tpl b/production/helm/loki/templates/_helpers.tpl index d5ddb039902a2..10afc527c903d 100644 --- a/production/helm/loki/templates/_helpers.tpl +++ b/production/helm/loki/templates/_helpers.tpl @@ -719,6 +719,8 @@ http { auth_basic off; } + ######################################################## + # simple-scalable mode hosts and urls definitions. {{- $backendHost := include "loki.backendFullname" .}} {{- $readHost := include "loki.readFullname" .}} {{- $writeHost := include "loki.writeFullname" .}} @@ -747,24 +749,45 @@ http { {{- $backendUrl = .Values.gateway.nginxConfig.customBackendUrl }} {{- end }} + ######################################################### + # distributed mode hosts and urls definitions. + {{- $distributorHost := include "loki.distributorFullname" .}} + {{- $ingesterHost := include "loki.ingesterFullname" .}} + {{- $queryFrontendHost := include "loki.queryFrontendFullname" .}} + {{- $indexGatewayHost := include "loki.indexGatewayFullname" .}} + {{- $rulerHost := include "loki.rulerFullname" .}} + + {{- $distributorUrl := printf "http://%s.%s.svc.%s:3100" $distributorHost .Release.Namespace .Values.global.clusterDomain -}} + {{- $ingesterUrl := printf "http://%s.%s.svc.%s:3100" $ingesterHost .Release.Namespace .Values.global.clusterDomain }} + {{- $queryFrontendUrl := printf "http://%s.%s.svc.%s:3100" $queryFrontendHost .Release.Namespace .Values.global.clusterDomain }} + {{- $indexGatewayUrl := printf "http://%s.%s.svc.%s:3100" $indexGatewayHost .Release.Namespace .Values.global.clusterDomain }} + {{- $rulerUrl := printf "http://%s.%s.svc.%s:3100" $rulerHost .Release.Namespace .Values.global.clusterDomain }} + + {{- if not "loki.deployment.isDistributed "}} + {{- $distributorUrl = $writeUrl }} + {{- $ingesterUrl = $writeUrl }} + {{- $queryFrontendUrl = $readUrl }} + {{- $indexGatewayUrl = $backendUrl }} + {{- $rulerUrl = $backendUrl }} + {{- end -}}-}} # Distributor location = /api/prom/push { - proxy_pass {{ $writeUrl }}$request_uri; + proxy_pass {{ $distributorUrl }}$request_uri; } location = /loki/api/v1/push { - proxy_pass {{ $writeUrl }}$request_uri; + proxy_pass {{ $distributorUrl }}$request_uri; } location = /distributor/ring { - proxy_pass {{ $writeUrl }}$request_uri; + proxy_pass {{ $distributorUrl }}$request_uri; } # Ingester location = /flush { - proxy_pass {{ $writeUrl }}$request_uri; + proxy_pass {{ $ingesterUrl }}$request_uri; } location ^~ /ingester/ { - proxy_pass {{ $writeUrl }}$request_uri; + proxy_pass {{ $ingesterUrl }}$request_uri; } location = /ingester { internal; # to suppress 301 @@ -772,36 +795,35 @@ http { # Ring location = /ring { - proxy_pass {{ $writeUrl }}$request_uri; + proxy_pass {{ $ingesterUrl }}$request_uri; } # MemberListKV location = /memberlist { - proxy_pass {{ $writeUrl }}$request_uri; + proxy_pass {{ $ingesterUrl }}$request_uri; } - # Ruler location = /ruler/ring { - proxy_pass {{ $backendUrl }}$request_uri; + proxy_pass {{ $rulerUrl }}$request_uri; } location = /api/prom/rules { - proxy_pass {{ $backendUrl }}$request_uri; + proxy_pass {{ $rulerUrl }}$request_uri; } location ^~ /api/prom/rules/ { - proxy_pass {{ $backendUrl }}$request_uri; + proxy_pass {{ $rulerUrl }}$request_uri; } location = /loki/api/v1/rules { - proxy_pass {{ $backendUrl }}$request_uri; + proxy_pass {{ $rulerUrl }}$request_uri; } location ^~ /loki/api/v1/rules/ { - proxy_pass {{ $backendUrl }}$request_uri; + proxy_pass {{ $rulerUrl }}$request_uri; } location = /prometheus/api/v1/alerts { - proxy_pass {{ $backendUrl }}$request_uri; + proxy_pass {{ $rulerUrl }}$request_uri; } location = /prometheus/api/v1/rules { - proxy_pass {{ $backendUrl }}$request_uri; + proxy_pass {{ $rulerUrl }}$request_uri; } # Compactor @@ -817,7 +839,7 @@ http { # IndexGateway location = /indexgateway/ring { - proxy_pass {{ $backendUrl }}$request_uri; + proxy_pass {{ $indexGatewayUrl }}$request_uri; } # QueryScheduler @@ -827,7 +849,7 @@ http { # Config location = /config { - proxy_pass {{ $backendUrl }}$request_uri; + proxy_pass {{ $ingesterUrl }}$request_uri; } {{- if and .Values.enterprise.enabled .Values.enterprise.adminApi.enabled }} @@ -843,29 +865,28 @@ http { # QueryFrontend, Querier location = /api/prom/tail { - proxy_pass {{ $readUrl }}$request_uri; + proxy_pass {{ $queryFrontendUrl }}$request_uri; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location = /loki/api/v1/tail { - proxy_pass {{ $readUrl }}$request_uri; + proxy_pass {{ $queryFrontendUrl }}$request_uri; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location ^~ /api/prom/ { - proxy_pass {{ $readUrl }}$request_uri; + proxy_pass {{ $queryFrontendUrl }}$request_uri; } location = /api/prom { internal; # to suppress 301 } location ^~ /loki/api/v1/ { - proxy_pass {{ $readUrl }}$request_uri; + proxy_pass {{ $queryFrontendUrl }}$request_uri; } location = /loki/api/v1 { internal; # to suppress 301 } - {{- with .Values.gateway.nginxConfig.serverSnippet }} {{ . | nindent 4 }} {{- end }} @@ -908,6 +929,16 @@ enableServiceLinks: false {{- printf "%s" $schedulerAddress }} {{- end }} +{{/* Determine querier address */}} +{{- define "loki.querierAddress" -}} +{{- $querierAddress := "" }} +{{- if "loki.deployment.isDistributed "}} +{{- $querierHost := include "loki.querierFullname" .}} +{{- $querierUrl := printf "http://%s.%s.svc.%s:3100" $querierHost .Release.Namespace .Values.global.clusterDomain }} +{{- $querierAddress = $querierUrl }} +{{- end -}} +{{- printf "%s" $querierAddress }} +{{- end }} {{- define "loki.config.checksum" -}} checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }} diff --git a/production/helm/loki/templates/distributor/service-distributor.yaml b/production/helm/loki/templates/distributor/service-distributor.yaml index be2705f15cba3..8145834d35097 100644 --- a/production/helm/loki/templates/distributor/service-distributor.yaml +++ b/production/helm/loki/templates/distributor/service-distributor.yaml @@ -19,7 +19,7 @@ spec: ports: - name: http-metrics port: 3100 - targetPort: http + targetPort: http-metrics protocol: TCP - name: grpc port: 9095 diff --git a/production/helm/loki/templates/ruler/statefulset-ruler.yaml b/production/helm/loki/templates/ruler/statefulset-ruler.yaml index 5bb752de52367..fcc98dbbb804b 100644 --- a/production/helm/loki/templates/ruler/statefulset-ruler.yaml +++ b/production/helm/loki/templates/ruler/statefulset-ruler.yaml @@ -87,8 +87,6 @@ spec: {{- toYaml .Values.loki.containerSecurityContext | nindent 12 }} readinessProbe: {{- toYaml .Values.loki.readinessProbe | nindent 12 }} - livenessProbe: - {{- toYaml .Values.loki.livenessProbe | nindent 12 }} volumeMounts: - name: config mountPath: /etc/loki/config diff --git a/production/helm/loki/values.yaml b/production/helm/loki/values.yaml index 3a012dc2d46fd..1d9892d274e9a 100644 --- a/production/helm/loki/values.yaml +++ b/production/helm/loki/values.yaml @@ -362,9 +362,10 @@ loki: ingester: {} # -- Optional index gateway configuration index_gateway: - mode: ring + mode: simple frontend: scheduler_address: '{{ include "loki.querySchedulerAddress" . }}' + tail_proxy_url: '{{ include "loki.querierAddress" . }}' frontend_worker: scheduler_address: '{{ include "loki.querySchedulerAddress" . }}' # -- Optional distributor configuration @@ -2337,7 +2338,7 @@ gateway: readinessProbe: httpGet: path: / - port: http + port: http-metrics initialDelaySeconds: 15 timeoutSeconds: 1 nginxConfig: