2
0
Эх сурвалжийг харах

Simplify exporter parameters.

Matt Bolt 11 сар өмнө
parent
commit
42322ddc49

+ 0 - 1
core/pkg/diagnostics/exporter/exporter.go

@@ -17,7 +17,6 @@ func NewDiagnosticExporter(clusterId string, applicationName string, storage sto
 	}
 
 	return exporter.NewEventStorageExporter(
-		diagnostics.DiagnosticsEventName,
 		pathing,
 		NewDiagnosticsEncoder(),
 		storage,

+ 10 - 18
core/pkg/exporter/exporter.go

@@ -26,26 +26,23 @@ type ComputeExporter[T any] Exporter[opencost.Window, T]
 // EventStorageExporter[T] is an implementation of an Exporter[T] that writes data to a storage backend using
 // the `github.com/opencost/opencost/core/pkg/storage` package, a pathing strategy, and an encoder.
 type EventStorageExporter[T any] struct {
-	pipeline string
-	paths    pathing.StoragePathFormatter[time.Time]
-	encoder  Encoder[T]
-	storage  storage.Storage
+	paths   pathing.StoragePathFormatter[time.Time]
+	encoder Encoder[T]
+	storage storage.Storage
 }
 
 // NewEventStorageExporter creates a new StorageExporter instance, which is responsible for exporting data to a storage backend.
 // It uses a pathing strategy to determine the storage location, an encoder to convert the data to binary format, and
 // a storage backend to write the data.
 func NewEventStorageExporter[T any](
-	pipeline string,
 	paths pathing.StoragePathFormatter[time.Time],
 	encoder Encoder[T],
 	storage storage.Storage,
 ) EventExporter[T] {
 	return &EventStorageExporter[T]{
-		pipeline: pipeline,
-		paths:    paths,
-		encoder:  encoder,
-		storage:  storage,
+		paths:   paths,
+		encoder: encoder,
+		storage: storage,
 	}
 }
 
@@ -71,7 +68,6 @@ func (se *EventStorageExporter[T]) Export(t time.Time, data *T) error {
 // ComputeStorageExporter[T] is an implementation of ComputeExporter[T] that writes data to a storage backend using
 // `github.com/opencost/opencost/core/pkg/storage`, a pathing strategy, and an encoder.
 type ComputeStorageExporter[T any] struct {
-	pipeline   string
 	resolution time.Duration
 	paths      pathing.StoragePathFormatter[opencost.Window]
 	encoder    Encoder[T]
@@ -84,20 +80,16 @@ type ComputeStorageExporter[T any] struct {
 // an encoder to convert the data to binary format, and a validator to check the data before export. The pipeline
 // name and resolution are also provided to help identify the data being exported.
 func NewComputeStorageExporter[T any](
-	pipeline string,
-	resolution time.Duration,
 	paths pathing.StoragePathFormatter[opencost.Window],
 	encoder Encoder[T],
 	storage storage.Storage,
 	validator validator.ExportValidator[T],
 ) ComputeExporter[T] {
 	return &ComputeStorageExporter[T]{
-		pipeline:   pipeline,
-		resolution: resolution,
-		paths:      paths,
-		encoder:    encoder,
-		storage:    storage,
-		validator:  validator,
+		paths:     paths,
+		encoder:   encoder,
+		storage:   storage,
+		validator: validator,
 	}
 }
 

+ 6 - 6
core/pkg/exporter/exporter_test.go

@@ -13,9 +13,8 @@ import (
 )
 
 const (
-	TestPipelineName = "test-pipeline"
-	TestClusterId    = "test-cluster"
-	TestEventName    = "test-event-path"
+	TestClusterId = "test-cluster"
+	TestEventName = "test-event-path"
 )
 
 type TestData struct {
@@ -31,7 +30,7 @@ func TestStorageExporters(t *testing.T) {
 		}
 
 		encoder := NewJSONEncoder[TestData]()
-		export := NewEventStorageExporter(TestPipelineName, p, encoder, store)
+		export := NewEventStorageExporter(p, encoder, store)
 
 		ts := time.Now().UTC().Truncate(time.Minute)
 
@@ -40,6 +39,7 @@ func TestStorageExporters(t *testing.T) {
 		})
 
 		expectedPath := p.ToFullPath("", ts, "json")
+		t.Logf("expected path: %s", expectedPath)
 
 		data, err := store.Read(expectedPath)
 		if err != nil {
@@ -50,6 +50,8 @@ func TestStorageExporters(t *testing.T) {
 			t.Fatalf("expected data to be non-empty, got empty")
 		}
 
+		t.Logf("Data: %s", string(data))
+
 		var td *TestData = new(TestData)
 		if err := json.Unmarshal(data, td); err != nil {
 			t.Fatalf("failed to unmarshal data: %v", err)
@@ -70,8 +72,6 @@ func TestStorageExporters(t *testing.T) {
 
 		encoder := NewBingenEncoder[opencost.AllocationSet]()
 		export := NewComputeStorageExporter[opencost.AllocationSet](
-			pipelines.AllocationPipelineName,
-			24*time.Hour,
 			p,
 			encoder,
 			store,

+ 0 - 1
core/pkg/heartbeat/exporter/exporter.go

@@ -17,7 +17,6 @@ func NewHeartbeatExporter(clusterId string, applicationName string, storage stor
 	}
 
 	return exporter.NewEventStorageExporter(
-		heartbeat.HeartbeatEventName,
 		pathing,
 		NewHeartbeatEncoder(),
 		storage,

+ 0 - 2
core/pkg/opencost/exporter/exporters.go

@@ -30,8 +30,6 @@ func NewComputePipelineExporter[T any, U export.BinaryMarshalerPtr[T], S validat
 	}
 
 	return export.NewComputeStorageExporter(
-		pipelineName,
-		resolution,
 		pathing,
 		export.NewBingenEncoder[T, U](),
 		store,