Skip to content

Commit

Permalink
Region handling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
karlmutch committed Sep 7, 2021
1 parent a30c2cb commit d00871d
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ vendor/google.golang.org/protobuf/
reports_pb2.py
../../assets/response_catcher/__pycache__/
assets/response_catcher/__pycache__/
tools/queue-scaler/queue-scaler
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/Rhymond/go-money v1.0.3
github.com/awnumar/memguard v0.22.2
github.com/aws/aws-sdk-go v1.40.35
github.com/aws/aws-sdk-go v1.40.38
github.com/benbjohnson/clock v1.1.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.1
github.com/containerd/containerd v1.5.2 // indirect
Expand Down Expand Up @@ -48,7 +48,6 @@ require (
github.com/karlmutch/hashstructure v0.0.0-20170609045927-2bca23e0e452
github.com/karlmutch/k8s v1.2.1-0.20210224003752-d750059a3836
github.com/karlmutch/logxi v0.0.0-20210224194221-fde727bca873
github.com/karlmutch/petname v0.0.0-20190202005206-caff460d43c2 // indirect
github.com/karlmutch/vtclean v0.0.0-20170504063817-d14193dfc626
github.com/karlseguin/expect v1.0.7 // indirect
github.com/klauspost/compress v1.13.0 // indirect
Expand Down Expand Up @@ -84,7 +83,7 @@ require (
go.uber.org/goleak v1.1.10 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5 // indirect
golang.org/x/net v0.0.0-20210825183410-e898025ed96a
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f
golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67 // indirect
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZo
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.37.18/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go v1.40.34/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q=
github.com/aws/aws-sdk-go v1.40.35 h1:ofWh1LlWaSbOpAsl8EHlg96PZXqgCGKKi8YgrdU2Z+I=
github.com/aws/aws-sdk-go v1.40.35/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q=
github.com/aws/aws-sdk-go v1.40.38 h1:kl3iIW0h/JEBFjSBcAxDsiRbKMPz4aI5FJIHMCAQ+J0=
github.com/aws/aws-sdk-go v1.40.38/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
Expand Down Expand Up @@ -698,8 +698,6 @@ github.com/karlmutch/k8s v1.2.1-0.20210224003752-d750059a3836 h1:oFlTQlXP6WaC4OU
github.com/karlmutch/k8s v1.2.1-0.20210224003752-d750059a3836/go.mod h1:bWAFqAM5ZDNun7BlVB0UNRkyuJeEpLbPhnAUKK7L9jI=
github.com/karlmutch/logxi v0.0.0-20210224194221-fde727bca873 h1:4cKuMQt9iBZuZHVvRuQ3ZUtSoDqYPxq/3TgZ1DJG6H8=
github.com/karlmutch/logxi v0.0.0-20210224194221-fde727bca873/go.mod h1:dYJcwwfyf109t+z+3mpUuMp895YlXwdhCEVxvIC4mog=
github.com/karlmutch/petname v0.0.0-20190202005206-caff460d43c2 h1:SQguTo2lAaqLhJ697vBZgT2r1x1WWfGdBPDoZzc3dlg=
github.com/karlmutch/petname v0.0.0-20190202005206-caff460d43c2/go.mod h1:/1GvcbPg0Cy3vQRvXylThwwSO+H/hMBw1I8OKfPgGy8=
github.com/karlmutch/semver v1.4.0 h1:v43bB1hi6OKGnQqWvYUbJEczzcRFy3jACArCmbJp3zk=
github.com/karlmutch/semver v1.4.0/go.mod h1:8oXKArMTj8cC1gpagjlMgCfmKMSp58lI4L3M2GdadQs=
github.com/karlmutch/vtclean v0.0.0-20170504063817-d14193dfc626 h1:EgnDPsWgUfoSSFmyObFmydr6Lh12hOTibgiteblUuTg=
Expand Down Expand Up @@ -1303,8 +1301,9 @@ golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210825183410-e898025ed96a h1:bRuuGXV8wwSdGTB+CtJf+FjgO1APK1CoO39T4BN/XBw=
golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f h1:w6wWR0H+nyVpbSAQbzVEIACVyr/h8l/BEkY6Sokc7Eg=
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190319182350-c85d3e98c914/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
7 changes: 4 additions & 3 deletions licenses.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ docs/slides/lib/font/source-sans-pro,OFL-1.0-no-RFN,0.757377
examples/aws/aws,OpenSSL,0.7797131
examples/aws/aws/dist/cryptography-2.8-py3.7.egg-info,BSD-3-Clause-Clear,0.83412325
examples/aws/cpu,deprecated_GPL-2.0-with-bison-exception,0.33333334
examples/docker,FSFAP,0.33333334
examples/local,deprecated_GPL-2.0-with-classpath-exception,0.33333334
examples/docker,CC-BY-NC-ND-2.0,0.33333334
examples/local,CC-BY-NC-SA-2.0,0.33333334
vendor/cloud.google.com/go,SHL-0.5,0.85278857
vendor/github.com/Azure/go-autorest,ECL-2.0,0.83882034
vendor/github.com/Azure/go-autorest/autorest,ECL-2.0,0.83882034
Expand Down Expand Up @@ -119,7 +119,7 @@ vendor/github.com/pkg/errors,BSD-2-Clause-NetBSD,0.9076087
vendor/github.com/prometheus/client_golang,SHL-0.5,0.85278857
vendor/github.com/prometheus/client_model,SHL-0.5,0.85278857
vendor/github.com/prometheus/common,SHL-0.5,0.85278857
vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg,NOSL,0.33333334
vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg,FSFAP,0.33333334
vendor/github.com/prometheus/procfs,SHL-0.5,0.85278857
vendor/github.com/prometheus/prom2json,SHL-0.5,0.85278857
vendor/github.com/rs/xid,MIT-0,0.8125
Expand Down Expand Up @@ -175,6 +175,7 @@ vendor/k8s.io/client-go,SHL-0.5,0.85278857
vendor/k8s.io/klog/v2,SHL-0.5,0.8657289
vendor/k8s.io/utils,SHL-0.5,0.85278857
vendor/sigs.k8s.io/structured-merge-diff/v4,SHL-0.5,0.85214007
L-0.5,0.85214007
214007
89
vendor/gopkg.in/neurosnap/sentences.v1,MIT-0,0.81595093
Expand Down
12 changes: 11 additions & 1 deletion tools/queue-scaler/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func NewSession(ctx context.Context, cfg *Config) (sess *session.Session, err kv
if errGo != nil {
return nil, kv.Wrap(errGo).With("stack", stack.Trace().TrimRuntime())
}

if len(cfg.region) == 0 {
if sess.Config.Region != nil {
cfg.region = *sess.Config.Region
}
}

return sess, nil
}

Expand Down Expand Up @@ -210,7 +217,7 @@ func ec2Instances(ctx context.Context, cfg *Config, sess *session.Session, statu
logger.Debug("getting pricing, this takes a few moments", "region", cfg.region, "stack", stack.Trace().TrimRuntime())
pricing, errGo := price.NewPricing(cfg.region)
if errGo != nil {
return nil, kv.Wrap(errGo).With("stack", stack.Trace().TrimRuntime())
return nil, kv.Wrap(errGo).With("region", cfg.region).With("stack", stack.Trace().TrimRuntime())
}

instances = []instanceDetails{}
Expand All @@ -220,6 +227,9 @@ func ec2Instances(ctx context.Context, cfg *Config, sess *session.Session, statu

prices := map[string]*price.Instance{}
detail, errGo := pricing.GetInstances(cfg.region)
if errGo != nil {
return nil, kv.Wrap(errGo).With("region", cfg.region).With("stack", stack.Trace().TrimRuntime())
}

for _, instance := range detail {
prices[instance.Type] = instance
Expand Down
3 changes: 3 additions & 0 deletions tools/queue-scaler/queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ func listQueues(ctx context.Context, cfg *Config, sess *session.Session, selectQ
}

if err = qMetrics(ctx, svc, &getOpts, q, &status); err != nil {
logger.Trace("queue ", name, err.Error())
return false
}

// Examine the first message if available for information
// as to how much hardware resource is needed for this
// queue
if err = qResources(ctx, cfg, svc, *q, &status); err != nil {
logger.Trace("queue ", name, err.Error())
return false
}

Expand All @@ -87,6 +89,7 @@ func listQueues(ctx context.Context, cfg *Config, sess *session.Session, selectQ
if status.Resource != nil {
costs, err := ec2Instances(ctx, cfg, sess, &status)
if err != nil {
logger.Trace("queue ", name, err.Error())
return false
}
status.Instances = costs
Expand Down
19 changes: 19 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/aws/endpoints/defaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/aws/aws-sdk-go/aws/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/golang.org/x/net/http2/errors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/golang.org/x/net/http2/frame.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions vendor/golang.org/x/net/http2/transport.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ github.com/awnumar/memcall
## explicit
github.com/awnumar/memguard
github.com/awnumar/memguard/core
# github.com/aws/aws-sdk-go v1.40.35
# github.com/aws/aws-sdk-go v1.40.38
## explicit
github.com/aws/aws-sdk-go/aws
github.com/aws/aws-sdk-go/aws/awserr
Expand Down Expand Up @@ -650,7 +650,7 @@ golang.org/x/crypto/ssh/knownhosts
# golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5
## explicit
golang.org/x/exp/rand
# golang.org/x/net v0.0.0-20210825183410-e898025ed96a
# golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f
## explicit
golang.org/x/net/context
golang.org/x/net/context/ctxhttp
Expand Down

0 comments on commit d00871d

Please sign in to comment.