Skip to content

Commit

Permalink
Added logger to SetScale function args (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelrib authored and levrado committed Jan 16, 2019
1 parent ece2765 commit 93b2171
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/autoscaler/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (as *Autoscaler) checkResourceToScale(t time.Time, activeResources []scaler
"deltaSeconds", t.Sub(minMetric.timestamp).Seconds(),
"windowSize", as.windowSize)

err := as.resourceScaler.SetScale(as.namespace, resourceName, 0)
err := as.resourceScaler.SetScale(as.logger, as.namespace, resourceName, 0)
if err != nil {
as.logger.WarnWith("Failed to set scale", "err", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/autoscaler/autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type autoScalerTest struct {
ch chan metricEntry
}

func (suite *autoScalerTest) SetScale(namespace string, resource scaler.Resource, scale int) error {
func (suite *autoScalerTest) SetScale(logger logger.Logger, namespace string, resource scaler.Resource, scale int) error {
suite.Called(namespace, resource)
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/dlx/resourcestarter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ResourceStarter struct {
namespace string
resourceSinksMap resourceSinksMap
resourceSinkMutex sync.Mutex
resourceReadinnesTimeout time.Duration
resourceReadinessTimeout time.Duration
scaler scaler.ResourceScaler
}

Expand All @@ -36,8 +36,8 @@ func NewResourceStarter(parentLogger logger.Logger,
logger: parentLogger.GetChild("resource-starter"),
resourceSinksMap: make(resourceSinksMap),
namespace: namespace,
resourceReadinnesTimeout: time.Minute,
scaler: scaler,
resourceReadinessTimeout: time.Minute,
scaler: scaler,
}
return fs, nil
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func (r *ResourceStarter) startResource(resourceSinkChannel chan responseChannel
go r.waitResourceReadiness(scaler.Resource(resourceName), resourceReadyChannel)

select {
case <-time.After(r.resourceReadinnesTimeout):
case <-time.After(r.resourceReadinessTimeout):
r.logger.WarnWith("Timed out waiting for resource to be ready", "resource", resourceName)
defer r.deleteResourceSink(resourceName)
resultStatus = ResourceStatusResult{
Expand Down Expand Up @@ -123,7 +123,7 @@ func (r *ResourceStarter) startResource(resourceSinkChannel chan responseChannel
}

func (r *ResourceStarter) waitResourceReadiness(resourceName scaler.Resource, resourceReadyChannel chan error) {
err := r.scaler.SetScale(r.namespace, resourceName, 1)
err := r.scaler.SetScale(r.logger, r.namespace, resourceName, 1)
resourceReadyChannel <- err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/dlx/resourcestarter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type mocker struct {
mock.Mock
}

func (suite *resourceStarterTest) SetScale(namespace string, resourceName scaler.Resource, scale int) error {
func (suite *resourceStarterTest) SetScale(logger logger.Logger, namespace string, resourceName scaler.Resource, scale int) error {
suite.mocker.Called(resourceName)
return nil
}
Expand All @@ -44,8 +44,8 @@ func (suite *resourceStarterTest) SetupTest() {
logger: suite.logger,
resourceSinksMap: make(resourceSinksMap),
namespace: "default",
resourceReadinnesTimeout: time.Duration(1 * time.Second),
scaler: suite,
resourceReadinessTimeout: time.Duration(1 * time.Second),
scaler: suite,
}
suite.mocker = new(mocker)
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/resourcescaler/resourcescaler.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package resourcescaler

import "github.com/v3io/scaler/pkg"
import (
"github.com/v3io/scaler/pkg"

"github.com/nuclio/logger"
)

type ResourceScaler struct{}

func New() *ResourceScaler {
return &ResourceScaler{}
}

func (r *ResourceScaler) SetScale(string, scaler.Resource, int) error {
func (r *ResourceScaler) SetScale(logger.Logger, string, scaler.Resource, int) error {
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scaler
import (
"time"

"github.com/nuclio/logger"
"k8s.io/client-go/kubernetes"
custommetricsv1 "k8s.io/metrics/pkg/client/custom_metrics"
)
Expand Down Expand Up @@ -48,7 +49,7 @@ type DLXOptions struct {
}

type ResourceScaler interface {
SetScale(string, Resource, int) error
SetScale(logger.Logger, string, Resource, int) error
GetResources() ([]Resource, error)
GetConfig() (*ResourceScalerConfig, error)
}
Expand Down

0 comments on commit 93b2171

Please sign in to comment.