From f04f1f30443e2deefe1e1a96e25055da7144bdde Mon Sep 17 00:00:00 2001 From: Liya Katz Date: Thu, 5 Sep 2024 09:24:34 +0300 Subject: [PATCH] add replicaCount and hpa for opik (#183) --- deployment/helm_chart/opik/README.md | 4 ++ .../helm_chart/opik/templates/deployment.yaml | 4 +- deployment/helm_chart/opik/templates/hpa.yaml | 44 +++++++++++++++++++ deployment/helm_chart/opik/values.yaml | 7 ++- 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 deployment/helm_chart/opik/templates/hpa.yaml diff --git a/deployment/helm_chart/opik/README.md b/deployment/helm_chart/opik/README.md index 0a991b034..0a62ce127 100644 --- a/deployment/helm_chart/opik/README.md +++ b/deployment/helm_chart/opik/README.md @@ -99,6 +99,7 @@ Call opik api on http://localhost:5173/api | clickhouse.replicasCount | int | `1` | | | clickhouse.shardsCount | int | `1` | | | clickhouse.storage | string | `"50Gi"` | | +| component.backend.autoscaling.enabled | bool | `false` | | | component.backend.env.ANALYTICS_DB_DATABASE_NAME | string | `"opik"` | | | component.backend.env.ANALYTICS_DB_HOST | string | `"clickhouse-opik-clickhouse"` | | | component.backend.env.ANALYTICS_DB_MIGRATIONS_URL | string | `"jdbc:clickhouse://clickhouse-opik-clickhouse:8123"` | | @@ -119,6 +120,7 @@ Call opik api on http://localhost:5173/api | component.backend.initContainers[0].env[0].value | string | `"http://clickhouse-opik-clickhouse:8123"` | | | component.backend.initContainers[0].image | string | `"stefanevinance/wait-for-200"` | | | component.backend.initContainers[0].name | string | `"wait-for-clickhouse-service"` | | +| component.backend.replicaCount | int | `1` | | | component.backend.service.ports[0].name | string | `"http"` | | | component.backend.service.ports[0].port | int | `8080` | | | component.backend.service.ports[0].protocol | string | `"TCP"` | | @@ -129,9 +131,11 @@ Call opik api on http://localhost:5173/api | component.backend.service.ports[1].targetPort | int | `3003` | | | component.backend.service.type | string | `"ClusterIP"` | | | component.backend.serviceAccount.create | bool | `true` | | +| component.frontend.autoscaling.enabled | bool | `false` | | | component.frontend.image.pullPolicy | string | `"IfNotPresent"` | | | component.frontend.image.repository | string | `"opik-frontend"` | | | component.frontend.ingress.enabled | bool | `false` | | +| component.frontend.replicaCount | int | `1` | | | component.frontend.service.ports[0].name | string | `"http"` | | | component.frontend.service.ports[0].port | int | `5173` | | | component.frontend.service.ports[0].protocol | string | `"TCP"` | | diff --git a/deployment/helm_chart/opik/templates/deployment.yaml b/deployment/helm_chart/opik/templates/deployment.yaml index 739248a4d..f20dc0be1 100644 --- a/deployment/helm_chart/opik/templates/deployment.yaml +++ b/deployment/helm_chart/opik/templates/deployment.yaml @@ -8,7 +8,9 @@ metadata: {{- include "opik.labels" $ | nindent 4 }} component: {{ include "opik.name" $ }}-{{ $key | lower }} spec: - replicas: 1 + {{- if not $value.autoscaling.enabled }} + replicas: {{ $value.replicaCount }} + {{- end }} selector: matchLabels: {{- include "opik.labels" $ | nindent 6 }} diff --git a/deployment/helm_chart/opik/templates/hpa.yaml b/deployment/helm_chart/opik/templates/hpa.yaml new file mode 100644 index 000000000..3df054800 --- /dev/null +++ b/deployment/helm_chart/opik/templates/hpa.yaml @@ -0,0 +1,44 @@ +{{- range $key, $value := .Values.component }} + {{- if $value.autoscaling.enabled }} +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "opik.name" $ }}-{{ $key | lower }}-hpa + labels: + {{- include "opik.labels" $ | nindent 4 }} + component: {{ include "opik.name" $ }}-{{ $key | lower }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: "Deployment" + name: {{ include "opik.name" $ }}-{{ $key | lower }} + minReplicas: {{ $value.autoscaling.minReplicas }} + maxReplicas: {{ $value.autoscaling.maxReplicas }} + metrics: + {{- if $value.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ $value.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if $value.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ $value.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} + {{- if $value.autoscaling.targetMemoryAverageValue }} + - type: Resource + resource: + name: memory + target: + type: AverageValue + averageValue: {{ $value.autoscaling.targetMemoryAverageValue }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deployment/helm_chart/opik/values.yaml b/deployment/helm_chart/opik/values.yaml index dc6fbb7ca..b1a084e1e 100644 --- a/deployment/helm_chart/opik/values.yaml +++ b/deployment/helm_chart/opik/values.yaml @@ -17,6 +17,9 @@ component: image: repository: opik-backend pullPolicy: IfNotPresent + replicaCount: 1 + autoscaling: + enabled: false initContainers: - name: wait-for-clickhouse-service image: stefanevinance/wait-for-200 @@ -71,7 +74,9 @@ component: image: repository: opik-frontend pullPolicy: IfNotPresent - + replicaCount: 1 + autoscaling: + enabled: false volumeMounts: - mountPath: /etc/nginx/conf.d/ name: opik-frontend-nginx