query.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. SplitIdle bool
  38. Step time.Duration
  39. }
  40. type AccumulateOption string
  41. const (
  42. AccumulateOptionNone AccumulateOption = ""
  43. AccumulateOptionAll AccumulateOption = "all"
  44. AccumulateOptionHour AccumulateOption = "hour"
  45. AccumulateOptionDay AccumulateOption = "day"
  46. AccumulateOptionWeek AccumulateOption = "week"
  47. AccumulateOptionMonth AccumulateOption = "month"
  48. AccumulateOptionQuarter AccumulateOption = "quarter"
  49. )
  50. // ParseAccumulate converts a string to an AccumulateOption
  51. func ParseAccumulate(acc string) AccumulateOption {
  52. var opt AccumulateOption
  53. switch strings.ToLower(acc) {
  54. case "quarter":
  55. opt = AccumulateOptionQuarter
  56. case "month":
  57. opt = AccumulateOptionMonth
  58. case "week":
  59. opt = AccumulateOptionWeek
  60. case "day":
  61. opt = AccumulateOptionDay
  62. case "hour":
  63. opt = AccumulateOptionHour
  64. case "true":
  65. opt = AccumulateOptionAll
  66. default:
  67. opt = AccumulateOptionNone
  68. }
  69. return opt
  70. }
  71. // AssetQueryOptions defines optional parameters for querying an Asset Store
  72. type AssetQueryOptions struct {
  73. Accumulate bool
  74. AggregateBy []string
  75. Compute bool
  76. DisableAdjustments bool
  77. DisableAggregatedStores bool
  78. Filter filter.Filter
  79. IncludeCloud bool
  80. SharedHourlyCosts map[string]float64
  81. Step time.Duration
  82. LabelConfig *LabelConfig
  83. }