From 05da1cbb4df703eb24f1ce9184d508b8a2a47256 Mon Sep 17 00:00:00 2001 From: xieydd Date: Mon, 9 Oct 2023 10:56:39 +0800 Subject: [PATCH] chore: Fix scale up or down retry, too many event (#186) Signed-off-by: xieydd --- agent/Makefile | 4 ++-- agent/api/types/requests.go | 1 + agent/pkg/runtime/inference_replicas.go | 9 ++++++--- agent/pkg/scaling/function_scaler.go | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/agent/Makefile b/agent/Makefile index 8c26c91..1cf6938 100644 --- a/agent/Makefile +++ b/agent/Makefile @@ -175,8 +175,8 @@ swag: swag-install swag init -g ./cmd/agent/main.go --parseDependency --output ./pkg/docs build-image: build-local - docker build -t ${BASE_REGISTRY}/${BASE_REGISTRY_USER}/modelz-agent:dev -f Dockerfile ./bin - docker push ${BASE_REGISTRY}/${BASE_REGISTRY_USER}/modelz-agent:dev + docker build -t ${BASE_REGISTRY}/${BASE_REGISTRY_USER}/openmodelz-agent:dev -f Dockerfile ./bin + docker push ${BASE_REGISTRY}/${BASE_REGISTRY_USER}/openmodelz-agent:dev release: @if [ ! -f ".release-env" ]; then \ diff --git a/agent/api/types/requests.go b/agent/api/types/requests.go index 022312a..1c91c0b 100644 --- a/agent/api/types/requests.go +++ b/agent/api/types/requests.go @@ -8,6 +8,7 @@ type ScaleServiceRequest struct { ServiceName string `json:"serviceName"` Replicas uint64 `json:"replicas"` EventMessage string `json:"eventMessage"` + Attempt int `json:"attempt"` } // DeleteFunctionRequest delete a deployed function diff --git a/agent/pkg/runtime/inference_replicas.go b/agent/pkg/runtime/inference_replicas.go index 1ff4bda..b90a685 100644 --- a/agent/pkg/runtime/inference_replicas.go +++ b/agent/pkg/runtime/inference_replicas.go @@ -64,9 +64,12 @@ func (r generalRuntime) InferenceScale(ctx context.Context, namespace string, } if r.eventEnabled { - err = r.eventRecorder.CreateDeploymentEvent(namespace, deployment.Name, event, req.EventMessage) - if err != nil { - return err + // Only create event when the first time scale up/down + if req.Attempt == 0 { + err = r.eventRecorder.CreateDeploymentEvent(namespace, deployment.Name, event, req.EventMessage) + if err != nil { + return err + } } } diff --git a/agent/pkg/scaling/function_scaler.go b/agent/pkg/scaling/function_scaler.go index 98b50a2..6805eda 100644 --- a/agent/pkg/scaling/function_scaler.go +++ b/agent/pkg/scaling/function_scaler.go @@ -154,7 +154,8 @@ func (s *InferenceScaler) Scale(ctx context.Context, if err := s.runtime.InferenceScale(ctx, namespace, types.ScaleServiceRequest{ ServiceName: inferenceName, Replicas: minReplicas, - EventMessage: fmt.Sprintf("scale up to minimum replicas %d", minReplicas), + EventMessage: fmt.Sprintf("scale up to replicas %d", minReplicas), + Attempt: attempt, }, inf); err != nil { return err }