source.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package exporter
  2. import (
  3. "context"
  4. "time"
  5. "github.com/opencost/opencost/core/pkg/diagnostics"
  6. )
  7. // DiagnosticSource is an `export.ExportSource` implementation that provides the basic data for a `DiagnosticResult` payload.
  8. type DiagnosticSource struct {
  9. diagnosticService diagnostics.DiagnosticService
  10. }
  11. // NewDiagnosticSource creates a new `HeartbeatSource` instance. The `provider` parameter is used to inject custom metadata,
  12. // but can be set to `nil` if no metadata is needed.
  13. func NewDiagnosticSource(diagnosticService diagnostics.DiagnosticService) *DiagnosticSource {
  14. return &DiagnosticSource{
  15. diagnosticService: diagnosticService,
  16. }
  17. }
  18. // Make creates a new `DiagnosticsRunReport` instance with the provided current time.
  19. func (ds *DiagnosticSource) Make(t time.Time) *diagnostics.DiagnosticsRunReport {
  20. ctx := context.Background()
  21. return &diagnostics.DiagnosticsRunReport{
  22. StartTime: t,
  23. Results: ds.diagnosticService.Run(ctx),
  24. }
  25. }
  26. func (ds *DiagnosticSource) Name() string {
  27. return diagnostics.DiagnosticsEventName + "-source"
  28. }