Skip to content

Commit

Permalink
[#3677] Add on_demand and spot instance count for telemetry
Browse files Browse the repository at this point in the history
### What is the feature/fix?

https://app.asana.com/0/1203637156732418/1204423756010922/f

### Add screenshot or video (optional)

### Does it has a breaking change?

no

### How to use/test it?

### Checklist
- [ ] New coverage tests
- [ ] Unit tests passing
- [ ] E2E tests passing
- [ ] E2E downgrade/update test passing
- [ ] Documentation updated
- [ ] No warnings or errors on Deepsource/Codecov
  • Loading branch information
Twsouza committed May 22, 2023
1 parent f02c01c commit 9962eff
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions provider/aws/workers_heartbeat.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package aws

import (
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/convox/logger"
"github.com/convox/rack/pkg/helpers"
)
Expand All @@ -26,15 +29,45 @@ func (p *Provider) heartbeat() {
return
}

req := &ec2.DescribeInstancesInput{
Filters: []*ec2.Filter{
{Name: aws.String("tag:Rack"), Values: []*string{aws.String(p.Rack)}},
{Name: aws.String("tag:aws:cloudformation:logical-id"), Values: []*string{aws.String("Instances"), aws.String("SpotInstances")}},
{Name: aws.String("instance-state-name"), Values: []*string{aws.String("pending"), aws.String("running"), aws.String("shutting-down"), aws.String("stopping")}},
},
}

onDemandCnt := 0
spotCnt := 0

err = p.ec2().DescribeInstancesPages(req, func(res *ec2.DescribeInstancesOutput, last bool) bool {
for _, r := range res.Reservations {
for _, i := range r.Instances {
if i.InstanceLifecycle != nil && strings.ToLower(*i.InstanceLifecycle) == "spot" {
spotCnt++
} else {
onDemandCnt++
}
}
}
return true
})
if err != nil {
log.Error(err)
return
}

ms := map[string]interface{}{
"id": coalesces(p.ClientId, p.StackId),
"app_count": len(as),
"instance_count": s.Count,
"instance_type": s.Type,
"provider": "aws",
"rack_id": p.StackId,
"region": p.Region,
"version": s.Version,
"id": coalesces(p.ClientId, p.StackId),
"app_count": len(as),
"instance_count": s.Count,
"instance_type": s.Type,
"provider": "aws",
"rack_id": p.StackId,
"region": p.Region,
"version": s.Version,
"on_demand_instance_count": onDemandCnt,
"spot_instance_count": spotCnt,
}

telemetryOn := s.Parameters["Telemetry"] == "true"
Expand Down

0 comments on commit 9962eff

Please sign in to comment.