Documentation ¶
Index ¶
- func ColumnPermutations(results []*CommonResult) map[string][]string
- func MonthlyTaxHandler(server *api.ApiServer, w http.ResponseWriter, r *http.Request)
- func Register(mux *http.ServeMux, apiServer *api.ApiServer)
- func StandardCounters(ctx context.Context, q *awsc.Queries, resp *ApiResponse)
- func StandardDates(response *ApiResponse, start time.Time, end time.Time, rangeEnd time.Time, ...)
- func StandardHandler(server *api.ApiServer, w http.ResponseWriter, r *http.Request)
- func YtdHandler(server *api.ApiServer, w http.ResponseWriter, r *http.Request)
- type ApiResponse
- type CommonResult
- type CountValues
- type Counters
- type GroupBy
- type PossibleResults
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColumnPermutations ¶ added in v1.1.0
func ColumnPermutations(results []*CommonResult) map[string][]string
ColumnPermutations uses the result set to create a list of columns and all of their possible values This is normally used to create table headers and the like
func MonthlyTaxHandler ¶
MonthlyTaxHandler handles the `taxSplitUrl` requests and returns a CostRepsonse. Returns total costs including and excluding tax for the last 12 months. Used to make comparing to finace data simpler as that doesnt include tax. No get parameters are used
- Connect to db vai `apiDbPath`
- Run query
- Set the column and column ordering data in apiResponse to fixed values
Sample urls:
- /v1/aws_costs/monthly-tax/
func Register ¶
Register sets the local context and database paths to the values passed and then attaches the local handles to the url patterns supported by aws_costs api
func StandardCounters ¶ added in v1.1.0
func StandardCounters(ctx context.Context, q *awsc.Queries, resp *ApiResponse)
StandardCounters adds the standard counter data
func StandardDates ¶ added in v1.1.0
func StandardHandler ¶
StandardHandler is configured to deal with `standardUrl` queries and will return a ApiResponse. Used by the majority of costs data calls
- Connects to sqlite db
- Uses the group and interval get parameters to determine which db query to run
- Adds columns to the apiResponse (driven from group data)
- Adds the unique values of each columns to the apiResponse
- Adds date range info to the apiResponse
Allows following get parameters:
- start: change the start date of the data (default to billingDate - 12)
- interval: group the data by DAY or MONTH (default MONTH)
- group: how to group the data by other fields (allowed: `unit`, `unit-env`, `detailed` default: unit)
- end: change the max date of the data (default to billingDate)
NOTE: the end parameter should be the day after the max you want to capture as a less than (`<`) is used
Sample urls
- /v1/aws_costs/?group=unit
- /v1/aws_costs/?start=2024-01&end=2024-06
- /v1/aws_costs/?start=2024-01-01&end=2024-02-01&interval=DAY
- /v1/aws_costs/?start=2024-01-01&end=2024-02-01&interval=DAY&group=detailed
func YtdHandler ¶
YtdHandler is configured to handle the `ytdUrl` queries and will return a ApiResponse. Returns a single cost value for the entire billing year so far. No get parameters are used
- Connects to sqlite db via `apiDbPath`
- Works out the start and end dates (based on billingDate and first of the year)
- Gets the single total value for the year to date
- Formats apiResponseto have one result with the value
Sample urls
- /v1/aws_costs/ytd/
Types ¶
type ApiResponse ¶ added in v1.2.1
type ApiResponse struct { *response.Response Counters *Counters `json:"counters,omitempty"` Columns map[string][]string `json:"columns,omitempty"` ColumnOrdering []string `json:"column_ordering,omitempty"` QueryFilters map[string]interface{} `json:"query_filters,omitempty"` Result []*CommonResult `json:"result"` }
ApiResponse is the response object used and returned by the aws_costs api handler Based on response.Response struct as a common ground and then add additional fields to the struct that are used for this api
type CommonResult ¶
type CommonResult struct { AccountID string `json:"account_id,omitempty"` Unit string `json:"unit,omitempty"` Label string `json:"label,omitempty"` Environment interface{} `json:"environment,omitempty"` Service string `json:"service,omitempty"` Total interface{} `json:"total,omitempty"` Interval interface{} `json:"interval,omitempty"` }
CommonResult is used instead of the variable versions encapsulated by PossibleResults in the ApiResponse struct This is to simplify the parsing on both the api and the consumer in front To be effective, any empty field is omited in the json Converted using `Common` func
func Common ¶
func Common[T PossibleResults](results []T) (common []*CommonResult)
Common func converts from the known aws cost structs to the common result type via json marshaling
func StandardQueryResults ¶ added in v1.1.0
func StandardQueryResults(ctx context.Context, q *awsc.Queries, req *request.Request, r *http.Request) (results []*CommonResult, err error)
StandardQueryResults uses the group and interval values from the request to determine which db query to run
The query to use is determined by the following: Interval set to `MONTH`
- group set to `unit` (unit)
- group set to `unit-env` (unit and environment)
- group set to `detailed` (unit, environment, account id and service)
Interval set to `DAY`
- group set to `unit` (unit)
- group set to `unit-env` (unit and environment)
- group set to `detailed` (unit, environment, account id and service)
Query results are converted to `[]*CommonResult` struct.
type CountValues ¶
type CountValues struct {
Count int `json:"count"`
}
CountValues tracks a single counter value This is normally used to track the total of the data sets
type Counters ¶
type Counters struct { Totals *CountValues `json:"totals"` This *CountValues `json:"current"` }
Counters captures multiple count values, in general we return the Total (so everyhing in the database) version and `This` - which is based on the current query result
type GroupBy ¶ added in v1.1.0
type GroupBy string
GroupBy is used by api / front tohandle group by allowed values
type PossibleResults ¶
type PossibleResults interface { awsc.MonthlyCostsDetailedRow | awsc.MonthlyCostsPerUnitRow | awsc.MonthlyCostsPerUnitEnvironmentRow | awsc.DailyCostsDetailedRow | awsc.DailyCostsPerUnitRow | awsc.DailyCostsPerUnitEnvironmentRow | awsc.MonthlyTotalsTaxSplitRow | awsc.MonthlyCostsDetailedForUnitRow | awsc.DailyCostsDetailedForUnitRow }
PossibleResults is used to constrain the type of the value on the Common func and simply is interface for all the know result types