Skip to content

Commit

Permalink
refactor: s/CostExplorable/CostExplorer
Browse files Browse the repository at this point in the history
  • Loading branch information
skl committed Dec 5, 2023
1 parent e51b26d commit 4c9e930
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.

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

6 changes: 3 additions & 3 deletions pkg/aws/costexplorer/costexplorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

var (
_ CostExplorable = Client{}
_ CostExplorer = Client{}
)

type CostExplorable interface {
type CostExplorer interface {
GetCostAndUsage(ctx context.Context, params *costexplorer.GetCostAndUsageInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetCostAndUsageOutput, error)
}

type Client struct {
c CostExplorable
c CostExplorer
}

func (c Client) GetCostAndUsage(ctx context.Context, params *costexplorer.GetCostAndUsageInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetCostAndUsageOutput, error) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/aws/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ var (
// Collector is the AWS implementation of the Collector interface
// It is responsible for registering and collecting metrics
type Collector struct {
client costexplorer.CostExplorable
client costexplorer.CostExplorer
interval time.Duration
nextScrape time.Time
}

// New creates a new Collector with a client and scrape interval defined.
func New(scrapeInterval time.Duration, client costexplorer.CostExplorable) (*Collector, error) {
func New(scrapeInterval time.Duration, client costexplorer.CostExplorer) (*Collector, error) {
return &Collector{
client: client,
interval: scrapeInterval,
Expand Down Expand Up @@ -220,7 +220,7 @@ func (s S3BillingData) AddMetricGroup(region string, component string, group typ

// getBillingData is responsible for making the API call to the AWS Cost Explorer API and parsing the response
// into a S3BillingData struct
func getBillingData(client costexplorer.CostExplorable, startDate time.Time, endDate time.Time) (S3BillingData, error) {
func getBillingData(client costexplorer.CostExplorer, startDate time.Time, endDate time.Time) (S3BillingData, error) {
log.Printf("Getting billing data for %s to %s\n", startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
input := &awscostexplorer.GetCostAndUsageInput{
TimePeriod: &types.DateInterval{
Expand Down Expand Up @@ -329,7 +329,7 @@ func getComponentFromKey(key string) string {
}

// ExportBillingData will query the previous 30 days of S3 billing data and export it to the prometheus metrics
func ExportBillingData(client costexplorer.CostExplorable) error {
func ExportBillingData(client costexplorer.CostExplorer) error {
// We go one day into the past as the current days billing data has no guarantee of being complete
endDate := time.Now().AddDate(0, 0, -1)
// Current assumption is that we're going to pull 30 days worth of billing data
Expand Down
6 changes: 3 additions & 3 deletions pkg/aws/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestS3BillingData_AddRegion(t *testing.T) {
func TestNewCollector(t *testing.T) {
type args struct {
interval time.Duration
client costexplorer.CostExplorable
client costexplorer.CostExplorer
}
tests := map[string]struct {
args args
Expand All @@ -177,7 +177,7 @@ func TestNewCollector(t *testing.T) {
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
c := mockcostexplorer.NewCostExplorable(t)
c := mockcostexplorer.NewCostExplorer(t)

got, err := New(tt.args.interval, c)
if tt.error {
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestExportBillingData(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
ce := mockcostexplorer.NewCostExplorable(t)
ce := mockcostexplorer.NewCostExplorer(t)
if tc.GetCostAndUsage != nil {
ce.EXPECT().
GetCostAndUsage(mock.Anything, mock.Anything, mock.Anything).
Expand Down

0 comments on commit 4c9e930

Please sign in to comment.