source.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package asset
  2. import (
  3. "time"
  4. "github.com/opencost/opencost/core/pkg/exporter"
  5. "github.com/opencost/opencost/core/pkg/opencost"
  6. "github.com/opencost/opencost/core/pkg/pipelines"
  7. )
  8. type AssetSource interface {
  9. ComputeAssets(start, end time.Time) (*opencost.AssetSet, error)
  10. }
  11. type AssetsComputeSource struct {
  12. src AssetSource
  13. }
  14. // NewAssetsComputeSource creates an `exporter.ComputeSource[opencost.AssetSet]` implementation
  15. func NewAssetsComputeSource(src AssetSource) exporter.ComputeSource[opencost.AssetSet] {
  16. return &AssetsComputeSource{
  17. src: src,
  18. }
  19. }
  20. // CanCompute should return true iff the ComputeSource can effectively act as
  21. // a source of T data for the given time range. For example, a ComputeSource
  22. // with two-day coverage cannot fulfill a range from three days ago, and should
  23. // not be left to return an error in Compute. Instead, it should report that is
  24. // cannot compute and allow another Source to handle the computation.
  25. func (acs *AssetsComputeSource) CanCompute(start, end time.Time) bool {
  26. return true
  27. }
  28. // Compute should compute a single T for the given time range.
  29. func (acs *AssetsComputeSource) Compute(start, end time.Time) (*opencost.AssetSet, error) {
  30. return acs.src.ComputeAssets(start, end)
  31. }
  32. // Name returns the name of the ComputeSource
  33. func (acs *AssetsComputeSource) Name() string {
  34. return pipelines.AssetsPipelineName
  35. }