source.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package networkinsight
  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 NetworkInsightSource interface {
  9. ComputeNetworkInsights(start, end time.Time, resolution time.Duration) (*opencost.NetworkInsightSet, error)
  10. }
  11. type NetworkInsightsComputeSource struct {
  12. src NetworkInsightSource
  13. }
  14. // NewNetworkInsightsComputeSource creates an `exporter.ComputeSource[opencost.NetworkInsightSet]` implementation
  15. func NewNetworkInsightsComputeSource(src NetworkInsightSource) exporter.ComputeSource[opencost.NetworkInsightSet] {
  16. return &NetworkInsightsComputeSource{
  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 *NetworkInsightsComputeSource) CanCompute(start, end time.Time) bool {
  26. return true
  27. }
  28. // Compute should compute a single T for the given time range, optionally using the given resolution.
  29. func (acs *NetworkInsightsComputeSource) Compute(start, end time.Time, resolution time.Duration) (*opencost.NetworkInsightSet, error) {
  30. return acs.src.ComputeNetworkInsights(start, end, resolution)
  31. }
  32. // Name returns the name of the ComputeSource
  33. func (acs *NetworkInsightsComputeSource) Name() string {
  34. return pipelines.NetworkInsightPipelineName
  35. }