Skip to content

Commit

Permalink
feat: aws cloudformationstack health (#62)
Browse files Browse the repository at this point in the history
* feat: aws cloudformationstack health

* chore: return aws status as they are


Co-authored-by: Moshe Immerman <moshe@flanksource.com>
  • Loading branch information
adityathebe and moshloop authored Jul 3, 2024
1 parent 6527595 commit 921c352
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 69 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/gobwas/glob v0.2.3
github.com/samber/lo v1.44.0
github.com/stretchr/testify v1.8.4
github.com/yuin/gopher-lua v1.1.0
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -23,7 +24,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/text v0.16.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/samber/lo v1.44.0 h1:5il56KxRE+GHsm1IR+sZ/6J42NODigFiqCWpSc2dybA=
github.com/samber/lo v1.44.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
Expand Down Expand Up @@ -166,8 +168,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down
160 changes: 95 additions & 65 deletions pkg/health/health_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ package health

import (
"strings"

"github.com/samber/lo"
)

const (
AWSResourceTypeEBS string = "ebs"
AWSResourceTypeEC2 string = "ec2"
AWSResourceTypeEKS string = "eks"
AWSResourceTypeELB string = "elb"
AWSResourceTypeRDS string = "rds"
AWSResourceTypeVPC string = "vpc"
AWSResourceTypeSubnet string = "subnet"
AWSResourceTypeEBS string = "ebs"
AWSResourceTypeEC2 string = "ec2"
AWSResourceTypeEKS string = "eks"
AWSResourceTypeELB string = "elb"
AWSResourceTypeRDS string = "rds"
AWSResourceTypeVPC string = "vpc"
AWSResourceTypeSubnet string = "subnet"
AWSResourceTypeCloudformationStack string = "cloudformationstack"
)

func GetAWSResourceHealth(resourceType, status string) (health HealthStatus) {
if resourceStatuses, found := awsResourceHealthmap[resourceType]; found {
if v, found := resourceStatuses[strings.ToLower(status)]; found {
v.Status = HealthStatusCode(lo.Capitalize(strings.ReplaceAll(strings.ReplaceAll(status, "-", " "), "_", " ")))
return v
}
}
Expand All @@ -29,83 +33,109 @@ func GetAWSResourceHealth(resourceType, status string) (health HealthStatus) {
}

var awsResourceHealthmap = map[string]map[string]HealthStatus{
AWSResourceTypeCloudformationStack: {
"create_complete": HealthStatus{Health: HealthHealthy, Ready: true},
"create_failed": HealthStatus{Health: HealthUnhealthy, Ready: true},
"create_in_progress": HealthStatus{Health: HealthUnknown},
"delete_complete": HealthStatus{Health: HealthUnknown, Ready: true},
"delete_failed": HealthStatus{Health: HealthUnhealthy, Ready: true},
"delete_in_progress": HealthStatus{Health: HealthUnknown},
"import_complete": HealthStatus{Health: HealthHealthy, Ready: true},
"import_in_progress": HealthStatus{Health: HealthUnknown},
"import_rollback_complete": HealthStatus{Health: HealthWarning, Ready: true},
"import_rollback_failed": HealthStatus{Health: HealthUnhealthy, Ready: true},
"import_rollback_in_progress": HealthStatus{Health: HealthWarning},
"review_in_progress": HealthStatus{Health: HealthUnknown},
"rollback_complete": HealthStatus{Health: HealthWarning, Ready: true},
"rollback_failed": HealthStatus{Health: HealthUnhealthy, Ready: true},
"rollback_in_progress": HealthStatus{Health: HealthWarning},
"update_complete_cleanup_in_progress": HealthStatus{Health: HealthUnknown},
"update_complete": HealthStatus{Health: HealthHealthy, Ready: true},
"update_failed": HealthStatus{Health: HealthUnhealthy, Ready: true},
"update_in_progress": HealthStatus{Health: HealthUnknown},
"update_rollback_complete_cleanup_in_progress": HealthStatus{Health: HealthUnknown},
"update_rollback_complete": HealthStatus{Health: HealthWarning, Ready: true},
"update_rollback_failed": HealthStatus{Health: HealthUnhealthy, Ready: true},
"update_rollback_in_progress": HealthStatus{Health: HealthWarning},
},

AWSResourceTypeEC2: {
"pending": HealthStatus{Status: HealthStatusPending, Health: HealthUnknown},
"running": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"shutting-down": HealthStatus{Status: HealthStatusDeleting, Health: HealthUnknown},
"stopped": HealthStatus{Status: HealthStatusStopped, Health: HealthUnknown},
"stopping": HealthStatus{Status: HealthStatusStopping, Health: HealthUnknown},
"terminated": HealthStatus{Status: HealthStatusDeleted, Health: HealthUnknown},
"pending": HealthStatus{Health: HealthUnknown},
"running": HealthStatus{Health: HealthHealthy, Ready: true},
"shutting-down": HealthStatus{Health: HealthUnknown},
"stopped": HealthStatus{Health: HealthUnknown, Ready: true},
"stopping": HealthStatus{Health: HealthUnknown},
"terminated": HealthStatus{Health: HealthUnknown, Ready: true},
},

AWSResourceTypeEKS: {
"creating": HealthStatus{Status: HealthStatusCreating, Health: HealthUnknown},
"active": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"deleting": HealthStatus{Status: HealthStatusDeleting, Health: HealthUnknown},
"failed": HealthStatus{Status: HealthStatusError, Health: HealthUnhealthy},
"updating": HealthStatus{Status: HealthStatusUpdating, Health: HealthUnknown},
"pending": HealthStatus{Status: HealthStatusPending, Health: HealthUnknown},
"creating": HealthStatus{Health: HealthUnknown},
"active": HealthStatus{Health: HealthHealthy, Ready: true},
"deleting": HealthStatus{Health: HealthUnknown},
"failed": HealthStatus{Health: HealthUnhealthy, Ready: true},
"updating": HealthStatus{Health: HealthUnknown},
"pending": HealthStatus{Health: HealthUnknown},
},

AWSResourceTypeEBS: {
"creating": HealthStatus{Status: HealthStatusCreating, Health: HealthUnknown},
"available": HealthStatus{Status: HealthStatusStopped, Health: HealthHealthy, Ready: true},
"in-use": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"deleting": HealthStatus{Status: HealthStatusDeleting, Health: HealthUnknown},
"deleted": HealthStatus{Status: HealthStatusDeleted, Health: HealthUnknown},
"error": HealthStatus{Status: HealthStatusError, Health: HealthUnhealthy},
"creating": HealthStatus{Health: HealthUnknown},
"available": HealthStatus{Health: HealthHealthy, Ready: true},
"in-use": HealthStatus{Health: HealthHealthy, Ready: true},
"deleting": HealthStatus{Health: HealthUnknown},
"deleted": HealthStatus{Health: HealthUnknown, Ready: true},
"error": HealthStatus{Health: HealthUnhealthy, Ready: true},
},

// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/accessing-monitoring.html
AWSResourceTypeRDS: {
"available": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"billed": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"backing-up": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"configuring-enhanced-monitoring": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"configuring-iam-database-auth": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"configuring-log-exports": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"converting-to-vpc": HealthStatus{Status: HealthStatusUpdating, Health: HealthHealthy, Ready: true},
"creating": HealthStatus{Status: HealthStatusCreating, Health: HealthUnknown},
"delete-precheck": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy, Ready: true},
"deleting": HealthStatus{Status: HealthStatusDeleting, Health: HealthUnknown},
"failed": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"inaccessible-encryption-credentials": HealthStatus{Status: HealthStatusInaccesible, Health: HealthUnhealthy},
"inaccessible-encryption-credentials-recoverable": HealthStatus{Status: HealthStatusInaccesible, Health: HealthWarning},
"incompatible-network": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"incompatible-option-group": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"incompatible-parameters": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"incompatible-restore": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"insufficient-capacity": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"maintenance": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"modifying": HealthStatus{Status: HealthStatusUpdating, Health: HealthHealthy, Ready: true},
"moving-to-vpc": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy},
"rebooting": HealthStatus{Status: HealthStatusRestart, Health: HealthHealthy},
"resetting-master-credentials": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy, Ready: true},
"renaming": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy, Ready: true},
"restore-error": HealthStatus{Status: HealthStatusError, Health: HealthUnhealthy},
"starting": HealthStatus{Status: HealthStatusStarting, Health: HealthUnknown},
"stopped": HealthStatus{Status: HealthStatusStopped, Health: HealthHealthy},
"stopping": HealthStatus{Status: HealthStatusStopping, Health: HealthUnknown},
"storage-config-upgrade": HealthStatus{Status: HealthStatusUpdating, Health: HealthHealthy, Ready: true},
"storage-full": HealthStatus{Status: HealthStatusUnhealthy, Health: HealthUnhealthy},
"storage-optimization": HealthStatus{Status: HealthStatusMaintenance, Health: HealthHealthy, Ready: true},
"upgrading": HealthStatus{Status: HealthStatusUpdating, Health: HealthHealthy},
"available": HealthStatus{Health: HealthHealthy, Ready: true},
"billed": HealthStatus{Health: HealthHealthy, Ready: true},
"backing-up": HealthStatus{Health: HealthHealthy},
"configuring-enhanced-monitoring": HealthStatus{Health: HealthHealthy},
"configuring-iam-database-auth": HealthStatus{Health: HealthHealthy},
"configuring-log-exports": HealthStatus{Health: HealthHealthy},
"converting-to-vpc": HealthStatus{Health: HealthHealthy, Ready: true},
"creating": HealthStatus{Health: HealthUnknown},
"delete-precheck": HealthStatus{Health: HealthHealthy},
"deleting": HealthStatus{Health: HealthUnknown},
"failed": HealthStatus{Health: HealthUnhealthy, Ready: true},
"inaccessible-encryption-credentials": HealthStatus{Health: HealthUnhealthy, Ready: true},
"inaccessible-encryption-credentials-recoverable": HealthStatus{Health: HealthWarning, Ready: true},
"incompatible-network": HealthStatus{Health: HealthUnhealthy, Ready: true},
"incompatible-option-group": HealthStatus{Health: HealthUnhealthy, Ready: true},
"incompatible-parameters": HealthStatus{Health: HealthUnhealthy, Ready: true},
"incompatible-restore": HealthStatus{Health: HealthUnhealthy, Ready: true},
"insufficient-capacity": HealthStatus{Health: HealthUnhealthy, Ready: true},
"maintenance": HealthStatus{Health: HealthHealthy},
"modifying": HealthStatus{Health: HealthHealthy, Ready: true},
"moving-to-vpc": HealthStatus{Health: HealthHealthy},
"rebooting": HealthStatus{Health: HealthHealthy},
"resetting-master-credentials": HealthStatus{Health: HealthHealthy},
"renaming": HealthStatus{Health: HealthHealthy},
"restore-error": HealthStatus{Health: HealthUnhealthy, Ready: true},
"starting": HealthStatus{Health: HealthUnknown},
"stopped": HealthStatus{Health: HealthHealthy, Ready: true},
"stopping": HealthStatus{Health: HealthUnknown},
"storage-config-upgrade": HealthStatus{Health: HealthHealthy},
"storage-full": HealthStatus{Health: HealthUnhealthy},
"storage-optimization": HealthStatus{Health: HealthHealthy},
"upgrading": HealthStatus{Health: HealthHealthy},
},

AWSResourceTypeELB: {
"active": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"provisioning": HealthStatus{Status: HealthStatusCreating, Health: HealthUnknown},
"active_impaired": HealthStatus{Status: HealthStatusWarning, Health: HealthWarning, Ready: true},
"failed": HealthStatus{Status: HealthStatusError, Health: HealthUnhealthy},
"active": HealthStatus{Health: HealthHealthy, Ready: true},
"provisioning": HealthStatus{Health: HealthUnknown},
"active_impaired": HealthStatus{Health: HealthWarning, Ready: true},
"failed": HealthStatus{Health: HealthUnhealthy, Ready: true},
},

AWSResourceTypeVPC: {
"pending": HealthStatus{Status: HealthStatusPending, Health: HealthUnknown},
"available": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"pending": HealthStatus{Health: HealthUnknown},
"available": HealthStatus{Health: HealthHealthy, Ready: true},
},

AWSResourceTypeSubnet: {
"pending": HealthStatus{Status: HealthStatusPending, Health: HealthUnknown},
"available": HealthStatus{Status: HealthStatusHealthy, Health: HealthHealthy, Ready: true},
"pending": HealthStatus{Health: HealthUnknown},
"available": HealthStatus{Health: HealthHealthy, Ready: true},
},
}
7 changes: 6 additions & 1 deletion pkg/health/health_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestMapAWSStatus(t *testing.T) {
{
name: "ec2",
args: args{status: "shutting-down", resourceType: AWSResourceTypeEC2},
want: HealthStatusDeleting,
want: "Shutting Down",
},
{
name: "unknown resource",
Expand All @@ -27,6 +27,11 @@ func TestMapAWSStatus(t *testing.T) {
args: args{status: "wakingup", resourceType: AWSResourceTypeEC2},
want: HealthStatusUnknown,
},
{
name: "cloudformation",
args: args{status: "import_rollback_complete", resourceType: AWSResourceTypeCloudformationStack},
want: HealthStatusCode("Import Rollback Complete"),
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 921c352

Please sign in to comment.