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

Add Spot/On-demand price to table-wide output irrespective of the price filters #106

Merged
merged 15 commits into from
Nov 15, 2021

Conversation

mdb
Copy link
Contributor

@mdb mdb commented Nov 4, 2021

This seeks to address issue #71 . It features the original changes submitted by @krishna-birla in the unmerged (and perhaps abandoned?) PR #78 , but also layers in the outstanding changes requested by @bwagner5 in code review.

Note, however, that it doesn't yet tackle this potential issue pointed out by @krishna-birla, nor does it dramatically change @krishna-birla's original implementation.

...this is currently a draft PR to surface visibility among the amazon-ec2-instance-selector maintainers and perhaps get some early feedback on what remaining work is necessary to get this to a mergeable state.

Thanks!

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Krishna Birla and others added 7 commits March 6, 2021 10:12
* remove the importing of un-used Lightsail packages, as [requested by @bwagner](aws#78 (comment))
* move non-standard lib imports to their own stanza, as [requested by @bwagner](aws#78 (comment))

Signed-off-by: Mike Ball <[email protected]>
This was requested by @bwagner here:
aws#78 (comment)

Signed-off-by: Mike Ball <[email protected]>
Per code review from @bwagner, this renames various
methods and fields to be `*CacheUTC` rather than `*CachedUTC`:
aws#78 (comment)
Previously, `selector` was incorrectly using the old
`LastSpotCachedUTC` method name.
Copy link
Contributor

@bwagner5 bwagner5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking nice! Thanks for picking this up! I haven't checked it out and taken it for a test drive yet, but the code looks good.

pkg/ec2pricing/ec2pricing.go Outdated Show resolved Hide resolved
pkg/ec2pricing/ec2pricing.go Outdated Show resolved Hide resolved
pkg/ec2pricing/ec2pricing.go Outdated Show resolved Hide resolved
@bwagner5
Copy link
Contributor

bwagner5 commented Nov 4, 2021

Looks like go mod tidy needs to be run.

mdb added 4 commits November 4, 2021 11:26
This is now fixed, as the Pricing client is always initialized to us-east-1.

Signed-off-by: Mike Ball <[email protected]>
Per [code review feedback](aws#106 (comment)), the error checking
should appear within the `range pricingOutput.PriceList`.

Signed-off-by: Mike Ball <[email protected]>
This issue is now resolved.

Signed-off-by: Mike Ball <[email protected]>
@mdb mdb requested a review from bwagner5 November 4, 2021 15:32
mdb added 3 commits November 5, 2021 10:54
This protects against panics like the following, for example:

```
--- FAIL: TestFilter_X8664_AMD64 (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x153ec41]

goroutine 153 [running]:
testing.tRunner.func1.2({0x1613ee0, 0x1cdfe70})
        /usr/local/Cellar/go/1.17.2/libexec/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
        /usr/local/Cellar/go/1.17.2/libexec/src/testing/testing.go:1212 +0x218
panic({0x1613ee0, 0x1cdfe70})
        /usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038 +0x215
github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector.Selector.rawFilter.func1(0x100e6e7, 0x68)
        /Users/mball/dev/go/src/github.com/aws/amazon-ec2-instance-selector/pkg/selector/selector.go:192 +0x241
github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector_test.mockedEC2.DescribeInstanceTypesPages(...)
        /Users/mball/dev/go/src/github.com/aws/amazon-ec2-instance-selector/pkg/selector/selector_test.go:70
github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector.Selector.rawFilter({{_, _}, {_, _}, {_}}, {0x0, 0x0, 0x0, 0xc0003854a0, 0x0, ...})
        /Users/mball/dev/go/src/github.com/aws/amazon-ec2-instance-selector/pkg/selector/selector.go:184 +0x5c2
github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector.Selector.FilterWithOutput({{_, _}, {_, _}, {_}}, {0x0, 0x0, 0x0, 0xc0003854a0, 0x0, ...}, ...)
        /Users/mball/dev/go/src/github.com/aws/amazon-ec2-instance-selector/pkg/selector/selector.go:116 +0xc5
github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector.Selector.Filter({{_, _}, {_, _}, {_}}, {0x0, 0x0, 0x0, 0xc0003854a0, 0x0, ...})
        /Users/mball/dev/go/src/github.com/aws/amazon-ec2-instance-selector/pkg/selector/selector.go:98 +0xcc
github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector_test.TestFilter_X8664_AMD64(0xc0002de820)
        /Users/mball/dev/go/src/github.com/aws/amazon-ec2-instance-selector/pkg/selector/selector_test.go:583 +0x14e
testing.tRunner(0xc00059b520, 0x177e1b0)
        /usr/local/Cellar/go/1.17.2/libexec/src/testing/testing.go:1259 +0x102
created by testing.(*T).Run
        /usr/local/Cellar/go/1.17.2/libexec/src/testing/testing.go:1306 +0x35a
exit status 2
```

Signed-off-by: Mike Ball <[email protected]>
This seeks to make the specifics of test failures a bit more clear.

Signed-off-by: Mike Ball <[email protected]>
This addresses the following:

```
$ make unit-test
go test -bench=. /Users/mball/dev/go/src/github.com/aws/amazon-ec2-instance-selector//...  -v -coverprofile=coverage.out -covermode=atomic -outputdir=/Users/mball/dev/go/src/github.com/aws/amazon-ec2-instance-selector//build
go: updates to go.mod needed; to update it:
        go mod tidy
make: *** [unit-test] Error 1
```

Signed-off-by: Mike Ball <[email protected]>
@bwagner5
Copy link
Contributor

bwagner5 commented Nov 5, 2021

looks like some unit-tests are failing having to do with pricing:

=== RUN   TestFilter_PricePerHour
selector_test.go:662: Should return 1 instance type; got 0

--- FAIL: TestFilter_PricePerHour (0.00s)
=== RUN   TestFilter_PricePerHour_NoResults
--- PASS: TestFilter_PricePerHour_NoResults (0.00s)
=== RUN   TestFilter_PricePerHour_OD
selector_test.go:701: Should return 1 instance type; got 0

--- FAIL: TestFilter_PricePerHour_OD (0.00s)
=== RUN   TestFilter_PricePerHour_Spot
selector_test.go:721: Should return 1 instance type; got 0

By populating the `lastOnDemandCacheUTC` and `lastSpotCacheUTC`
fields with non-`nil` values, the `Filter` tests exercise relevant
code paths.

Note that this doesn't change @krishna-birla's original implementation
(see PR aws#78) or vision; it only ensures the tests pass.

Signed-off-by: Mike Ball <[email protected]>
@mdb mdb marked this pull request as ready for review November 6, 2021 11:01
itf := selector.Selector{
EC2: ec2Mock,
EC2Pricing: &ec2PricingMock{
GetOndemandInstanceTypeCostResp: 0.0104,
lastOnDemandCacheUTC: &now,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ By ensuring the *CacheUTC field(s) are populated with a non-nil value, the tests exercise relevant code paths in selector.rawFilter.

@bwagner5
Copy link
Contributor

bwagner5 commented Nov 9, 2021

It looks like something isn't working quite right. I pulled the code down today and did a table-wide run and no prices were output. I haven't had a chance to dive any deeper.

./ec2-instance-selector -o table-wide
Instance Type  VCPUs   Mem (GiB)  Hypervisor  Current Gen  Hibernation Support  CPU Arch  Network Performance  ENIs    GPUs    GPU Mem (GiB)  GPU Info  On-Demand Price/Hr  Spot Price/Hr (30d avg)
-------------  -----   ---------  ----------  -----------  -------------------  --------  -------------------  ----    ----    -------------  --------  ------------------  -----------------------
a1.2xlarge     8       16         nitro       false        false                arm64     Up to 10 Gigabit     4       0       0                        -Not Fetched-       -Not Fetched-
a1.4xlarge     16      32         nitro       false        false                arm64     Up to 10 Gigabit     8       0       0                        -Not Fetched-       -Not Fetched-
a1.large       2       4          nitro       false        false                arm64     Up to 10 Gigabit     3       0       0                        -Not Fetched-       -Not Fetched-
a1.medium      1       2          nitro       false        false                arm64     Up to 10 Gigabit     2       0       0                        -Not Fetched-       -Not Fetched-
a1.metal       16      32         none        false        false                arm64     Up to 10 Gigabit     8       0       0                        -Not Fetched-       -Not Fetched-
a1.xlarge      4       8          nitro       false        false                arm64     Up to 10 Gigabit     4       0       0                        -Not Fetched-       -Not Fetched-
c4.2xlarge     8       15         xen         true         true                 x86_64    High                 4       0       0                        -Not Fetched-       -Not Fetched-
c4.4xlarge     16      30         xen         true         true                 x86_64    High                 8       0       0                        -Not Fetched-       -Not Fetched-
c4.8xlarge     36      60         xen         true         true                 x86_64    10 Gigabit           8       0       0                        -Not Fetched-       -Not Fetched-
c4.large       2       3.75       xen         true         true                 x86_64    Moderate             3       0       0                        -Not Fetched-       -Not Fetched-
c4.xlarge      4       7.5        xen         true         true                 x86_64    High                 4       0       0                        -Not Fetched-       -Not Fetched-
c5.12xlarge    48      96         nitro       true         true                 x86_64    12 Gigabit           8       0       0                        -Not Fetched-       -Not Fetched-
c5.18xlarge    72      144        nitro       true         true                 x86_64    25 Gigabit           15      0       0                        -Not Fetched-       -Not Fetched-
c5.24xlarge    96      192        nitro       true         false                x86_64    25 Gigabit           15      0       0                        -Not Fetched-       -Not Fetched-
c5.2xlarge     8       16         nitro       true         true                 x86_64    Up to 10 Gigabit     4       0       0                        -Not Fetched-       -Not Fetched-
c5.4xlarge     16      32         nitro       true         true                 x86_64    Up to 10 Gigabit     8       0       0                        -Not Fetched-       -Not Fetched-
c5.9xlarge     36      72         nitro       true         true                 x86_64    10 Gigabit           8       0       0                        -Not Fetched-       -Not Fetched-
c5.large       2       4          nitro       true         true                 x86_64    Up to 10 Gigabit     3       0       0                        -Not Fetched-       -Not Fetched-
c5.metal       96      192        none        true         false                x86_64    25 Gigabit           15      0       0                        -Not Fetched-       -Not Fetched-
c5.xlarge      4       8          nitro       true         true                 x86_64    Up to 10 Gigabit     4       0       0                        -Not Fetched-       -Not Fetched-
NOTE: 362 entries were truncated, increase --max-results to see more

@mdb
Copy link
Contributor Author

mdb commented Nov 13, 2021

It looks like something isn't working quite right.

@bwagner5 Thanks for looking. It appears to work for me using a fresh binary compiled via make compile -- is it possible one of us is confused?

$ ./build/ec2-instance-selector -o table-wide --region us-east-1

Instance Type  VCPUs   Mem (GiB)  Hypervisor  Current Gen  Hibernation Support  CPU Arch      Network Performance  ENIs    GPUs    GPU Mem (GiB)  GPU Info  On-Demand Price/Hr  Spot Price/Hr (30d avg)
-------------  -----   ---------  ----------  -----------  -------------------  --------      -------------------  ----    ----    -------------  --------  ------------------  -----------------------
a1.2xlarge     8       16         nitro       false        false                arm64         Up to 10 Gigabit     4       0       0                        $0.204              $0.0671
a1.4xlarge     16      32         nitro       false        false                arm64         Up to 10 Gigabit     8       0       0                        $0.408              $0.1343
a1.large       2       4          nitro       false        false                arm64         Up to 10 Gigabit     3       0       0                        $0.051              $0.02047
a1.medium      1       2          nitro       false        false                arm64         Up to 10 Gigabit     2       0       0                        $0.0255             $0.00841
a1.metal       16      32         none        false        false                arm64         Up to 10 Gigabit     8       0       0                        $0.408              $0.1343
a1.xlarge      4       8          nitro       false        false                arm64         Up to 10 Gigabit     4       0       0                        $0.102              $0.03386
c1.medium      2       1.69922    xen         false        false                i386, x86_64  Moderate             2       0       0                        $0.13               $0.013
c1.xlarge      8       7          xen         false        false                x86_64        High                 4       0       0                        $0.52               $0.23213
c3.2xlarge     8       15         xen         false        true                 x86_64        High                 4       0       0                        $0.42               $0.12853
c3.4xlarge     16      30         xen         false        true                 x86_64        High                 8       0       0                        $0.84               $0.28717
c3.8xlarge     32      60         xen         false        true                 x86_64        10 Gigabit           8       0       0                        $1.68               $0.54466
c3.large       2       3.75       xen         false        true                 i386, x86_64  Moderate             3       0       0                        $0.105              $0.0294
c3.xlarge      4       7.5        xen         false        true                 x86_64        Moderate             4       0       0                        $0.21               $0.05902
c4.2xlarge     8       15         xen         true         true                 x86_64        High                 4       0       0                        $0.398              $0.20069
c4.4xlarge     16      30         xen         true         true                 x86_64        High                 8       0       0                        $0.796              $0.27595
c4.8xlarge     36      60         xen         true         true                 x86_64        10 Gigabit           8       0       0                        $1.591              $0.66631
c4.large       2       3.75       xen         true         true                 x86_64        Moderate             3       0       0                        $0.1                $0.03453
c4.xlarge      4       7.5        xen         true         true                 x86_64        High                 4       0       0                        $0.199              $0.07209
c5.12xlarge    48      96         nitro       true         true                 x86_64        12 Gigabit           8       0       0                        $2.04               $0.82979
c5.18xlarge    72      144        nitro       true         true                 x86_64        25 Gigabit           15      0       0                        $3.06               $1.29916

@bwagner5
Copy link
Contributor

You're right, I was definitely the one confused :) I guess I was testing an old binary before... anyways LGTM! Thanks!

Copy link
Contributor

@bwagner5 bwagner5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants