2.1 (latest)
Search
K
Links

Allocation Trends API

Calculating trend value

The Allocation Trends API determines changes in resource cost usage over time based on the interval set window parameter and provides that information via the schema field value. Cost usage for the current window sampled will be compared with the previous window, the window directly before the current window of the same size interval. For example, for window=3d, Kubecost will output cost usage for the past three days compared to cost usage of the three days before the start of the window. This means a total of six days of allocation data must be available and sampled in order to provide an accurate value.
The equation for calculating value is: value=current/previous - 1
Receiving a positive value means your more recent totalCost has increased compared to the previous window. A negative value means spending has decreased.
It's important to recognize when a resource is not detected to exist in the previous window. This is designated by the field IsInfinite=true, which means the allocation could not be determined to exist. Otherwise, the cause of an unexpected or major trend change could be misattributed. The field isNaN, meaning not a number, refers to if the value is unreal. If so, isNan should return true, which means there was an error during calculation. Both fields should return false during a successful query.
In the example output below, value is expressed as -0.27..., meaning spending has decreased in the current window by roughly 27% from the previous window.
"allocationTrends": {
"aggregator": {
"trends": {
"costs": {
"totalCost": {
"relativeChange": {
"isInfinite": false,
"isNaN": false,
"value": -0.2786223889995989
}
}
}
}
},

Using the names parameter

names is a mandatory parameter which determines the sequence of items returned, based on whatever the query is aggregating by. For example, when using aggregate=namespace, the user should provide a comma-separated list of all namespaces they wish to see trend values for in this category. In this case, they should provide names=kubecost,aggregator,kube-system... to receive a list of trend values for all provided namespaces as ordered. If the user does not provide a value for aggregate, they must still use the names parameter to list all line items requested.

Viewing trend percentages in the UI

Trend values are converted into percentages in the Kubecost Allocations page, calculated based on your current query. Trends will be presented in the rightmost column, next to your Total cost. The window parameter is determined by your selected date range in the top right of the page. The default is Last 7 days (window=7d). The equation value*100 is used to provide percentages.
Total cost column
Requests with large time intervals for window can result in an error. The recommended maximum interval for window is 7 days. A failed response will show a N/A inside a gray bubble in the UI with no percentage returned.
The Trends API does not currently support cost comparisons besides totalCost.