Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
blentz committed Nov 18, 2022
1 parent 06e1975 commit 00d4a7b
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 84 deletions.
19 changes: 10 additions & 9 deletions aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (

"golang.org/x/time/rate"

"github.com/hortonworks/cloud-haunter/utils"
"github.com/aws/aws-sdk-go/service/cloudformation"
elb "github.com/aws/aws-sdk-go/service/elbv2"
"github.com/hortonworks/cloud-haunter/utils"

ctx "github.com/hortonworks/cloud-haunter/context"
"github.com/hortonworks/cloud-haunter/types"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
Expand All @@ -27,8 +29,6 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/rds"
ctx "github.com/hortonworks/cloud-haunter/context"
"github.com/hortonworks/cloud-haunter/types"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -1913,17 +1913,18 @@ func newStack(stack *cloudformation.Stack, region string) *types.Stack {

// The low byte represents the state. The high byte is an opaque internal value
// and should be ignored.
// * 0 : pending
//
// * 16 : running
// - 0 : pending
//
// - 16 : running
//
// * 32 : shutting-down
// - 32 : shutting-down
//
// * 48 : terminated
// - 48 : terminated
//
// * 64 : stopping
// - 64 : stopping
//
// * 80 : stopped
// - 80 : stopped
func getInstanceState(instance *ec2.Instance) types.State {
if instance.State == nil {
return types.Unknown
Expand Down
4 changes: 2 additions & 2 deletions aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"time"

ctx "github.com/hortonworks/cloud-haunter/context"
"github.com/hortonworks/cloud-haunter/types"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/cloudtrail"
Expand All @@ -13,8 +15,6 @@ import (
elb "github.com/aws/aws-sdk-go/service/elbv2"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/rds"
ctx "github.com/hortonworks/cloud-haunter/context"
"github.com/hortonworks/cloud-haunter/types"
"github.com/stretchr/testify/assert"
)

Expand Down
16 changes: 9 additions & 7 deletions azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,15 @@ func getScaleSetInstanceState(view compute.VirtualMachineScaleSetVMInstanceView)
}

// Possible values:
// "PowerState/deallocated"
// "PowerState/deallocating"
// "PowerState/running"
// "PowerState/starting"
// "PowerState/stopped"
// "PowerState/stopping"
// "PowerState/unknown"
//
// "PowerState/deallocated"
// "PowerState/deallocating"
// "PowerState/running"
// "PowerState/starting"
// "PowerState/stopped"
// "PowerState/stopping"
// "PowerState/unknown"
//
// The assumption is that the status without time is the currently active status
func convertViewStatusToState(actualStatus compute.InstanceViewStatus) types.State {
switch *actualStatus.Code {
Expand Down
1 change: 1 addition & 0 deletions filter/longrunning.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (f longRunning) Execute(items []types.CloudItem) []types.CloudItem {
case types.Alert:
if item.GetItem().(types.Alert).State != types.Unused {
log.Debugf("[LONGRUNNING] Filter alert, because it's in used state: %s", item.GetName())
}
case types.Cluster:
if item.GetItem().(types.Cluster).State != types.Running {
log.Debugf("[LONGRUNNING] Filter instance, because it's not in RUNNING state: %s", item.GetName())
Expand Down
51 changes: 27 additions & 24 deletions gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (

var provider = gcpProvider{}

const DATAPROC_ENDPOINT_SUFFIX := "-dataproc.googleapis.com:443"

type gcpProvider struct {
projectID string
computeClient *compute.Service
Expand Down Expand Up @@ -986,14 +988,15 @@ func getRegions(p gcpProvider) ([]string, error) {
}

// Possible values:
// "PROVISIONING"
// "RUNNING"
// "STAGING"
// "STOPPED"
// "STOPPING"
// "SUSPENDED"
// "SUSPENDING"
// "TERMINATED"
//
// "PROVISIONING"
// "RUNNING"
// "STAGING"
// "STOPPED"
// "STOPPING"
// "SUSPENDED"
// "SUSPENDING"
// "TERMINATED"
func getInstanceState(instance *compute.Instance) types.State {
switch instance.Status {
case "PROVISIONING", "RUNNING", "STAGING":
Expand Down Expand Up @@ -1083,7 +1086,7 @@ func (p gcpProvider) getDatabases(aggregator *sqladmin.InstancesListCall) ([]*ty
for _, databaseInstance := range gDatabaseList.Items {
instanceName := databaseInstance.Name

listOperationCall := p.sqlClient.Operations.List(p.projectID, instanceName)
listOperationCall := p.sqlClient.Operations.List(instanceName)
creationTimeStamp, err := getDatabaseInstanceCreationTimeStamp(listOperationCall, instanceName)
if err != nil {
log.Errorf("[GCP] Failed to get the creation timestamp of the DB: %s, err: %s", instanceName, err.Error())
Expand Down Expand Up @@ -1141,12 +1144,12 @@ func getDatabaseInstanceCreationTimeStamp(opService *sqladmin.OperationsListCall
return time.Time{}, errors.New(fmt.Sprintf("[GCP] Failed to get the CREATE operation of the DB instance: %s", dbName))
}

//Possible values:
//CREATING: Disk is provisioning.
//RESTORING: Source data is being copied into the disk.
//FAILED: Disk creation failed.
//READY: Disk is ready for use.
//DELETING: Disk is deleting.
// Possible values:
// CREATING: Disk is provisioning.
// RESTORING: Source data is being copied into the disk.
// FAILED: Disk creation failed.
// READY: Disk is ready for use.
// DELETING: Disk is deleting.
func getDiskStatus(gDisk *compute.Disk) types.State {
switch gDisk.Status {
case "CREATING", "RESTORING", "STAGING", "READY", "FAILED":
Expand All @@ -1162,13 +1165,13 @@ func getDiskStatus(gDisk *compute.Disk) types.State {
}
}

//SQL_INSTANCE_STATE_UNSPECIFIED The state of the instance is unknown.
//RUNNABLE The instance is running.
//SUSPENDED The instance is currently offline, but it may run again in the future.
//PENDING_DELETE The instance is being deleted.
//PENDING_CREATE The instance is being created.
//MAINTENANCE The instance is down for maintenance.
//FAILED The instance failed to be created.
// SQL_INSTANCE_STATE_UNSPECIFIED The state of the instance is unknown.
// RUNNABLE The instance is running.
// SUSPENDED The instance is currently offline, but it may run again in the future.
// PENDING_DELETE The instance is being deleted.
// PENDING_CREATE The instance is being created.
// MAINTENANCE The instance is down for maintenance.
// FAILED The instance failed to be created.
func getDatabaseInstanceStatus(instance *sqladmin.DatabaseInstance) types.State {
switch instance.State {
case "RUNNABLE":
Expand Down Expand Up @@ -1215,7 +1218,7 @@ func newCluster(cluster *dataprocpb.Cluster, region string) *types.Cluster {
Created: cluster.Status.StateStartTime.AsTime(),
CloudType: types.GCP,
Region: region,
Tags: convertTags(cluster.Labels),
Tags: cluster.Labels,
Config: cluster.GetConfig(),
State: getClusterState(cluster.Status.GetState()),
}
Expand Down Expand Up @@ -1267,7 +1270,7 @@ func (p gcpProvider) GetClusters() ([]*types.Cluster, error) {
return nil, err
}
for _, r := range regionsList {
regionalClient, err := dataproc.NewClusterControllerClient(ctx, option.WithEndpoint(r+"-dataproc.googleapis.com:443"))
regionalClient, err := dataproc.NewClusterControllerClient(ctx, option.WithEndpoint(r + DATAPROC_ENDPOINT_SUFFIX))
if err != nil {
log.Errorf("[GET_CLUSTERS] Error creating dataproc client for region %s: %+v", r, err)
return nil, err
Expand Down
41 changes: 28 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@ module github.com/hortonworks/cloud-haunter
go 1.17

require (
cloud.google.com/go/dataproc v1.8.0
github.com/Azure/azure-sdk-for-go v60.1.0+incompatible
github.com/Azure/azure-storage-blob-go v0.14.0
github.com/Azure/go-autorest/autorest v0.11.23
github.com/Azure/go-autorest/autorest/azure/auth v0.5.9
github.com/aws/aws-sdk-go v1.29.34
github.com/sirupsen/logrus v1.0.5
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.8.1
github.com/tbruyelle/hipchat-go v0.0.0-20160921153256-749fb9e14beb
golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd
google.golang.org/api v0.0.0-20180717000714-0025a57598c0
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783
google.golang.org/api v0.102.0
google.golang.org/genproto v0.0.0-20221116193143-41c2ba794472
gopkg.in/yaml.v2 v2.2.2
)

require (
cloud.google.com/go v0.25.0 // indirect
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
cloud.google.com/go/longrunning v0.3.0 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
go.opencensus.io v0.24.0 // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
cloud.google.com/go v0.105.0 // indirect
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.14 // indirect
Expand All @@ -27,24 +43,23 @@ require (
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.2.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/mattn/go-ieproxy v0.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306
google.golang.org/appengine v1.1.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
)
Loading

0 comments on commit 00d4a7b

Please sign in to comment.