From e167c0ec83c9f6f1824f4d3149db2fad52205861 Mon Sep 17 00:00:00 2001 From: Andrii Chubatiuk Date: Mon, 4 May 2026 12:39:49 +0300 Subject: [PATCH] vmanomaly/vmagent: fix logging for sharded deployments --- .../controller/operator/factory/vmagent/vmagent.go | 13 +++++++------ .../operator/factory/vmanomaly/statefulset.go | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/internal/controller/operator/factory/vmagent/vmagent.go b/internal/controller/operator/factory/vmagent/vmagent.go index b16538652..27d20c1a0 100644 --- a/internal/controller/operator/factory/vmagent/vmagent.go +++ b/internal/controller/operator/factory/vmagent/vmagent.go @@ -190,13 +190,14 @@ func createOrUpdateApp(ctx context.Context, rclient client.Client, cr, prevCR *v shardCount := cr.GetShardCount() prevShardCount := prevCR.GetShardCount() - isUpscaling := false + isUpscaling := prevShardCount < shardCount if prevCR.IsSharded() { - if prevShardCount < shardCount { - logger.WithContext(ctx).Info(fmt.Sprintf("VMAgent shard upscaling from=%d to=%d", prevShardCount, shardCount)) - isUpscaling = true - } else { - logger.WithContext(ctx).Info(fmt.Sprintf("VMAgent shard downscaling from=%d to=%d", prevShardCount, shardCount)) + if prevShardCount != shardCount { + action := "downscaling" + if isUpscaling { + action = "upscaling" + } + logger.WithContext(ctx).Info(fmt.Sprintf("VMAgent shard %s from=%d to=%d", action, prevShardCount, shardCount)) } } diff --git a/internal/controller/operator/factory/vmanomaly/statefulset.go b/internal/controller/operator/factory/vmanomaly/statefulset.go index 3d94c9931..affe53c15 100644 --- a/internal/controller/operator/factory/vmanomaly/statefulset.go +++ b/internal/controller/operator/factory/vmanomaly/statefulset.go @@ -176,13 +176,14 @@ func createOrUpdateApp(ctx context.Context, rclient client.Client, cr, prevCR *v shardCount := cr.GetShardCount() prevShardCount := prevCR.GetShardCount() - isUpscaling := false + isUpscaling := prevShardCount < shardCount if prevCR.IsSharded() { - if prevShardCount < shardCount { - logger.WithContext(ctx).Info(fmt.Sprintf("%T shard upscaling from=%d to=%d", cr, prevShardCount, shardCount)) - isUpscaling = true - } else { - logger.WithContext(ctx).Info(fmt.Sprintf("%T shard downscaling from=%d to=%d", cr, prevShardCount, shardCount)) + if prevShardCount != shardCount { + action := "downscaling" + if isUpscaling { + action = "upscaling" + } + logger.WithContext(ctx).Info(fmt.Sprintf("VMAnomaly shard %s from=%d to=%d", action, prevShardCount, shardCount)) } }