customcostresponse.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. package model
  2. import "github.com/opencost/opencost/core/pkg/opencost"
  3. // see design at https://link.excalidraw.com/l/ABLQ24dkKai/CBEQtjH6Mr
  4. // for additional details on how these objects work in the context of
  5. // opencost's plugin system
  6. type CustomCostResponse struct {
  7. // provides metadata on the Custom CostResponse
  8. // deliberately left unstructured
  9. Metadata map[string]string
  10. // declared by plugin
  11. // eg snowflake == "data management",
  12. // datadog == "observability" etc
  13. // intended for top level agg
  14. Costsource string
  15. // the name of the custom cost source
  16. // e.g., "datadog"
  17. Domain string
  18. // the version of the Custom Cost response
  19. // is set by the plugin, will vary between
  20. // different plugins
  21. Version string
  22. // FOCUS billing currency
  23. Currency string
  24. // the window of the returned objects
  25. Window opencost.Window
  26. // array of CustomCosts
  27. Costs []*CustomCost
  28. // any errors in processing
  29. Errors []error
  30. }
  31. // designed to provide a superset of the FOCUS spec
  32. // https://github.com/FinOps-Open-Cost-and-Usage-Spec/FOCUS_Spec/releases/latest/download/spec.pdf
  33. type CustomCost struct {
  34. // provides metadata on the Custom CostResponse
  35. // deliberately left unstructured
  36. Metadata map[string]string
  37. // the region that the resource was incurred
  38. // corresponds to 'availability zone' of FOCUS
  39. Zone string
  40. // FOCUS billed Cost
  41. BilledCost float32
  42. // FOCUS billing account name
  43. AccountName string
  44. // FOCUS charge category
  45. ChargeCategory string
  46. // FOCUS charge description
  47. Description string
  48. // FOCUS List Cost
  49. ListCost float32
  50. // FOCUS List Unit Price
  51. ListUnitPrice float32
  52. // FOCUS Resource Name
  53. ResourceName string
  54. // FOCUS Resource type
  55. // if not set, assumed to be domain
  56. ResourceType string
  57. // ID of the individual cost. should be globally
  58. // unique. Assigned by plugin on read
  59. Id string
  60. // the provider's ID for the cost, if
  61. // available
  62. // FOCUS resource ID
  63. ProviderId string
  64. // the window of the returned specific
  65. // custom cost
  66. // equivalent to charge period start/end of FOCUS
  67. Window *opencost.Window
  68. // Returns key/value sets of labels
  69. // equivalent to Tags in focus spec
  70. Labels map[string]string
  71. // FOCUS usage quantity
  72. UsageQty float32
  73. // FOCUS usage Unit
  74. UsageUnit string
  75. // Optional struct to implement other focus
  76. // spec attributes
  77. ExtendedAttributes *ExtendedCustomCostAttributes
  78. }
  79. // These parts of the FOCUS spec are not expected
  80. // to be implemented by every plugin
  81. // however, if these bits of information are available,
  82. // they should be provided
  83. type ExtendedCustomCostAttributes struct {
  84. // FOCUS billing period start/end
  85. BillingPeriod *opencost.Window
  86. // FOCUS Billing Account ID
  87. AccountID string
  88. // FOCUS Charge Frequency
  89. ChargeFrequency string
  90. // FOCUS Charge Subcategory
  91. Subcategory string
  92. // FOCUS Commitment Discount Category
  93. CommitmentDiscountCategory string
  94. // FOCUS Commitment Discount ID
  95. CommitmentDiscountID string
  96. // FOCUS Commitment Discount Name
  97. CommitmentDiscountName string
  98. // FOCUS Commitment Discount Type
  99. CommitmentDiscountType string
  100. // FOCUS Effective Cost
  101. EffectiveCost float32
  102. // FOCUS Invoice Issuer
  103. InvoiceIssuer string
  104. // FOCUS Provider
  105. // if unset, assumed to be domain
  106. Provider string
  107. // FOCUS Publisher
  108. // if unset, assumed to be domain
  109. Publisher string
  110. // FOCUS Service Category
  111. // if unset, assumed to be cost source
  112. ServiceCategory string
  113. // FOCUS Service Name
  114. // if unset, assumed to be cost source
  115. ServiceName string
  116. // FOCUS SKU ID
  117. SkuID string
  118. // FOCUS SKU Price ID
  119. SkuPriceID string
  120. // FOCUS Sub Account ID
  121. SubAccountID string
  122. // FOCUS Sub Account Name
  123. SubAccountName string
  124. // FOCUS Pricing Quantity
  125. PricingQuantity float32
  126. // FOCUS Pricing Unit
  127. PricingUnit string
  128. // FOCUS Pricing Category
  129. PricingCategory string
  130. }
  131. func (e *ExtendedCustomCostAttributes) GetBillingPeriod() *opencost.Window {
  132. return e.BillingPeriod
  133. }
  134. func (e *ExtendedCustomCostAttributes) GetAccountID() string {
  135. return e.AccountID
  136. }
  137. func (e *ExtendedCustomCostAttributes) GetChargeFrequency() string {
  138. return e.ChargeFrequency
  139. }
  140. func (e *ExtendedCustomCostAttributes) GetSubcategory() string {
  141. return e.Subcategory
  142. }
  143. func (e *ExtendedCustomCostAttributes) GetCommitmentDiscountCategory() string {
  144. return e.CommitmentDiscountCategory
  145. }
  146. func (e *ExtendedCustomCostAttributes) GetCommitmentDiscountID() string {
  147. return e.CommitmentDiscountID
  148. }
  149. func (e *ExtendedCustomCostAttributes) GetCommitmentDiscountName() string {
  150. return e.CommitmentDiscountName
  151. }
  152. func (e *ExtendedCustomCostAttributes) GetCommitmentDiscountType() string {
  153. return e.CommitmentDiscountType
  154. }
  155. func (e *ExtendedCustomCostAttributes) GetEffectiveCost() float32 {
  156. return e.EffectiveCost
  157. }
  158. func (e *ExtendedCustomCostAttributes) GetInvoiceIssuer() string {
  159. return e.InvoiceIssuer
  160. }
  161. func (e *ExtendedCustomCostAttributes) GetProvider() string {
  162. return e.Provider
  163. }
  164. func (e *ExtendedCustomCostAttributes) GetPublisher() string {
  165. return e.Publisher
  166. }
  167. func (e *ExtendedCustomCostAttributes) GetServiceCategory() string {
  168. return e.ServiceCategory
  169. }
  170. func (e *ExtendedCustomCostAttributes) GetServiceName() string {
  171. return e.ServiceName
  172. }
  173. func (e *ExtendedCustomCostAttributes) GetSKUID() string {
  174. return e.SkuID
  175. }
  176. func (e *ExtendedCustomCostAttributes) GetSKUPriceID() string {
  177. return e.SkuPriceID
  178. }
  179. func (e *ExtendedCustomCostAttributes) GetSubAccountID() string {
  180. return e.SubAccountID
  181. }
  182. func (e *ExtendedCustomCostAttributes) GetSubAccountName() string {
  183. return e.SubAccountName
  184. }
  185. func (e *ExtendedCustomCostAttributes) GetPricingQuantity() float32 {
  186. return e.PricingQuantity
  187. }
  188. func (e *ExtendedCustomCostAttributes) GetPricingUnit() string {
  189. return e.PricingUnit
  190. }
  191. func (e *ExtendedCustomCostAttributes) GetPricingCategory() string {
  192. return e.PricingCategory
  193. }
  194. func (d *CustomCost) GetMetadata() map[string]string {
  195. return d.Metadata
  196. }
  197. func (d *CustomCost) GetCostIncurredZone() string {
  198. return d.Zone
  199. }
  200. func (d *CustomCost) GetBilledCost() float32 {
  201. return d.BilledCost
  202. }
  203. func (d *CustomCost) GetAccountName() string {
  204. return d.AccountName
  205. }
  206. func (d *CustomCost) GetChargeCategory() string {
  207. return d.ChargeCategory
  208. }
  209. func (d *CustomCost) GetDescription() string {
  210. return d.Description
  211. }
  212. func (d *CustomCost) GetListCost() float32 {
  213. return d.ListCost
  214. }
  215. func (d *CustomCost) GetListUnitPrice() float32 {
  216. return d.ListUnitPrice
  217. }
  218. func (d *CustomCost) GetResourceName() string {
  219. return d.ResourceName
  220. }
  221. func (d *CustomCost) GetID() string {
  222. return d.Id
  223. }
  224. func (d *CustomCost) GetProviderID() string {
  225. return d.ProviderId
  226. }
  227. func (d *CustomCost) GetWindow() *opencost.Window {
  228. return d.Window
  229. }
  230. func (d *CustomCost) GetLabels() map[string]string {
  231. return d.Labels
  232. }
  233. func (d *CustomCost) GetUsageQuantity() float32 {
  234. return d.UsageQty
  235. }
  236. func (d *CustomCost) GetUsageUnit() string {
  237. return d.UsageUnit
  238. }
  239. func (d *CustomCost) GetExtendedAttributes() *ExtendedCustomCostAttributes {
  240. return d.ExtendedAttributes
  241. }
  242. func (d *CustomCost) GetResourceType() string {
  243. return d.ResourceType
  244. }
  245. func (d *CustomCostResponse) GetMetadata() map[string]string {
  246. return d.Metadata
  247. }
  248. func (d *CustomCostResponse) GetCostSource() string {
  249. return d.Costsource
  250. }
  251. func (d *CustomCostResponse) GetDomain() string {
  252. return d.Domain
  253. }
  254. func (d *CustomCostResponse) GetVersion() string {
  255. return d.Version
  256. }
  257. func (d *CustomCostResponse) GetCurrency() string {
  258. return d.Currency
  259. }
  260. func (d *CustomCostResponse) GetWindow() opencost.Window {
  261. return d.Window
  262. }
  263. func (d *CustomCostResponse) GetCosts() []*CustomCost {
  264. return d.Costs
  265. }
  266. func (d *CustomCostResponse) GetErrors() []error {
  267. return d.Errors
  268. }