Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reference ScaledObject's/ScaledJob's name in the scalers log #3495

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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