Skip to content

Commit

Permalink
feat(aws): scrape elastiCache
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jun 27, 2024
1 parent 0e6c61d commit 437a30e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/v1/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type CostReporting struct {
}

const (
AWSElastiCacheCluster = "AWS::ElastiCache::CacheCluster"
AWSEKSFargateProfile = "AWS::ECS::FargateProfile"
AWSECSTask = "AWS::ECS:Task"
AWSECSService = "AWS::EC2::Service"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/ecs v1.24.2
github.com/aws/aws-sdk-go-v2/service/efs v1.19.9
github.com/aws/aws-sdk-go-v2/service/eks v1.27.8
github.com/aws/aws-sdk-go-v2/service/elasticache v1.26.6
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.15.6
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.19.7
github.com/aws/aws-sdk-go-v2/service/iam v1.19.8
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ github.com/aws/aws-sdk-go-v2/service/efs v1.19.9 h1:IZM3sHHZy+NoCXKEiB04Lkhkyfta
github.com/aws/aws-sdk-go-v2/service/efs v1.19.9/go.mod h1:WkMJD5lMsA0tugbGhOvj49IYsWKBCJxta2J9gezQJJ8=
github.com/aws/aws-sdk-go-v2/service/eks v1.27.8 h1:o3cnwMi1lTjOB1N5kKMHc1yjq6al8wmMT9uyI2VLhpc=
github.com/aws/aws-sdk-go-v2/service/eks v1.27.8/go.mod h1:XNcs5UYWyXvctSc/tVZIfq6sj2QA1jTy2hMkTzSDZ3c=
github.com/aws/aws-sdk-go-v2/service/elasticache v1.26.6 h1:PRbssBtMKTVa+Ge+ARwMSFcwT3s+KGPn5A//ckodgcg=
github.com/aws/aws-sdk-go-v2/service/elasticache v1.26.6/go.mod h1:YG1Qmu7Nan+5htEwo6iVa4mcZjoKm+NjbJUE5f+Oq9k=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.15.6 h1:rY5DlQpQVGje6jiZQ+8xb4WbUyq4EFoPowpAnE3LrGg=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.15.6/go.mod h1:by4vXHvRiuHkKrp3h++wo776M2E80m4Wmyt+Yj6uF1M=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.19.7 h1:XpIms0tmerNg/t6IiGrbKU6Au25CHyXqs8Yc3zOET5o=
Expand Down
28 changes: 28 additions & 0 deletions scrapers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ecs"
"github.com/aws/aws-sdk-go-v2/service/efs"
"github.com/aws/aws-sdk-go-v2/service/eks"
"github.com/aws/aws-sdk-go-v2/service/elasticache"
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing"
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
"github.com/aws/aws-sdk-go-v2/service/iam"
Expand Down Expand Up @@ -382,6 +383,32 @@ func (aws Scraper) eksFargateProfiles(ctx *AWSContext, config v1.AWS, results *v
}
}

func (aws Scraper) elastiCache(ctx *AWSContext, config v1.AWS, results *v1.ScrapeResults) {
if config.Excludes("ElastiCache") {
return
}

svc := elasticache.NewFromConfig(*ctx.Session)

clusters, err := svc.DescribeCacheClusters(ctx, &elasticache.DescribeCacheClustersInput{})
if err != nil {
results.Errorf(err, "failed to describe ElastiCache clusters")
return
}

for _, cluster := range clusters.CacheClusters {
*results = append(*results, v1.ScrapeResult{
ID: *cluster.CacheClusterId,
Type: v1.AWSElastiCacheCluster,
BaseScraper: config.BaseScraper,
Config: cluster,
ConfigClass: "Cache",
Name: *cluster.CacheClusterId,
Parents: []v1.ConfigExternalKey{{Type: v1.AWSAccount, ExternalID: lo.FromPtr(ctx.Caller.Account)}},
})
}
}

func (aws Scraper) lambdaFunctions(ctx *AWSContext, config v1.AWS, results *v1.ScrapeResults) {
if config.Excludes("lambda") {
return
Expand Down Expand Up @@ -1435,6 +1462,7 @@ func (aws Scraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResults {
}

ctx.Logger.V(1).Infof("scraping %s", awsCtx)
aws.elastiCache(awsCtx, awsConfig, results)
aws.lambdaFunctions(awsCtx, awsConfig, results)
aws.ecsClusters(awsCtx, awsConfig, results)
aws.ecsTasks(awsCtx, awsConfig, results)
Expand Down

0 comments on commit 437a30e

Please sign in to comment.