Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/npm_and_yarn/dashboard/next-14…
Browse files Browse the repository at this point in the history
….2.5
  • Loading branch information
Azanul authored Aug 4, 2024
2 parents d547f7c + f082b9d commit d46c7b0
Show file tree
Hide file tree
Showing 26 changed files with 368 additions and 171 deletions.
199 changes: 93 additions & 106 deletions dashboard/package-lock.json

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

2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@storybook/addon-essentials": "^8.0.5",
"@storybook/addon-interactions": "^8.0.9",
"@storybook/addon-links": "^8.2.4",
"@storybook/addons": "^7.4.6",
"@storybook/addons": "^7.6.17",
"@storybook/blocks": "^7.6.4",
"@storybook/nextjs": "^8.2.5",
"@storybook/preview-api": "^8.1.6",
Expand Down
90 changes: 90 additions & 0 deletions providers/aws/redshift/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package redshift

import (
"context"
"fmt"
"time"

log "github.com/sirupsen/logrus"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/redshift"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
awsUtils "github.com/tailwarden/komiser/providers/aws/utils"
)

func Resources(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)
var config redshift.DescribeClustersInput
redshiftClient := redshift.NewFromConfig(*client.AWSClient)

stsClient := sts.NewFromConfig(*client.AWSClient)
stsOutput, err := stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
if err != nil {
return resources, err
}

accountId := stsOutput.Account

serviceCost, err := awsUtils.GetCostAndUsage(ctx, client.AWSClient.Region, "Redshift")
if err != nil {
log.Warnln("Couldn't fetch Redshift cost and usage:", err)
}

for {
output, err := redshiftClient.DescribeClusters(ctx, &config)
if err != nil {
return resources, err
}

for _, cluster := range output.Clusters {
resourceArn := fmt.Sprintf("arn:aws:redshift:%s:%s:cluster/%s", client.AWSClient.Region, *accountId, *cluster.ClusterIdentifier)
outputTags := cluster.Tags

tags := make([]models.Tag, 0)

for _, tag := range outputTags {
tags = append(tags, models.Tag{
Key: *tag.Key,
Value: *tag.Value,
})
}

monthlyCost := float64(0)

resources = append(resources, models.Resource{
Provider: "AWS",
Account: client.Name,
Service: "Redshift Cluster",
ResourceId: resourceArn,
Region: client.AWSClient.Region,
Name: *cluster.ClusterIdentifier,
Cost: monthlyCost,
Metadata: map[string]string{
"serviceCost": fmt.Sprint(serviceCost),
},
Tags: tags,
FetchedAt: time.Now(),
Link: fmt.Sprintf("https://%s.console.aws.amaxon.com/redshift/home?region=%s/clusters/%s", client.AWSClient.Region, client.AWSClient.Region, *cluster.ClusterIdentifier),
})

}

if aws.ToString(output.Marker) == "" {
break
}
config.Marker = output.Marker
}

log.WithFields(log.Fields{
"provider": "AWS",
"account": client.Name,
"region": client.AWSClient.Region,
"service": "Redshift Cluster",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil

}
Loading

0 comments on commit d46c7b0

Please sign in to comment.