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

Replace all unnecessary backtick strings with reggo strings #88

Merged
merged 2 commits into from
May 17, 2023
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
8 changes: 8 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
steps:
- name: ":go: go fmt"
key: test-go-fmt
command: ".buildkite/steps/test-go-fmt.sh"
plugins:
- docker#v3.1.0:
image: "golang:1.19"
workdir: /go/src/github.com/buildkite/buildkite-agent-scaler

- name: ":golang:"
command: ".buildkite/steps/tests.sh"
plugins:
Expand Down
11 changes: 11 additions & 0 deletions .buildkite/steps/test-go-fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

if [[ $(gofmt -l ./ | head -c 1 | wc -c) != 0 ]]; then
echo "The following files haven't been formatted with \`go fmt\`:"
gofmt -l ./
echo
echo "Fix this by running \`go fmt ./...\` locally, and committing the result."
exit 1
fi

echo "Everything is formatted! 🎉"
2 changes: 1 addition & 1 deletion buildkite/buildkite.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

const (
DefaultMetricsEndpoint = "https://agent.buildkite.com/v3"
PollDurationHeader = `Buildkite-Agent-Metrics-Poll-Duration`
PollDurationHeader = "Buildkite-Agent-Metrics-Poll-Duration"
)

type Client struct {
Expand Down
42 changes: 20 additions & 22 deletions lambda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type LastScaleASGResult struct {
}

func main() {
if os.Getenv(`DEBUG`) != "" {
if os.Getenv("DEBUG") != "" {
_, err := Handler(context.Background(), json.RawMessage([]byte{}))
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -69,21 +69,21 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {
disableScaleOut, disableScaleIn bool
)

if v := os.Getenv(`LAMBDA_INTERVAL`); v != "" {
if v := os.Getenv("LAMBDA_INTERVAL"); v != "" {
if interval, err = time.ParseDuration(v); err != nil {
return "", err
}
}

if v := os.Getenv(`LAMBDA_TIMEOUT`); v != "" {
if v := os.Getenv("LAMBDA_TIMEOUT"); v != "" {
if timeoutDuration, err := time.ParseDuration(v); err != nil {
return "", err
} else {
timeout = time.After(timeoutDuration)
}
}

if v := os.Getenv(`ASG_ACTIVITY_TIMEOUT`); v != "" {
if v := os.Getenv("ASG_ACTIVITY_TIMEOUT"); v != "" {
if timeoutDuration, err := time.ParseDuration(v); err != nil {
return "", err
} else {
Expand All @@ -92,45 +92,45 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {
}
}

if v := os.Getenv(`SCALE_IN_COOLDOWN_PERIOD`); v != "" {
if v := os.Getenv("SCALE_IN_COOLDOWN_PERIOD"); v != "" {
if scaleInCooldownPeriod, err = time.ParseDuration(v); err != nil {
return "", err
}
}

if v := os.Getenv(`SCALE_IN_FACTOR`); v != "" {
if v := os.Getenv("SCALE_IN_FACTOR"); v != "" {
if scaleInFactor, err = strconv.ParseFloat(v, 64); err != nil {
return "", err
}
scaleInFactor = math.Abs(scaleInFactor)
}

if v := os.Getenv(`SCALE_ONLY_AFTER_ALL_EVENT`); v != "" {
if v := os.Getenv("SCALE_ONLY_AFTER_ALL_EVENT"); v != "" {
if v == "true" || v == "1" {
scaleOnlyAfterAllEvent = true
}
}

if v := os.Getenv(`SCALE_OUT_COOLDOWN_PERIOD`); v != "" {
if v := os.Getenv("SCALE_OUT_COOLDOWN_PERIOD"); v != "" {
if scaleOutCooldownPeriod, err = time.ParseDuration(v); err != nil {
return "", err
}
}

if v := os.Getenv(`SCALE_OUT_FACTOR`); v != "" {
if v := os.Getenv("SCALE_OUT_FACTOR"); v != "" {
if scaleOutFactor, err = strconv.ParseFloat(v, 64); err != nil {
return "", err
}
scaleOutFactor = math.Abs(scaleOutFactor)
}

if v := os.Getenv(`INCLUDE_WAITING`); v != "" {
if v := os.Getenv("INCLUDE_WAITING"); v != "" {
if v == "true" || v == "1" {
includeWaiting = true
}
}

if v := os.Getenv(`INSTANCE_BUFFER`); v != "" {
if v := os.Getenv("INSTANCE_BUFFER"); v != "" {
if instanceBuffer, err = strconv.Atoi(v); err != nil {
return "", err
}
Expand All @@ -144,17 +144,17 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {
}
}

if m := os.Getenv(`CLOUDWATCH_METRICS`); m == `true` || m == `1` {
if m := os.Getenv("CLOUDWATCH_METRICS"); m == "true" || m == "1" {
log.Printf("Publishing cloudwatch metrics")
publishCloudWatchMetrics = true
}

if m := os.Getenv(`DISABLE_SCALE_IN`); m == `true` || m == `1` {
if m := os.Getenv("DISABLE_SCALE_IN"); m == "true" || m == "1" {
log.Printf("Disabling scale-in 🙅🏼‍")
disableScaleIn = true
}

if m := os.Getenv(`DISABLE_SCALE_OUT`); m == `true` || m == `1` {
if m := os.Getenv("DISABLE_SCALE_OUT"); m == "true" || m == "1" {
log.Printf("Disabling scale-out 🙅🏼‍♂️")
disableScaleOut = true
}
Expand All @@ -181,7 +181,7 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {

// set last scale in and out from asg's activities
asg := &scaler.ASGDriver{
Name: mustGetEnv(`ASG_NAME`),
Name: mustGetEnv("ASG_NAME"),
Sess: sess,
MaxDescribeScalingActivitiesPages: maxDescribeScalingActivitiesPages,
}
Expand Down Expand Up @@ -238,7 +238,7 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {
case <-timeout:
return "", nil
default:
token := os.Getenv(`BUILDKITE_AGENT_TOKEN`)
token := os.Getenv("BUILDKITE_AGENT_TOKEN")
ssmTokenKey := os.Getenv("BUILDKITE_AGENT_TOKEN_SSM_KEY")

if ssmTokenKey != "" {
Expand All @@ -250,16 +250,14 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {
}

if token == "" {
return "", errors.New(
"Must provide either BUILDKITE_AGENT_TOKEN or BUILDKITE_AGENT_TOKEN_SSM_KEY",
)
return "", errors.New("Must provide either BUILDKITE_AGENT_TOKEN or BUILDKITE_AGENT_TOKEN_SSM_KEY")
}

client := buildkite.NewClient(token)
params := scaler.Params{
BuildkiteQueue: mustGetEnv(`BUILDKITE_QUEUE`),
AutoScalingGroupName: mustGetEnv(`ASG_NAME`),
AgentsPerInstance: mustGetEnvInt(`AGENTS_PER_INSTANCE`),
BuildkiteQueue: mustGetEnv("BUILDKITE_QUEUE"),
AutoScalingGroupName: mustGetEnv("ASG_NAME"),
AgentsPerInstance: mustGetEnvInt("AGENTS_PER_INSTANCE"),
IncludeWaiting: includeWaiting,
ScaleInParams: scaler.ScaleParams{
CooldownPeriod: scaleInCooldownPeriod,
Expand Down
6 changes: 3 additions & 3 deletions scaler/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func (s *Scaler) Run() (time.Duration, error) {

if s.metrics != nil {
err = s.metrics.Publish(metrics.OrgSlug, metrics.Queue, map[string]int64{
`ScheduledJobsCount`: metrics.ScheduledJobs,
`RunningJobsCount`: metrics.RunningJobs,
`WaitingJobsCount`: metrics.WaitingJobs,
"ScheduledJobsCount": metrics.ScheduledJobs,
"RunningJobsCount": metrics.RunningJobs,
"WaitingJobsCount": metrics.WaitingJobs,
})
if err != nil {
return metrics.PollDuration, err
Expand Down