Skip to content

Commit

Permalink
Apply go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
triarius committed Mar 31, 2023
1 parent b918626 commit 035f358
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
20 changes: 10 additions & 10 deletions lambda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ var (

type LastScaleASGResult struct {
LastScaleOutActivity *autoscaling.Activity
LastScaleInActivity *autoscaling.Activity
Err error
LastScaleInActivity *autoscaling.Activity
Err error
}

func main() {
Expand All @@ -50,7 +50,7 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {
interval time.Duration = 10 * time.Second

asgActivityTimeoutDuration = 10 * time.Second
asgActivityTimeout = time.After(asgActivityTimeoutDuration)
asgActivityTimeout = time.After(asgActivityTimeoutDuration)

scaleInCooldownPeriod time.Duration
scaleInFactor float64
Expand Down Expand Up @@ -164,19 +164,19 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {
scalingLastActivityStartTime := time.Now()
go func() {
scaleOutOutput, scaleInOutput, err := asg.GetLastScalingInAndOutActivity()
result := LastScaleASGResult {
scaleOutOutput,
result := LastScaleASGResult{
scaleOutOutput,
scaleInOutput,
err,
}
c1 <- result
}()

select {
case res := <-c1:
case res := <-c1:
if res.Err != nil {
log.Printf("Failed to retrieve last scaling activity events due to error (%s)", res.Err)
break;
break
}

scaleInOutput := res.LastScaleInActivity
Expand All @@ -189,8 +189,8 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {
}
scalingTimeDiff := time.Now().Sub(scalingLastActivityStartTime)
log.Printf("Succesfully retrieved last scaling activity events. Last scale out %v, last scale in %v. Discovery took %s.", lastScaleOut, lastScaleIn, scalingTimeDiff)
case <- asgActivityTimeout:
log.Printf("Failed to retrieve last scaling activity events due to %s timeout", asgActivityTimeoutDuration)
case <-asgActivityTimeout:
log.Printf("Failed to retrieve last scaling activity events due to %s timeout", asgActivityTimeoutDuration)
}

for {
Expand Down Expand Up @@ -231,7 +231,7 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {
Factor: scaleOutFactor,
LastEvent: lastScaleOut,
},
InstanceBuffer: instanceBuffer,
InstanceBuffer: instanceBuffer,
ScaleOnlyAfterAllEvent: scaleOnlyAfterAllEvent,
}

Expand Down
4 changes: 2 additions & 2 deletions scaler/asg.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
activitySucessfulStatusCode = "Successful"
activitySucessfulStatusCode = "Successful"
userRequestForChangingDesiredCapacity = "a user request explicitly set group desired capacity changing the desired capacity"
)

Expand Down Expand Up @@ -89,7 +89,7 @@ func (a *ASGDriver) GetAutoscalingActivities(nextToken *string) (*autoscaling.De
svc := autoscaling.New(a.Sess)
input := &autoscaling.DescribeScalingActivitiesInput{
AutoScalingGroupName: aws.String(a.Name),
NextToken: nextToken,
NextToken: nextToken,
}
return svc.DescribeScalingActivities(input)
}
Expand Down
14 changes: 7 additions & 7 deletions scaler/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ type Scaler struct {
metrics interface {
Publish(orgSlug, queue string, metrics map[string]int64) error
}
scaling ScalingCalculator
scaleInParams ScaleParams
scaleOutParams ScaleParams
instanceBuffer int
scaling ScalingCalculator
scaleInParams ScaleParams
scaleOutParams ScaleParams
instanceBuffer int
scaleOnlyAfterAllEvent bool
}

Expand All @@ -55,9 +55,9 @@ func NewScaler(client *buildkite.Client, sess *session.Session, params Params) (
client: client,
queue: params.BuildkiteQueue,
},
scaleInParams: params.ScaleInParams,
scaleOutParams: params.ScaleOutParams,
instanceBuffer: params.InstanceBuffer,
scaleInParams: params.ScaleInParams,
scaleOutParams: params.ScaleOutParams,
instanceBuffer: params.InstanceBuffer,
scaleOnlyAfterAllEvent: params.ScaleOnlyAfterAllEvent,
}

Expand Down
32 changes: 16 additions & 16 deletions scaler/scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestScalingOutWithoutError(t *testing.T) {
{
metrics: buildkite.AgentMetrics{
ScheduledJobs: 1,
IdleAgents: 0,
IdleAgents: 0,
TotalAgents: 0,
},
params: Params{
Expand All @@ -242,7 +242,7 @@ func TestScalingOutWithoutError(t *testing.T) {
CooldownPeriod: 2 * time.Minute,
},
ScaleInParams: ScaleParams{
LastEvent:time.Now().Add(-1 * time.Minute),
LastEvent: time.Now().Add(-1 * time.Minute),
CooldownPeriod: 5 * time.Minute,
},
ScaleOnlyAfterAllEvent: true,
Expand All @@ -256,11 +256,11 @@ func TestScalingOutWithoutError(t *testing.T) {
desiredCapacity: tc.currentDesiredCapacity,
}
s := Scaler{
autoscaling: asg,
bk: &buildkiteTestDriver{metrics: tc.metrics},
scaleOutParams: tc.params.ScaleOutParams,
scaleInParams: tc.params.ScaleInParams,
instanceBuffer: tc.params.InstanceBuffer,
autoscaling: asg,
bk: &buildkiteTestDriver{metrics: tc.metrics},
scaleOutParams: tc.params.ScaleOutParams,
scaleInParams: tc.params.ScaleInParams,
instanceBuffer: tc.params.InstanceBuffer,
scaleOnlyAfterAllEvent: tc.params.ScaleOnlyAfterAllEvent,
scaling: ScalingCalculator{
includeWaiting: tc.params.IncludeWaiting,
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestScalingInWithoutError(t *testing.T) {
},
params: Params{
AgentsPerInstance: 1,
InstanceBuffer: 10,
InstanceBuffer: 10,
},
currentDesiredCapacity: 30,
expectedDesiredCapacity: 25,
Expand All @@ -354,8 +354,8 @@ func TestScalingInWithoutError(t *testing.T) {
// Make sure we round down so we eventually reach zero
{
metrics: buildkite.AgentMetrics{
IdleAgents: 1,
TotalAgents: 1,
IdleAgents: 1,
TotalAgents: 1,
},
params: Params{
AgentsPerInstance: 1,
Expand All @@ -369,7 +369,7 @@ func TestScalingInWithoutError(t *testing.T) {
// Scale in disabled
{
metrics: buildkite.AgentMetrics{
TotalAgents: 1,
TotalAgents: 1,
},
params: Params{
ScaleInParams: ScaleParams{
Expand All @@ -383,7 +383,7 @@ func TestScalingInWithoutError(t *testing.T) {
{
metrics: buildkite.AgentMetrics{
IdleAgents: 3,
TotalAgents: 3,
TotalAgents: 3,
},
params: Params{
AgentsPerInstance: 1,
Expand All @@ -392,7 +392,7 @@ func TestScalingInWithoutError(t *testing.T) {
CooldownPeriod: 5 * time.Minute,
},
ScaleInParams: ScaleParams{
LastEvent:time.Now().Add(-10 * time.Minute),
LastEvent: time.Now().Add(-10 * time.Minute),
CooldownPeriod: 2 * time.Minute,
},
ScaleOnlyAfterAllEvent: true,
Expand All @@ -414,9 +414,9 @@ func TestScalingInWithoutError(t *testing.T) {
includeWaiting: tc.params.IncludeWaiting,
agentsPerInstance: tc.params.AgentsPerInstance,
},
scaleInParams: tc.params.ScaleInParams,
scaleOutParams: tc.params.ScaleOutParams,
instanceBuffer: tc.params.InstanceBuffer,
scaleInParams: tc.params.ScaleInParams,
scaleOutParams: tc.params.ScaleOutParams,
instanceBuffer: tc.params.InstanceBuffer,
scaleOnlyAfterAllEvent: tc.params.ScaleOnlyAfterAllEvent,
}

Expand Down

0 comments on commit 035f358

Please sign in to comment.