source.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. "github.com/opencost/opencost/pkg/costmodel"
  8. )
  9. type NetworkInsightsComputeSource struct {
  10. cm *costmodel.CostModel
  11. }
  12. // NewNetworkInsightsComputeSource creates an `exporter.ComputeSource[opencost.NetworkInsightSet]` implementation
  13. func NewNetworkInsightsComputeSource(cm *costmodel.CostModel) exporter.ComputeSource[opencost.NetworkInsightSet] {
  14. return &NetworkInsightsComputeSource{
  15. cm: cm,
  16. }
  17. }
  18. // CanCompute should return true iff the ComputeSource can effectively act as
  19. // a source of T data for the given time range. For example, a ComputeSource
  20. // with two-day coverage cannot fulfill a range from three days ago, and should
  21. // not be left to return an error in Compute. Instead, it should report that is
  22. // cannot compute and allow another Source to handle the computation.
  23. func (acs *NetworkInsightsComputeSource) CanCompute(start, end time.Time) bool {
  24. return true
  25. }
  26. // Compute should compute a single T for the given time range, optionally using the given resolution.
  27. func (acs *NetworkInsightsComputeSource) Compute(start, end time.Time, resolution time.Duration) (*opencost.NetworkInsightSet, error) {
  28. return acs.cm.ComputeNetworkInsights(start, end, resolution)
  29. }
  30. // Name returns the name of the ComputeSource
  31. func (acs *NetworkInsightsComputeSource) Name() string {
  32. return pipelines.NetworkInsightPipelineName
  33. }