Skip to content

Commit 7407af0

Browse files
committed
[metrics] Fix panic during metrics manager startup
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.
1 parent 96338ca commit 7407af0

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

pkg/metrics/metrics.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ const (
3939
)
4040

4141
var (
42-
gkeComponentVersion *metrics.GaugeVec
43-
pdcsiOperationErrorsMetric *metrics.CounterVec
44-
)
45-
46-
func initMetrics() {
4742
// This metric is exposed only from the controller driver component when GKE_PDCSI_VERSION env variable is set.
4843
gkeComponentVersion = metrics.NewGaugeVec(&metrics.GaugeOpts{
4944
Name: "component_version",
@@ -58,7 +53,7 @@ func initMetrics() {
5853
StabilityLevel: metrics.ALPHA,
5954
},
6055
[]string{"driver_name", "method_name", "grpc_status_code", "disk_type", "enable_confidential_storage", "enable_storage_pools"})
61-
}
56+
)
6257

6358
type MetricsManager struct {
6459
registry metrics.KubeRegistry

pkg/metrics/metrics_test_util.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ package metrics
1919
// Test-only method used for resetting metric counts.
2020
func (mm *MetricsManager) ResetMetrics() {
2121
// Re-initialize metrics
22-
initMetrics()
22+
gkeComponentVersion.Reset()
23+
pdcsiOperationErrorsMetric.Reset()
2324
}

0 commit comments

Comments
 (0)