From 94ee0e92611964a140a93551de14595121865363 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 18 Oct 2024 14:03:50 +0500 Subject: [PATCH] [traffic-proxy] Update traffic-proxy chart configuration and nginx template (#518) * Update traffic-proxy chart configuration and nginx template * Add customizable server section * Update charts/traffic-proxy/templates/configmap.yaml Co-authored-by: Voronkov Alexander * Update charts/traffic-proxy/templates/configmap.yaml Co-authored-by: Voronkov Alexander * Change log configuration * Change README * lint fix * Delete duplicate field description in traffic-proxy * Fix configmap spaces. Add loglevel field allowed values --------- Co-authored-by: Sergey Vlasov Co-authored-by: Voronkov Alexander --- charts/traffic-proxy/README.md | 22 ++++++--- charts/traffic-proxy/templates/configmap.yaml | 31 +++++++++++-- charts/traffic-proxy/values.yaml | 46 +++++++++++++++++++ 3 files changed, 87 insertions(+), 12 deletions(-) diff --git a/charts/traffic-proxy/README.md b/charts/traffic-proxy/README.md index ed9df5966..f7b6f885d 100644 --- a/charts/traffic-proxy/README.md +++ b/charts/traffic-proxy/README.md @@ -44,13 +44,21 @@ See the [documentation](https://docs.2gis.com/en/on-premise/traffic-proxy) to le ### Proxy server settings -| Name | Description | Value | -| --------------------- | --------------------------------------------------------------------------------------- | ------ | -| `proxy.host` | URL for the proxy server to serve, ex: https://traffic0.edromaps.2gis.com. **Required** | `""` | -| `proxy.listen` | Port for the proxy server to listen. | `8080` | -| `proxy.cache.enabled` | If caching should be enabled for the proxy server. | `true` | -| `proxy.cache.age` | Cache validity period. | `1m` | -| `proxy.cache.size` | Maximum cache size. | `32m` | +| Name | Description | Value | +| -------------------------- | ------------------------------------------------------------------------------------------------------ | ------- | +| `proxy.host` | URL for the proxy server to serve, ex: https://traffic0.edromaps.2gis.com. **Required** | `""` | +| `proxy.listen` | Port for the proxy server to listen. | `8080` | +| `proxy.cache.enabled` | If caching should be enabled for the proxy server. | `true` | +| `proxy.cache.age` | Cache validity period. | `1m` | +| `proxy.cache.size` | Maximum cache size. | `32m` | +| `proxy.worker.processes` | Number of worker processes. | `2` | +| `proxy.worker.connections` | Number of worker connections. | `1024` | +| `proxy.log.errorLog.level` | Error log level. Allowed values: `debug`, `info`, `notice`, `warn`, `error`, `crit`, `alert`, `emerg`. | `error` | +| `proxy.log.accessLog` | Access log definition. | `off` | +| `proxy.keepaliveTimeout` | Keepalive timeout. | `65` | +| `proxy.log.customFormats` | List of custom log formats to be used in NGINX configuration | `[]` | +| `proxy.locations` | List of additional location blocks to be included in the NGINX configuration | `[]` | +| `proxy.httpServers` | List of additional server blocks to be included in the NGINX configuration | `{}` | ### Deployment settings diff --git a/charts/traffic-proxy/templates/configmap.yaml b/charts/traffic-proxy/templates/configmap.yaml index 75e1031d5..3532cb917 100644 --- a/charts/traffic-proxy/templates/configmap.yaml +++ b/charts/traffic-proxy/templates/configmap.yaml @@ -8,12 +8,12 @@ metadata: {{- include "traffic-proxy.labels" . | nindent 4 }} data: nginx.conf: | - worker_processes 2; + worker_processes {{ .Values.proxy.worker.processes }}; pid /run/nginx.pid; events { - worker_connections 1024; + worker_connections {{ .Values.proxy.worker.connections }}; } http { @@ -44,12 +44,19 @@ data: '"request_id":"$http_x_request_id",' '"upstream_request_id":"$upstream_http_x_request_id"}'; - access_log off; - error_log /dev/stderr error; + {{- if .Values.proxy.log.customFormats }} + {{ range .Values.proxy.log.customFormats }} + log_format {{ .name }} escape={{ .escape }} {{ .format | nindent 36 | trim }}; + {{- end }} + {{- end }} + + access_log {{ required "A valid .Values.proxy.log.accessLog required" .Values.proxy.log.accessLog }}; + + error_log /dev/stderr {{ required "A valid .Values.proxy.log.errorLog.level required" .Values.proxy.log.errorLog.level }}; sendfile on; tcp_nopush on; - keepalive_timeout 65; + keepalive_timeout {{ .Values.proxy.keepaliveTimeout }}; {{ if .Values.proxy.cache.enabled }} proxy_cache_path /var/cache/nginx/trafficcache keys_zone=trafficcache:{{ .Values.proxy.cache.size }}; @@ -81,5 +88,19 @@ data: default_type text/html; return 200 "

OK

\n"; } + + {{ if .Values.proxy.locations }} + {{ range .Values.proxy.locations }} + location {{ .path }} { + {{- .definition | trim | nindent 14}} + } + {{ end }} + {{ end }} } + + {{ if .Values.proxy.httpServers }} + {{ range .Values.proxy.httpServers }} + {{- . | trim | nindent 6 }} + {{ end }} + {{ end }} } diff --git a/charts/traffic-proxy/values.yaml b/charts/traffic-proxy/values.yaml index 622b8d8a5..543d8d60f 100644 --- a/charts/traffic-proxy/values.yaml +++ b/charts/traffic-proxy/values.yaml @@ -39,6 +39,12 @@ podLabels: {} # @param proxy.cache.enabled If caching should be enabled for the proxy server. # @param proxy.cache.age Cache validity period. # @param proxy.cache.size Maximum cache size. +# @param proxy.worker.processes Number of worker processes. +# @param proxy.worker.connections Number of worker connections. +# @param proxy.log.errorLog.level Error log level. Allowed values: `debug`, `info`, `notice`, `warn`, `error`, `crit`, `alert`, `emerg`. +# @param proxy.log.accessLog Access log definition. +# @param proxy.keepaliveTimeout Keepalive timeout. + proxy: host: '' @@ -49,6 +55,46 @@ proxy: enabled: true age: 1m size: 32m + worker: + processes: 2 + connections: 1024 + log: + # @param proxy.log.customFormats List of custom log formats to be used in NGINX configuration + customFormats: [] + # - name: small + # escape: json + # format: | + # '{"time_local":"$time_local",' + # '"remote_addr":"$remote_addr",' + # '"request":"$request",' + # '"status":"$status",' + # '"host":"$host"}' + errorLog: + level: error + + accessLog: off + # accessLog: '/dev/stdout main' + + keepaliveTimeout: 65 + + # @param proxy.locations List of additional location blocks to be included in the NGINX configuration + locations: [] + # - path: /test/ + # definition: | + # default_type text/html; + # return 200 "

test page

\n"; + + # @param proxy.httpServers List of additional server blocks to be included in the NGINX configuration + httpServers: {} + # examplecfg: | + # server { + # listen 0.0.0.0:8080; + + # location / { + # default_type text/html; + # return 200 "

test page

\n"; + # } + # } # @section Deployment settings