Skip to content

Commit

Permalink
Refactor metrics code
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Mar 18, 2024
1 parent 7905520 commit 98cf649
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
7 changes: 3 additions & 4 deletions adapter/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,9 @@ type tracing struct {

// Metrics defines the configuration for metrics collection.
type Metrics struct {
Enabled bool
Type string
Port int32
CollectionInterval int32
Enabled bool
Type string
Port int32
}

type analyticsAdapter struct {
Expand Down
11 changes: 5 additions & 6 deletions adapter/internal/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func InitOperator(metricsConfig config.Metrics) {

if metricsConfig.Enabled {
options.Metrics.BindAddress = fmt.Sprintf(":%d", metricsConfig.Port)
// Register the metrics collector
if strings.EqualFold(metricsConfig.Type, metrics.PrometheusMetricType) {
loggers.LoggerAPKOperator.Info("Registering Prometheus metrics collector.")
metrics.RegisterPrometheusCollector()
}
} else {
options.Metrics.BindAddress = "0"
}
Expand Down Expand Up @@ -145,12 +150,6 @@ func InitOperator(metricsConfig config.Metrics) {
loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2603, logging.BLOCKER, "Unable to set up ready check: %v", err))
}

// Register the metrics collector
if metricsConfig.Enabled && strings.EqualFold(metricsConfig.Type, metrics.PrometheusMetricType) {
loggers.LoggerAPKOperator.Info("Registering Prometheus metrics collector.")
go metrics.RegisterPrometheusCollector()
}

go synchronizer.HandleAPILifeCycleEvents(&ch, &successChannel)
go synchronizer.HandleGatewayLifeCycleEvents(&gatewaych)
if config.ReadConfigs().PartitionServer.Enabled {
Expand Down
7 changes: 3 additions & 4 deletions common-controller/internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ type webServer struct {

// Metrics defines the configuration for metrics collection.
type Metrics struct {
Enabled bool
Type string
Port int32
CollectionInterval int32
Enabled bool
Type string
Port int32
}

type database struct {
Expand Down
12 changes: 6 additions & 6 deletions common-controller/internal/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func InitOperator(metricsConfig config.Metrics) {

if metricsConfig.Enabled {
options.Metrics.BindAddress = fmt.Sprintf(":%d", metricsConfig.Port)

// Register the metrics collector
if strings.EqualFold(metricsConfig.Type, metrics.PrometheusMetricType) {
loggers.LoggerAPKOperator.Info("Registering Prometheus metrics collector.")
metrics.RegisterPrometheusCollector()
}
} else {
options.Metrics.BindAddress = "0"
}
Expand Down Expand Up @@ -208,12 +214,6 @@ func InitOperator(metricsConfig config.Metrics) {
}()
}

// Register the metrics collector
if metricsConfig.Enabled && strings.EqualFold(metricsConfig.Type, metrics.PrometheusMetricType) {
loggers.LoggerAPKOperator.Info("Registering Prometheus metrics collector.")
go metrics.RegisterPrometheusCollector()
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2604, logging.BLOCKER, "Problem running manager: %v", err))
Expand Down

0 comments on commit 98cf649

Please sign in to comment.