pricingmodel.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package pricingmodel
  2. import (
  3. "time"
  4. "github.com/opencost/opencost/core/pkg/model/shared"
  5. )
  6. // TODO: assess whether we need any of this, or whether we can adapt all existing
  7. // references to it to use core/pkg/pricing concepts, instead.
  8. //
  9. // See:
  10. // pkg/cloud/aws/pricinglistpricingsource.go
  11. // pkg/cloud/azure/retailpricingsource.go
  12. // pkg/cloud/gcp/billingpricingsource.go
  13. type PricingSource interface {
  14. // PricingSourceType returns the instance type of the PricingSource, each implementation of this interface should
  15. // provide a unique type that all instances should return
  16. PricingSourceType() PricingSourceType
  17. // PricingSourceKey returns the unique key of the PricingSource instance. In PricingSource implementation that may
  18. // have multiple instances running side by side this key (derived from some configuration will) will Identify each
  19. // instance. In PricingSource implementations where there will only be a single instance (ex Provider List Pricing)
  20. // The PricingSourceKey should match the PricingSourceType
  21. PricingSourceKey() string
  22. GetPricing() (*PricingModelSet, error)
  23. }
  24. type PricingSourceType string
  25. type PricingModelSet struct {
  26. TimeStamp time.Time
  27. SourceType PricingSourceType
  28. SourceKey string
  29. NodePricing map[NodeKey]NodePricing
  30. }
  31. // NewPricingModelSet creates a PricingModelSet with SourceKey initialized to sourceType.
  32. func NewPricingModelSet(timeStamp time.Time, sourceType PricingSourceType, sourceKey string) *PricingModelSet {
  33. return &PricingModelSet{
  34. TimeStamp: timeStamp,
  35. SourceType: sourceType,
  36. SourceKey: sourceKey,
  37. NodePricing: make(map[NodeKey]NodePricing),
  38. }
  39. }
  40. type NodePricingType string
  41. const (
  42. NodePricingTypeTotal NodePricingType = "Total"
  43. NodePricingTypeCPUCore NodePricingType = "CPUCore"
  44. NodePricingTypeRamGB NodePricingType = "RamGB"
  45. NodePricingTypeDevice NodePricingType = "Device"
  46. )
  47. type NodeKey struct {
  48. Provider shared.Provider
  49. PricingType NodePricingType
  50. UsageType shared.UsageType
  51. Region string
  52. NodeType string
  53. Family string
  54. DeviceType string
  55. }
  56. type NodePricing struct {
  57. HourlyRate float64
  58. }