Skip to content

Commit

Permalink
update helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
kondratyevd committed Feb 7, 2025
1 parent 3839dcf commit 7b06cc3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 49 deletions.
72 changes: 24 additions & 48 deletions helm/supersonic/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{- /* templates/_helpers.tpl */ -}}

{{/*
Get instance name (equal to release name unless overridden)
*/}}
{{- define "supersonic.name" -}}
{{- if .Values.nameOverride }}
{{- printf "%s" .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
Expand All @@ -7,64 +11,27 @@
{{- end }}
{{- end -}}

{{/*
Get Triton server name
*/}}
{{- define "supersonic.tritonName" -}}
{{- printf "%s-triton" (include "supersonic.name" .) | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Get Envoy proxy name
*/}}
{{- define "supersonic.envoyName" -}}
{{- printf "%s-envoy" (include "supersonic.name" .) | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "supersonic.prometheusName" -}}
{{- printf "%s-prometheus" (include "supersonic.name" .) | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "supersonic.grafanaName" -}}
{{- printf "%s-grafana" (include "supersonic.name" .) | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "supersonic.defaultMetric" -}}
{{- if not ( eq .Values.prometheus.serverLoadMetric "" ) }}
{{- printf "%s" .Values.prometheus.serverLoadMetric -}}
{{- else }}
sum by (job) (
rate(nv_inference_queue_duration_us{job=~"{{ include "supersonic.tritonName" . }}"}[15s])
)
/
sum by (job) (
(rate(nv_inference_exec_count{job=~"{{ include "supersonic.tritonName" . }}"}[15s]) * 1000) + 0.001
)
{{- end }}
{{- end }}

{{/*
Get gRPC endpoint for client connections
*/}}
{{- define "supersonic.grpcEndpoint" -}}
{{- if .Values.ingress.enabled -}}
{{ .Values.ingress.hostName }}:443
{{- end }}
{{- end }}

{{- define "supersonic.prometheusUrl" -}}
{{- if (not .Values.prometheus.external) -}}
{{- if .Values.prometheus.ingress.enabled -}}
https://{{ .Values.prometheus.ingress.hostName }}
{{- else -}}
http://{{ include "supersonic.prometheusName" . }}.{{ .Release.Namespace }}.svc.cluster.local:9090
{{- end -}}
{{- else if .Values.prometheus.url -}}
{{ .Values.prometheus.scheme }}://{{ .Values.prometheus.url }}
{{- end }}
{{- end }}

{{- define "supersonic.validateRBACPermissions" -}}
{{- if not .Values.prometheus.external -}}
{{- $canReadRoles := false -}}
{{- if (lookup "rbac.authorization.k8s.io/v1" "Role" .Release.Namespace "") -}}
{{- $canReadRoles = true -}}
{{- end -}}
{{- if not $canReadRoles -}}
{{- fail "\nError: Failed to install Prometheus due to lack of permissions to get 'roles' in API group 'rbac.authorization.k8s.io'.\nEither:\n1. Set prometheus.external=true in value.yaml and provide an external Prometheus URL, or\n2. Request necessary RBAC permissions from your cluster administrator." -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Expand All @@ -76,7 +43,7 @@ Validate that there is no existing Grafana instance when enabling a new one
{{- $root := . -}}
{{- range (lookup "v1" "Service" .Release.Namespace "").items -}}
{{- if and (eq (index .metadata.labels "app.kubernetes.io/name") "grafana")
(eq (index .metadata.labels "app.kubernetes.io/instance") "supersonic")}}
(ne (index .metadata.labels "app.kubernetes.io/instance") (include "supersonic.name" $root))}}
{{- $releaseName := index .metadata.annotations "meta.helm.sh/release-name" -}}
{{- $podName := "" -}}
{{- if (lookup "v1" "Pod" $root.Release.Namespace "") -}}
Expand All @@ -96,7 +63,16 @@ Validate that there is no existing Grafana instance when enabling a new one
{{- end -}}
{{- end -}}
{{- end -}}
{{- fail (printf "\n\nError: Found existing Grafana instance in the namespace:\n • Pod name: %s\n • Related to SuperSONIC release: %s\nTo proceed, either:\n 1. Set grafana.enabled=false in values.yaml to use the existing Grafana instance, or\n 2. Remove the existing Grafana instance by running:\n helm upgrade %s fastml/supersonic --reuse-values --set grafana.enabled=false -n %s" $podName (default "standalone Grafana" $supersonic_release) $releaseName $root.Release.Namespace) -}}
{{- $message := cat "" -}}
Error: Found existing Grafana instance in the namespace:
- Pod name: {{ $podName }}
- Related to SuperSONIC release: {{ default "standalone Grafana" $supersonic_release }}

To proceed, either:
1. Set grafana.enabled=false in values.yaml to use the existing Grafana instance, or
2. Remove the existing Grafana instance by running:
helm upgrade {{ $releaseName }} fastml/supersonic --reuse-values --set grafana.enabled=false -n {{ $root.Release.Namespace }}
{{- $message | nindent 0 | fail -}}
{{- end -}}
{{- end -}}
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion helm/supersonic/templates/_prometheus.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Validate RBAC permissions for Prometheus
{{- if (lookup "rbac.authorization.k8s.io/v1" "Role" .Release.Namespace "") -}}
{{- $canReadRoles = true -}}
{{- end -}}
{{- if not $canReadRoles -}}
{{- if eq $canReadRoles false -}}
{{- fail "\nError: Failed to install Prometheus due to lack of permissions to get 'roles' in API group 'rbac.authorization.k8s.io'.\nEither:\n1. Set prometheus.external=true in value.yaml and provide an external Prometheus URL, or\n2. Request necessary RBAC permissions from your cluster administrator." -}}
{{- end -}}
{{- end -}}
Expand Down
23 changes: 23 additions & 0 deletions helm/supersonic/templates/_scaling-metric.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{/*
Get default scaling metric
*/}}
{{- define "supersonic.defaultMetric" -}}
{{- if not ( eq .Values.prometheus.serverLoadMetric "" ) }}
{{- printf "%s" .Values.prometheus.serverLoadMetric -}}
{{- else }}
sum by (release) (
rate(nv_inference_queue_duration_us{release=~"{{ include "supersonic.name" . }}"}[15s])
)
/
sum by (release) (
(rate(nv_inference_exec_count{release=~"{{ include "supersonic.name" . }}"}[15s]) * 1000) + 0.001
)
{{- end }}
{{- end }}

{{/*
Get server load threshold (defaults to 100 if not set)
*/}}
{{- define "supersonic.serverLoadThreshold" -}}
{{- default 100 .Values.prometheus.serverLoadThreshold -}}
{{- end -}}

0 comments on commit 7b06cc3

Please sign in to comment.