Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions api/handlers_spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (s *server) SpaceGetHandler(w http.ResponseWriter, r *http.Request) {
endTime := vars["end"]
spaceID := vars["space"]
groupBy := vars["groupby"]
granularity := vars["granularity"]

role := fmt.Sprintf("arn:aws:iam::%s:role/%s", account, s.session.RoleName)
policy, err := costExplorerReadPolicy()
Expand All @@ -37,11 +38,12 @@ func (s *server) SpaceGetHandler(w http.ResponseWriter, r *http.Request) {
out, cached, expire, err := orch.getCostAndUsageForSpace(
r.Context(),
&costAndUsageReq{
account: account,
spaceID: spaceID,
start: startTime,
end: endTime,
groupBy: groupBy,
account: account,
spaceID: spaceID,
start: startTime,
end: endTime,
groupBy: groupBy,
granularity: granularity,
},
)
if err != nil {
Expand Down
11 changes: 8 additions & 3 deletions api/orchestration_costexplorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type costAndUsageReq struct {
account, spaceID, start, end, groupBy string
account, spaceID, start, end, groupBy, granularity string
}

func (o *costExplorerOrchestrator) getCostAndUsageForSpace(ctx context.Context, req *costAndUsageReq) ([]*costexplorer.ResultByTime, bool, time.Duration, error) {
Expand All @@ -22,9 +22,14 @@ func (o *costExplorerOrchestrator) getCostAndUsageForSpace(ctx context.Context,
return nil, false, 0, nil
}

granularity := "MONTHLY"
if req.granularity == "DAILY" {
granularity = "DAILY"
}

input := costexplorer.GetCostAndUsageInput{
Filter: ce.And(inSpace(req.spaceID), inOrg(o.server.org), notTryIT()),
Granularity: aws.String("MONTHLY"),
Granularity: aws.String(granularity),
Metrics: []*string{
aws.String("BLENDED_COST"),
aws.String("UNBLENDED_COST"),
Expand Down Expand Up @@ -57,7 +62,7 @@ func (o *costExplorerOrchestrator) getCostAndUsageForSpace(ctx context.Context,
// Since we will accept date-range cost exploring and grouping, concatenate
// the spaceID, the start time, end time and group by so we can cache each
// time-based result
cacheKey := fmt.Sprintf("%s_%s_%s_%s_%s", req.account, req.spaceID, req.start, req.end, req.groupBy)
cacheKey := fmt.Sprintf("%s_%s_%s_%s_%s_%s", req.account, req.spaceID, req.start, req.end, req.groupBy, granularity)

log.Debugf("cacheKey: %s", cacheKey)

Expand Down
4 changes: 4 additions & 0 deletions api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,9 @@ func matchSpaceQueries(req *http.Request, r *mux.RouteMatch) bool {
r.Vars["groupby"] = g[0]
}

if g, ok := queries["granularity"]; ok {
r.Vars["granularity"] = g[0]
}

return true
}
Loading