Skip to content

Commit

Permalink
Merge pull request #23 from mikemrm/add-otel
Browse files Browse the repository at this point in the history
add nginx otel configuration
  • Loading branch information
mikemrm authored Dec 10, 2024
2 parents 186f6cf + cd5d0e0 commit 3d7c2bd
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 48 deletions.
38 changes: 0 additions & 38 deletions nginx-redirect/nginx-templates/default.conf.template

This file was deleted.

103 changes: 98 additions & 5 deletions nginx-redirect/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,103 @@
{{- $files := .Files.Glob "nginx-templates/*" }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "common.names.fullname" . }}-templates
name: {{ include "common.names.fullname" . }}-config
data:
{{- range $filename, $content := $files }}
{{ base $filename }}: | {{- tpl ($content | toString) $ | nindent 4 }}
{{- end }}
nginx.conf: |
{{- if .Values.otel.enabled }}
load_module modules/ngx_otel_module.so;
{{- end }}
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
{{- with .Values.otel }}
{{- if .enabled }}
otel_exporter {
endpoint {{ or .endpoint (fail "otel.endpoint required") }};
interval {{ .interval }};
batch_size {{ .batchSize }};
batch_count {{ .batchCount }};
}
otel_trace on;
otel_trace_context {{ .context }};
otel_service_name {{ .serviceName | default $.Release.Name | quote }};
{{- with .spanName }}
otel_span_name {{ quote . }};
{{- end }}
{{- range $name, $value := .spanAttributes }}
otel_span_attr {{ quote $name }} {{ quote $value }};
{{- end }}
{{- end }}
{{- end }}
map $host$request_uri $redir_to {
default "not-found";
{{- range $src, $dst := .Values.redirects }}
{{- if hasPrefix "^" $src }}
{{ printf "~%s" $src }} {{ quote $dst }};
{{- end }}
{{- end }}
}
map $host $redir_host_to {
default "not-found";
{{- range $src, $dst := .Values.redirects }}
{{- if not (hasPrefix "^" $src) }}
{{ quote $src }} {{ quote $dst }};
{{- end }}
{{- end }}
}
server {
listen 80;
{{- range .Values.proxy_real_ip_from }}
set_real_ip_from {{ quote . }};
{{- end }}
location / {
resolver {{ .Values.resolver }} valid=30s;
if ($redir_to != "not-found") {
return 301 $redir_to;
}
if ($redir_host_to != "not-found") {
return 301 $redir_host_to;
}
return 404;
}
}
include /etc/nginx/conf.d/*.conf;
}
14 changes: 9 additions & 5 deletions nginx-redirect/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{{- $defaultImageTag := printf "%s-alpine" .Chart.AppVersion }}
{{- if .Values.otel.enabled }}
{{- $defaultImageTag = printf "%s-otel" $defaultImageTag }}
{{- end }}
---
apiVersion: apps/v1
kind: Deployment
Expand All @@ -11,7 +14,7 @@ spec:
template:
metadata:
annotations:
checksum/templates: {{ include "common.utils.checksumTemplate" (dict "path" "/configmap.yaml" "context" $) | quote }}
checksum/config: {{ include "common.utils.checksumTemplate" (dict "path" "/configmap.yaml" "context" $) | quote }}
{{- with .Values.deployment.annotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -40,15 +43,16 @@ spec:
securityContext: {{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: nginx-templates
mountPath: /etc/nginx/templates
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
{{- with .Values.deployment.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
volumes:
- name: nginx-templates
- name: nginx-config
configMap:
name: {{ include "common.names.fullname" . }}-templates
name: {{ include "common.names.fullname" . }}-config
{{- with .Values.deployment.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
29 changes: 29 additions & 0 deletions nginx-redirect/values.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
---
redirects: {}
# redirect.host: https://redirect/url
# ^redirect.host/path$: https://redirect/url

proxy_real_ip_from: []
# - 192.168.0.0/16

resolver: kube-dns.kube-system.svc.cluster.local

otel:
enabled: false
# -- the address of OTLP/gRPC endpoint that will accept telemetry data.
endpoint: ""
# -- the maximum interval between two exports.
interval: 5s
# -- the maximum number of spans to be sent in one batch per worker.
batchSize: 512
# -- the number of pending batches per worker, spans exceeding the limit are dropped.
batchCount: 4
# -- sets the "service.name" attribute of the OTel resource.
# @default -- .Release.Name
serviceName: ""
# -- specifies how to propagate trace context.
# Options:
# - `extract` uses an existing trace context from the request, so that the identifiers of a trace and the parent span are inherited from the incoming request.
# - `inject` adds a new context to the request, overwriting existing headers, if any.
# - `propagate` updates the existing context (combines extract and i nject).
# - `ignore` skips context headers processing.
context: inject
# -- defines the name of the OTel span.
spanName: ""
# -- defines additional attributes on the span.
spanAttributes:
http.referer: $http_referer

nameOverride: ""
fullnameOverride: ""

Expand Down

0 comments on commit 3d7c2bd

Please sign in to comment.