Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions helm/templates/dashboards.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{{- if .Values.grafanaDashboards.enabled }}
{{- range $path, $bytes := .Files.Glob "dashboards/*.json" }}
{{- $filename := base $path }}
{{- if and (eq $filename "lmcache-dashboard.json") (not $.Values.cacheserverSpec.enabled) }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If a user overrides .Values and completely omits cacheserverSpec or sets it to null, accessing $.Values.cacheserverSpec.enabled will cause a template rendering error (nil pointer evaluation). To make this check robust and prevent potential rendering failures, we can use the Sprig dig function to safely traverse the nested map with a default fallback value.

{{- if and (eq $filename "lmcache-dashboard.json") (not (dig "cacheserverSpec" "enabled" false $.Values)) }}

{{- continue }}
{{- end }}
---
apiVersion: v1
kind: ConfigMap
Expand Down
38 changes: 36 additions & 2 deletions helm/tests/dashboards_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ tests:
- hasDocuments:
count: 0

- it: should render dashboards when grafanaDashboards is enabled
- it: should render all dashboards when grafanaDashboards and cacheserver are enabled
release:
name: vllm
set:
grafanaDashboards:
enabled: true
annotations:
app: grafana
cacheserverSpec:
enabled: true
asserts:
- hasDocuments:
count: 2
count: 3
- documentIndex: 0
equal:
path: metadata.name
Expand Down Expand Up @@ -50,3 +52,35 @@ tests:
path: metadata.labels
value:
grafana_dashboard: "1"
- documentIndex: 2
equal:
path: metadata.name
value: vllm-grafana-vllm-model-metrics-dashboard
- documentIndex: 2
exists:
path: data["vllm-model-metrics-dashboard.json"]
- documentIndex: 2
equal:
path: metadata.labels
value:
grafana_dashboard: "1"

- it: should exclude lmcache-dashboard when cacheserver is disabled
release:
name: vllm
set:
grafanaDashboards:
enabled: true
cacheserverSpec:
enabled: false
asserts:
- hasDocuments:
count: 2
- documentIndex: 0
equal:
path: metadata.name
value: vllm-grafana-vllm-dashboard
- documentIndex: 1
equal:
path: metadata.name
value: vllm-grafana-vllm-model-metrics-dashboard