Skip to content

Commit

Permalink
[metrics] Fix panic during metrics manager startup
Browse files Browse the repository at this point in the history
This fixes a regression introduced in #1876 where the driver would start
panicking on startup if `--http-endpoint` was specified. This was caused
by the metrics not being initialized anymore during startup. The
proposed fix involves using the `Reset` methods of the metrics object
instead of trying to redefine them each time they need to be reset.
  • Loading branch information
Fricounet committed Dec 18, 2024
1 parent 96338ca commit 7407af0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
7 changes: 1 addition & 6 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ const (
)

var (
gkeComponentVersion *metrics.GaugeVec
pdcsiOperationErrorsMetric *metrics.CounterVec
)

func initMetrics() {
// This metric is exposed only from the controller driver component when GKE_PDCSI_VERSION env variable is set.
gkeComponentVersion = metrics.NewGaugeVec(&metrics.GaugeOpts{
Name: "component_version",
Expand All @@ -58,7 +53,7 @@ func initMetrics() {
StabilityLevel: metrics.ALPHA,
},
[]string{"driver_name", "method_name", "grpc_status_code", "disk_type", "enable_confidential_storage", "enable_storage_pools"})
}
)

type MetricsManager struct {
registry metrics.KubeRegistry
Expand Down
3 changes: 2 additions & 1 deletion pkg/metrics/metrics_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ package metrics
// Test-only method used for resetting metric counts.
func (mm *MetricsManager) ResetMetrics() {
// Re-initialize metrics
initMetrics()
gkeComponentVersion.Reset()
pdcsiOperationErrorsMetric.Reset()
}

0 comments on commit 7407af0

Please sign in to comment.