The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Enhancement(helm): ServiceMonitor template rendering (#17038)
Saar wintrov777ef628d2fc
diff --git a/deploy/charts/litellm-helm/templates/deployment.yaml b/deploy/charts/litellm-helm/templates/deployment.yamlindex 6a5a6e87577..316323be99a 100644--- a/deploy/charts/litellm-helm/templates/deployment.yaml+++ b/deploy/charts/litellm-helm/templates/deployment.yaml@@ -129,6 +129,10 @@ spec:args:- --config- /etc/litellm/config.yaml+ {{ if .Values.numWorkers }}+ - --num_workers+ - {{ .Values.numWorkers | quote }}+ {{- end }}ports:- name: httpcontainerPort: {{ .Values.service.port }}@@ -208,3 +212,8 @@ spec:tolerations:{{- toYaml . | nindent 8 }}{{- end }}+ terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds | default 90 }}+ {{- if .Values.topologySpreadConstraints }}+ topologySpreadConstraints:+ {{- toYaml .Values.topologySpreadConstraints | nindent 8 }}+ {{- end }}\ No newline at end of filediff --git a/deploy/charts/litellm-helm/templates/servicemonitor.yaml b/deploy/charts/litellm-helm/templates/servicemonitor.yamlnew file mode 100644index 00000000000..743098deb3f--- /dev/null+++ b/deploy/charts/litellm-helm/templates/servicemonitor.yaml@@ -0,0 +1,39 @@+{{- with .Values.serviceMonitor }}+{{- if and (eq .enabled true) }}+apiVersion: monitoring.coreos.com/v1+kind: ServiceMonitor+metadata:+ name: {{ include "litellm.fullname" $ }}+ labels:+ {{- include "litellm.labels" $ | nindent 4 }}+ {{- if .labels }}+ {{- toYaml .labels | nindent 4 }}+ {{- end }}+ {{- if .annotations }}+ annotations:+ {{- toYaml .annotations | nindent 4 }}+ {{- end }}+spec:+ selector:+ matchLabels:+ {{- include "litellm.selectorLabels" $ | nindent 6 }}+ namespaceSelector:+ matchNames:+ # if not set, use the release namespace+ {{- if not .namespaceSelector.matchNames }}+ - {{ $.Release.Namespace | quote }}+ {{- else }}+ {{- toYaml .namespaceSelector.matchNames | nindent 4 }}+ {{- end }}+ endpoints:+ - port: http+ path: /metrics/+ interval: {{ .interval }}+ scrapeTimeout: {{ .scrapeTimeout }}+ scheme: http+ {{- if .relabelings }}+ relabelings:+{{- toYaml .relabelings | nindent 4 }}+ {{- end }}+{{- end }}+{{- end }}diff --git a/deploy/charts/litellm-helm/templates/tests/test-servicemonitor.yaml b/deploy/charts/litellm-helm/templates/tests/test-servicemonitor.yamlnew file mode 100644index 00000000000..c2a4f84ec21--- /dev/null+++ b/deploy/charts/litellm-helm/templates/tests/test-servicemonitor.yaml@@ -0,0 +1,152 @@+{{- if .Values.serviceMonitor.enabled }}+apiVersion: v1+kind: Pod+metadata:+ name: "{{ include "litellm.fullname" . }}-test-servicemonitor"+ labels:+ {{- include "litellm.labels" . | nindent 4 }}+ annotations:+ "helm.sh/hook": test+spec:+ containers:+ - name: test+ image: bitnami/kubectl:latest+ command: ['sh', '-c']+ args:+ - |+ set -e+ echo "🔍 Testing ServiceMonitor configuration..."++ # Check if ServiceMonitor exists+ if ! kubectl get servicemonitor {{ include "litellm.fullname" . }} -n {{ .Release.Namespace }} &>/dev/null; then+ echo "❌ ServiceMonitor not found"+ exit 1+ fi+ echo "✅ ServiceMonitor exists"++ # Get ServiceMonitor YAML+ SM=$(kubectl get servicemonitor {{ include "litellm.fullname" . }} -n {{ .Release.Namespace }} -o yaml)++ # Test endpoint configuration+ ENDPOINT_PORT=$(echo "$SM" | grep -A 5 "endpoints:" | grep "port:" | awk '{print $2}')+ if [ "$ENDPOINT_PORT" != "http" ]; then+ echo "❌ Endpoint port mismatch. Expected: http, Got: $ENDPOINT_PORT"+ exit 1+ fi+ echo "✅ Endpoint port is correctly set to: $ENDPOINT_PORT"++ # Test endpoint path+ ENDPOINT_PATH=$(echo "$SM" | grep -A 5 "endpoints:" | grep "path:" | awk '{print $2}')+ if [ "$ENDPOINT_PATH" != "/metrics/" ]; then+ echo "❌ Endpoint path mismatch. Expected: /metrics/, Got: $ENDPOINT_PATH"+ exit 1+ fi+ echo "✅ Endpoint path is correctly set to: $ENDPOINT_PATH"++ # Test interval+ INTERVAL=$(echo "$SM" | grep "interval:" | awk '{print $2}')+ if [ "$INTERVAL" != "{{ .Values.serviceMonitor.interval }}" ]; then+ echo "❌ Interval mismatch. Expected: {{ .Values.serviceMonitor.interval }}, Got: $INTERVAL"+ exit 1+ fi+ echo "✅ Interval is correctly set to: $INTERVAL"++ # Test scrapeTimeout+ TIMEOUT=$(echo "$SM" | grep "scrapeTimeout:" | awk '{print $2}')+ if [ "$TIMEOUT" != "{{ .Values.serviceMonitor.scrapeTimeout }}" ]; then+ echo "❌ ScrapeTimeout mismatch. Expected: {{ .Values.serviceMonitor.scrapeTimeout }}, Got: $TIMEOUT"+ exit 1+ fi+ echo "✅ ScrapeTimeout is correctly set to: $TIMEOUT"++ # Test scheme+ SCHEME=$(echo "$SM" | grep "scheme:" | awk '{print $2}')+ if [ "$SCHEME" != "http" ]; then+ echo "❌ Scheme mismatch. Expected: http, Got: $SCHEME"+ exit 1+ fi+ echo "✅ Scheme is correctly set to: $SCHEME"++ {{- if .Values.serviceMonitor.labels }}+ # Test custom labels+ echo "🔍 Checking custom labels..."+ {{- range $key, $value := .Values.serviceMonitor.labels }}+ LABEL_VALUE=$(echo "$SM" | grep -A 20 "metadata:" | grep "{{ $key }}:" | awk '{print $2}')+ if [ "$LABEL_VALUE" != "{{ $value }}" ]; then+ echo "❌ Label {{ $key }} mismatch. Expected: {{ $value }}, Got: $LABEL_VALUE"+ exit 1+ fi+ echo "✅ Label {{ $key }} is correctly set to: {{ $value }}"+ {{- end }}+ {{- end }}++ {{- if .Values.serviceMonitor.annotations }}+ # Test annotations+ echo "🔍 Checking annotations..."+ {{- range $key, $value := .Values.serviceMonitor.annotations }}+ ANNOTATION_VALUE=$(echo "$SM" | grep -A 10 "annotations:" | grep "{{ $key }}:" | awk '{print $2}')+ if [ "$ANNOTATION_VALUE" != "{{ $value }}" ]; then+ echo "❌ Annotation {{ $key }} mismatch. Expected: {{ $value }}, Got: $ANNOTATION_VALUE"+ exit 1+ fi+ echo "✅ Annotation {{ $key }} is correctly set to: {{ $value }}"+ {{- end }}+ {{- end }}++ {{- if .Values.serviceMonitor.namespaceSelector.matchNames }}+ # Test namespace selector+ echo "🔍 Checking namespace selector..."+ {{- range .Values.serviceMonitor.namespaceSelector.matchNames }}+ if ! echo "$SM" | grep -A 5 "namespaceSelector:" | grep -q "{{ . }}"; then+ echo "❌ Namespace {{ . }} not found in namespaceSelector"+ exit 1+ fi+ echo "✅ Namespace {{ . }} found in namespaceSelector"+ {{- end }}+ {{- else }}+ # Test default namespace selector (should be release namespace)+ if ! echo "$SM" | grep -A 5 "namespaceSelector:" | grep -q "{{ .Release.Namespace }}"; then+ echo "❌ Release namespace {{ .Release.Namespace }} not found in namespaceSelector"+ exit 1+ fi+ echo "✅ Default namespace selector set to release namespace: {{ .Release.Namespace }}"+ {{- end }}++ {{- if .Values.serviceMonitor.relabelings }}+ # Test relabelings+ echo "🔍 Checking relabelings configuration..."+ if ! echo "$SM" | grep -q "relabelings:"; then+ echo "❌ Relabelings section not found"+ exit 1+ fi+ echo "✅ Relabelings section exists"+ {{- range .Values.serviceMonitor.relabelings }}+ {{- if .targetLabel }}+ if ! echo "$SM" | grep -A 50 "relabelings:" | grep -q "targetLabel: {{ .targetLabel }}"; then+ echo "❌ Relabeling targetLabel {{ .targetLabel }} not found"+ exit 1+ fi+ echo "✅ Relabeling targetLabel {{ .targetLabel }} found"+ {{- end }}+ {{- if .action }}+ if ! echo "$SM" | grep -A 50 "relabelings:" | grep -q "action: {{ .action }}"; then+ echo "❌ Relabeling action {{ .action }} not found"+ exit 1+ fi+ echo "✅ Relabeling action {{ .action }} found"+ {{- end }}+ {{- end }}+ {{- end }}++ # Test selector labels match the service+ echo "🔍 Checking selector labels match service..."+ SVC_LABELS=$(kubectl get svc {{ include "litellm.fullname" . }} -n {{ .Release.Namespace }} -o jsonpath='{.metadata.labels}')+ echo "Service labels: $SVC_LABELS"+ echo "✅ Selector labels validation passed"++ echo ""+ echo "🎉 All ServiceMonitor tests passed successfully!"+ serviceAccountName: {{ include "litellm.serviceAccountName" . }}+ restartPolicy: Never+{{- end }}+diff --git a/deploy/charts/litellm-helm/values.yaml b/deploy/charts/litellm-helm/values.yamlindex c1792497d29..acb8c9ca32f 100644--- a/deploy/charts/litellm-helm/values.yaml+++ b/deploy/charts/litellm-helm/values.yaml@@ -3,6 +3,7 @@# Declare variables to be passed into your templates.replicaCount: 1+# numWorkers: 2image:# Use "ghcr.io/berriai/litellm-database" for optimized image with database@@ -33,6 +34,15 @@ deploymentAnnotations: {}podAnnotations: {}podLabels: {}+terminationGracePeriodSeconds: 90+topologySpreadConstraints: []+ # - maxSkew: 1+ # topologyKey: kubernetes.io/hostname+ # whenUnsatisfiable: DoNotSchedule+ # labelSelector:+ # matchLabels:+ # app: litellm+# At the time of writing, the litellm docker image requires write access to the# filesystem on startup so that prisma can install some dependencies.podSecurityContext: {}@@ -248,3 +258,19 @@ pdb:maxUnavailable: null # e.g. 1 or "20%"annotations: {}labels: {}++serviceMonitor:+ enabled: false+ labels: {}+ # test: test+ annotations: {}+ # kubernetes.io/test: test+ interval: 15s+ scrapeTimeout: 10s+ relabelings: []+ # - targetLabel: __meta_kubernetes_pod_node_name+ # replacement: $1+ # action: replace+ namespaceSelector:+ matchNames: []+ # - test-namespace\ No newline at end of file