source.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package kubemodel
  2. import (
  3. "time"
  4. "github.com/opencost/opencost/core/pkg/exporter"
  5. "github.com/opencost/opencost/core/pkg/model/kubemodel"
  6. "github.com/opencost/opencost/core/pkg/pipelines"
  7. )
  8. type KubeModelSource interface {
  9. ComputeKubeModelSet(start, end time.Time) (*kubemodel.KubeModelSet, error)
  10. }
  11. type KubeModelComputeSource struct {
  12. src KubeModelSource
  13. }
  14. // NewKubeModelComputeSource creates an `exporter.ComputeSource[opencost.KubeModelSet]` implementation
  15. func NewKubeModelComputeSource(src KubeModelSource) exporter.ComputeSource[kubemodel.KubeModelSet] {
  16. return &KubeModelComputeSource{
  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 *KubeModelComputeSource) 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 *KubeModelComputeSource) Compute(start, end time.Time) (*kubemodel.KubeModelSet, error) {
  30. return acs.src.ComputeKubeModelSet(start, end)
  31. }
  32. // Name returns the name of the ComputeSource
  33. func (acs *KubeModelComputeSource) Name() string {
  34. return pipelines.KubeModelPipelineName
  35. }