Просмотр исходного кода

use app name for wal file paths (#3322)

Signed-off-by: Sean Holcomb <seanholcomb@gmail.com>
Sean Holcomb 9 месяцев назад
Родитель
Сommit
63d4c57c98

+ 2 - 2
core/pkg/diagnostics/exporter/controller.go

@@ -8,13 +8,13 @@ import (
 
 // NewDiagnosticsExportController creates a new EventExportController for DiagnosticsRunReport events.
 func NewDiagnosticsExportController(
-	clusterId string,
 	applicationName string,
+	clusterId string,
 	store storage.Storage,
 	service diagnostics.DiagnosticService,
 ) *exporter.EventExportController[diagnostics.DiagnosticsRunReport] {
 	return exporter.NewEventExportController(
 		NewDiagnosticSource(applicationName, service),
-		NewDiagnosticExporter(clusterId, applicationName, store),
+		NewDiagnosticExporter(applicationName, clusterId, store),
 	)
 }

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

@@ -9,7 +9,7 @@ import (
 )
 
 // NewDiagnosticExporter creates a new `StorageExporter[DiagnosticsRunReport]` instance for exporting diagnostic run events.
-func NewDiagnosticExporter(clusterId string, applicationName string, storage storage.Storage) exporter.EventExporter[diagnostics.DiagnosticsRunReport] {
+func NewDiagnosticExporter(applicationName string, clusterId string, storage storage.Storage) exporter.EventExporter[diagnostics.DiagnosticsRunReport] {
 	pathing, err := pathing.NewEventStoragePathFormatter(applicationName, clusterId, diagnostics.DiagnosticsEventName)
 	if err != nil {
 		log.Errorf("failed to create pathing formatter: %v", err)

+ 6 - 0
core/pkg/env/core.go

@@ -10,6 +10,7 @@ const DefaultStorageFile = "federated-store.yaml"
 const (
 	APIPortEnvVar    = "API_PORT"
 	ClusterIDEnvVar  = "CLUSTER_ID"
+	AppNameEnvVar    = "APP_NAME"
 	ConfigPathEnvVar = "CONFIG_PATH"
 
 	PProfEnabledEnvVar = "PPROF_ENABLED"
@@ -29,6 +30,11 @@ func GetClusterID() string {
 	return Get(ClusterIDEnvVar, "")
 }
 
+// GetAppName returns the name of the application name running the values
+func GetAppName() string {
+	return Get(AppNameEnvVar, "Opencost")
+}
+
 // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
 // model configuration path
 func GetConfigPath() string {

+ 2 - 2
core/pkg/heartbeat/exporter/controller.go

@@ -9,14 +9,14 @@ import (
 // NewHeartbeatExportController creates a new EventExportController for Heartbeat events.
 // A HeartbeatMetadataProvider can optionally be provided to append metadata to the Heartbeat payload.
 func NewHeartbeatExportController(
-	clusterId string,
 	applicationName string,
+	clusterId string,
 	version string,
 	store storage.Storage,
 	provider HeartbeatMetadataProvider,
 ) *exporter.EventExportController[heartbeat.Heartbeat] {
 	return exporter.NewEventExportController(
 		NewHeartbeatSource(applicationName, version, provider),
-		NewHeartbeatExporter(clusterId, applicationName, store),
+		NewHeartbeatExporter(applicationName, clusterId, store),
 	)
 }

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

@@ -9,7 +9,7 @@ import (
 )
 
 // NewHeartbeatExporter creates a new `StorageExporter[Heartbeat]` instance for exporting Heartbeat events.
-func NewHeartbeatExporter(clusterId string, applicationName string, storage storage.Storage) exporter.EventExporter[heartbeat.Heartbeat] {
+func NewHeartbeatExporter(applicationName string, clusterId string, storage storage.Storage) exporter.EventExporter[heartbeat.Heartbeat] {
 	pathing, err := pathing.NewEventStoragePathFormatter(applicationName, clusterId, heartbeat.HeartbeatEventName)
 	if err != nil {
 		log.Errorf("failed to create pathing formatter: %v", err)

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

@@ -38,7 +38,7 @@ func TestHeartbeatExporter(t *testing.T) {
 	mdp := NewMockHeartbeatMetadataProvider()
 	store := storage.NewMemoryStorage()
 
-	controller := NewHeartbeatExportController(MockClusterId, MockApplicationName, MockVersion, store, mdp)
+	controller := NewHeartbeatExportController(MockApplicationName, MockClusterId, MockVersion, store, mdp)
 
 	if !controller.Start(time.Second) {
 		t.Fatal("Failed to start controller")

+ 9 - 7
modules/collector-source/pkg/collector/config.go

@@ -7,10 +7,11 @@ import (
 )
 
 type CollectorConfig struct {
-	Resolutions    []util.ResolutionConfiguration `json:"resolutions"`
-	ScrapeInterval string                         `json:"scrape_interval"`
-	ClusterID      string                         `json:"cluster_id"`
-	NetworkPort    int                            `json:"network_port"`
+	Resolutions     []util.ResolutionConfiguration `json:"resolutions"`
+	ScrapeInterval  string                         `json:"scrape_interval"`
+	ClusterID       string                         `json:"cluster_id"`
+	ApplicationName string                         `json:"application_name"`
+	NetworkPort     int                            `json:"network_port"`
 }
 
 func NewOpenCostCollectorConfigFromEnv() CollectorConfig {
@@ -29,8 +30,9 @@ func NewOpenCostCollectorConfigFromEnv() CollectorConfig {
 				Retention: env.GetCollection1dResolutionRetention(),
 			},
 		},
-		ScrapeInterval: env.GetCollectorScrapeIntervalSeconds(),
-		ClusterID:      coreenv.GetClusterID(),
-		NetworkPort:    env.GetNetworkPort(),
+		ScrapeInterval:  env.GetCollectorScrapeIntervalSeconds(),
+		ClusterID:       coreenv.GetClusterID(),
+		ApplicationName: coreenv.GetAppName(),
+		NetworkPort:     env.GetNetworkPort(),
 	}
 }

+ 11 - 10
modules/collector-source/pkg/collector/datasource.go

@@ -18,11 +18,11 @@ import (
 )
 
 type collectorDataSource struct {
-	metricsQuerier *collectorMetricsQuerier
-	clusterMap     clusters.ClusterMap
-	clusterInfo    clusters.ClusterInfoProvider
-	config         CollectorConfig
-	diagnosticsModule    *metric.DiagnosticsModule
+	metricsQuerier    *collectorMetricsQuerier
+	clusterMap        clusters.ClusterMap
+	clusterInfo       clusters.ClusterInfoProvider
+	config            CollectorConfig
+	diagnosticsModule *metric.DiagnosticsModule
 }
 
 func NewDefaultCollectorDataSource(
@@ -67,6 +67,7 @@ func NewCollectorDataSource(
 	if store != nil {
 		wal, err := metric.NewWalinator(
 			config.ClusterID,
+			config.ApplicationName,
 			store,
 			resolutions,
 			updater,
@@ -98,11 +99,11 @@ func NewCollectorDataSource(
 	clusterMap := newCollectorClusterMap(clusterInfo)
 
 	return &collectorDataSource{
-		config:         config,
-		metricsQuerier: metricQuerier,
-		clusterInfo:    clusterInfo,
-		clusterMap:     clusterMap,
-		diagnosticsModule:    diagnosticsModule,
+		config:            config,
+		metricsQuerier:    metricQuerier,
+		clusterInfo:       clusterInfo,
+		clusterMap:        clusterMap,
+		diagnosticsModule: diagnosticsModule,
 	}
 }
 

+ 2 - 1
modules/collector-source/pkg/metric/walinator.go

@@ -37,6 +37,7 @@ type Walinator struct {
 
 func NewWalinator(
 	clusterID string,
+	applicationName string,
 	store storage.Storage,
 	resolutions []*util.Resolution,
 	updater Updater,
@@ -47,7 +48,7 @@ func NewWalinator(
 			limitResolution = resolution
 		}
 	}
-	pathFormatter, err := pathing.NewEventStoragePathFormatter("", clusterID, ControllerEventName)
+	pathFormatter, err := pathing.NewEventStoragePathFormatter(applicationName, clusterID, ControllerEventName)
 	if err != nil {
 		return nil, fmt.Errorf("filed to create path formatter for scrape controller: %s", err.Error())
 	}

+ 3 - 0
modules/collector-source/pkg/metric/walinator_test.go

@@ -58,6 +58,7 @@ func TestWalinator_Update(t *testing.T) {
 		testMetricCollector,
 	)
 	wal, _ := NewWalinator(
+		"test",
 		"test",
 		store,
 		resolutions,
@@ -107,6 +108,7 @@ func TestWalinator_restore(t *testing.T) {
 		testMetricCollector,
 	)
 	wal, _ := NewWalinator(
+		"test",
 		"test",
 		store,
 		resolutions,
@@ -219,6 +221,7 @@ func TestWalinator_clean(t *testing.T) {
 		testMetricCollector,
 	)
 	wal, _ := NewWalinator(
+		"test",
 		"test",
 		store,
 		resolutions,