Skip to content

Commit

Permalink
fix: Reference ScaledObject's/ScaledJob's name in the scalers log (#3495
Browse files Browse the repository at this point in the history
)

Signed-off-by: Zbynek Roubalik <[email protected]>
  • Loading branch information
zroubalik authored Aug 3, 2022
1 parent e345bf5 commit e6580a5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
2 changes: 2 additions & 0 deletions pkg/scalers/azure_data_explorer_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type azureDataExplorerScaler struct {
client *kusto.Client
name string
namespace string
logger logr.Logger
}

const adxName = "azure-data-explorer"
Expand Down Expand Up @@ -66,6 +67,7 @@ func NewAzureDataExplorerScaler(ctx context.Context, config *ScalerConfig) (Scal
client: client,
name: config.ScalableObjectName,
namespace: config.ScalableObjectNamespace,
logger: logger,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/scalers/azure_data_explorer_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func TestDataExplorerGetMetricSpecForScaling(t *testing.T) {
client: nil,
name: "mock_scaled_object",
namespace: "mock_namespace",
logger: logr.Discard(),
}

metricSpec := mockDataExplorerScaler.GetMetricSpecForScaling(context.Background())
Expand Down
29 changes: 7 additions & 22 deletions pkg/scalers/redis_streams_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"

"github.com/go-logr/logr"
"github.com/go-redis/redis/v8"
v2beta2 "k8s.io/api/autoscaling/v2beta2"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/metrics/pkg/apis/external_metrics"
Expand Down Expand Up @@ -101,6 +102,7 @@ func createClusteredRedisStreamsScaler(ctx context.Context, meta *redisStreamsMe
metadata: meta,
closeFn: closeFn,
getPendingEntriesCountFn: pendingEntriesCountFn,
logger: logger,
}, nil
}

Expand All @@ -110,28 +112,7 @@ func createSentinelRedisStreamsScaler(ctx context.Context, meta *redisStreamsMet
return nil, fmt.Errorf("connection to redis sentinel failed: %s", err)
}

closeFn := func() error {
if err := client.Close(); err != nil {
logger.Error(err, "error closing redis client")
return err
}
return nil
}

pendingEntriesCountFn := func(ctx context.Context) (int64, error) {
pendingEntries, err := client.XPending(ctx, meta.streamName, meta.consumerGroupName).Result()
if err != nil {
return -1, err
}
return pendingEntries.Count, nil
}

return &redisStreamsScaler{
metricType: metricType,
metadata: meta,
closeFn: closeFn,
getPendingEntriesCountFn: pendingEntriesCountFn,
}, nil
return createScaler(client, meta, metricType, logger)
}

func createRedisStreamsScaler(ctx context.Context, meta *redisStreamsMetadata, metricType v2beta2.MetricTargetType, logger logr.Logger) (Scaler, error) {
Expand All @@ -140,6 +121,10 @@ func createRedisStreamsScaler(ctx context.Context, meta *redisStreamsMetadata, m
return nil, fmt.Errorf("connection to redis failed: %s", err)
}

return createScaler(client, meta, metricType, logger)
}

func createScaler(client *redis.Client, meta *redisStreamsMetadata, metricType v2beta2.MetricTargetType, logger logr.Logger) (Scaler, error) {
closeFn := func() error {
if err := client.Close(); err != nil {
logger.Error(err, "error closing redis client")
Expand Down

0 comments on commit e6580a5

Please sign in to comment.