query.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package opencost
  2. import (
  3. "strings"
  4. "time"
  5. "github.com/opencost/opencost/core/pkg/filter"
  6. )
  7. // AllocationQuerier interface defining api for requesting Allocation data
  8. type AllocationQuerier interface {
  9. QueryAllocation(start, end time.Time, opts *AllocationQueryOptions) (*AllocationSetRange, error)
  10. }
  11. // SummaryAllocationQuerier interface defining api for requesting SummaryAllocation data
  12. type SummaryAllocationQuerier interface {
  13. QuerySummaryAllocation(start, end time.Time, opts *AllocationQueryOptions) (*SummaryAllocationSetRange, error)
  14. }
  15. // AssetQuerier interface defining api for requesting Asset data
  16. type AssetQuerier interface {
  17. QueryAsset(start, end time.Time, opts *AssetQueryOptions) (*AssetSetRange, error)
  18. }
  19. // AllocationQueryOptions defines optional parameters for querying an Allocation Store
  20. type AllocationQueryOptions struct {
  21. Accumulate AccumulateOption
  22. AggregateBy []string
  23. Compute bool
  24. DisableAggregatedStores bool
  25. Filter filter.Filter
  26. IdleByNode bool
  27. IncludeExternal bool
  28. IncludeIdle bool
  29. LabelConfig *LabelConfig
  30. MergeUnallocated bool
  31. Reconcile bool
  32. ReconcileNetwork bool
  33. ShareFuncs []AllocationMatchFunc
  34. SharedHourlyCosts map[string]float64
  35. ShareIdle string
  36. ShareSplit string
  37. ShareTenancyCosts bool
  38. SplitIdle bool
  39. Step time.Duration
  40. }
  41. type AccumulateOption string
  42. const (
  43. AccumulateOptionNone AccumulateOption = ""
  44. AccumulateOptionAll AccumulateOption = "all"
  45. AccumulateOptionHour AccumulateOption = "hour"
  46. AccumulateOptionDay AccumulateOption = "day"
  47. AccumulateOptionWeek AccumulateOption = "week"
  48. AccumulateOptionMonth AccumulateOption = "month"
  49. AccumulateOptionQuarter AccumulateOption = "quarter"
  50. )
  51. // ParseAccumulate converts a string to an AccumulateOption
  52. func ParseAccumulate(acc string) AccumulateOption {
  53. var opt AccumulateOption
  54. switch strings.ToLower(acc) {
  55. case "quarter":
  56. opt = AccumulateOptionQuarter
  57. case "month":
  58. opt = AccumulateOptionMonth
  59. case "week":
  60. opt = AccumulateOptionWeek
  61. case "day":
  62. opt = AccumulateOptionDay
  63. case "hour":
  64. opt = AccumulateOptionHour
  65. case "true":
  66. opt = AccumulateOptionAll
  67. default:
  68. opt = AccumulateOptionNone
  69. }
  70. return opt
  71. }
  72. // AssetQueryOptions defines optional parameters for querying an Asset Store
  73. type AssetQueryOptions struct {
  74. Accumulate bool
  75. AggregateBy []string
  76. Compute bool
  77. DisableAdjustments bool
  78. DisableAggregatedStores bool
  79. Filter filter.Filter
  80. IncludeCloud bool
  81. SharedHourlyCosts map[string]float64
  82. Step time.Duration
  83. LabelConfig *LabelConfig
  84. }