diff --git a/pkg/server/options/encryptionconfig/controller/controller_test.go b/pkg/server/options/encryptionconfig/controller/controller_test.go index c68ed064e..900746324 100644 --- a/pkg/server/options/encryptionconfig/controller/controller_test.go +++ b/pkg/server/options/encryptionconfig/controller/controller_test.go @@ -44,17 +44,11 @@ func TestController(t *testing.T) { featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.KMSv1, true) const expectedSuccessMetricValue = ` -# HELP apiserver_encryption_config_controller_automatic_reload_success_total [ALPHA] Total number of successful automatic reloads of encryption configuration split by apiserver identity. -# TYPE apiserver_encryption_config_controller_automatic_reload_success_total counter -apiserver_encryption_config_controller_automatic_reload_success_total{apiserver_id_hash="sha256:cd8a60cec6134082e9f37e7a4146b4bc14a0bf8a863237c36ec8fdb658c3e027"} 1 # HELP apiserver_encryption_config_controller_automatic_reloads_total [ALPHA] Total number of reload successes and failures of encryption configuration split by apiserver identity. # TYPE apiserver_encryption_config_controller_automatic_reloads_total counter apiserver_encryption_config_controller_automatic_reloads_total{apiserver_id_hash="sha256:cd8a60cec6134082e9f37e7a4146b4bc14a0bf8a863237c36ec8fdb658c3e027",status="success"} 1 ` const expectedFailureMetricValue = ` -# HELP apiserver_encryption_config_controller_automatic_reload_failures_total [ALPHA] Total number of failed automatic reloads of encryption configuration split by apiserver identity. -# TYPE apiserver_encryption_config_controller_automatic_reload_failures_total counter -apiserver_encryption_config_controller_automatic_reload_failures_total{apiserver_id_hash="sha256:cd8a60cec6134082e9f37e7a4146b4bc14a0bf8a863237c36ec8fdb658c3e027"} 1 # HELP apiserver_encryption_config_controller_automatic_reloads_total [ALPHA] Total number of reload successes and failures of encryption configuration split by apiserver identity. # TYPE apiserver_encryption_config_controller_automatic_reloads_total counter apiserver_encryption_config_controller_automatic_reloads_total{apiserver_id_hash="sha256:cd8a60cec6134082e9f37e7a4146b4bc14a0bf8a863237c36ec8fdb658c3e027",status="failure"} 1 @@ -338,8 +332,6 @@ apiserver_encryption_config_controller_automatic_reloads_total{apiserver_id_hash } if err := testutil.GatherAndCompare(legacyregistry.DefaultGatherer, strings.NewReader(test.wantMetrics), - "apiserver_encryption_config_controller_automatic_reload_success_total", - "apiserver_encryption_config_controller_automatic_reload_failures_total", "apiserver_encryption_config_controller_automatic_reloads_total", ); err != nil { t.Errorf("failed to validate metrics: %v", err) diff --git a/pkg/server/options/encryptionconfig/metrics/metrics.go b/pkg/server/options/encryptionconfig/metrics/metrics.go index 745277002..43b6ebbf3 100644 --- a/pkg/server/options/encryptionconfig/metrics/metrics.go +++ b/pkg/server/options/encryptionconfig/metrics/metrics.go @@ -43,34 +43,6 @@ var ( []string{"status", "apiserver_id_hash"}, ) - // deprecatedEncryptionConfigAutomaticReloadFailureTotal has been deprecated in 1.30.0 - // use encryptionConfigAutomaticReloadsTotal instead - deprecatedEncryptionConfigAutomaticReloadFailureTotal = metrics.NewCounterVec( - &metrics.CounterOpts{ - Namespace: namespace, - Subsystem: subsystem, - Name: "automatic_reload_failures_total", - Help: "Total number of failed automatic reloads of encryption configuration split by apiserver identity.", - StabilityLevel: metrics.ALPHA, - DeprecatedVersion: "1.30.0", - }, - []string{"apiserver_id_hash"}, - ) - - // deprecatedEncryptionConfigAutomaticReloadSuccessTotal has been deprecated in 1.30.0 - // use encryptionConfigAutomaticReloadsTotal instead - deprecatedEncryptionConfigAutomaticReloadSuccessTotal = metrics.NewCounterVec( - &metrics.CounterOpts{ - Namespace: namespace, - Subsystem: subsystem, - Name: "automatic_reload_success_total", - Help: "Total number of successful automatic reloads of encryption configuration split by apiserver identity.", - StabilityLevel: metrics.ALPHA, - DeprecatedVersion: "1.30.0", - }, - []string{"apiserver_id_hash"}, - ) - encryptionConfigAutomaticReloadLastTimestampSeconds = metrics.NewGaugeVec( &metrics.GaugeOpts{ Namespace: namespace, @@ -94,8 +66,6 @@ func RegisterMetrics() { }, } legacyregistry.MustRegister(encryptionConfigAutomaticReloadsTotal) - legacyregistry.MustRegister(deprecatedEncryptionConfigAutomaticReloadFailureTotal) - legacyregistry.MustRegister(deprecatedEncryptionConfigAutomaticReloadSuccessTotal) legacyregistry.MustRegister(encryptionConfigAutomaticReloadLastTimestampSeconds) }) } @@ -103,14 +73,12 @@ func RegisterMetrics() { func RecordEncryptionConfigAutomaticReloadFailure(apiServerID string) { apiServerIDHash := getHash(apiServerID) encryptionConfigAutomaticReloadsTotal.WithLabelValues("failure", apiServerIDHash).Inc() - deprecatedEncryptionConfigAutomaticReloadFailureTotal.WithLabelValues(apiServerIDHash).Inc() recordEncryptionConfigAutomaticReloadTimestamp("failure", apiServerIDHash) } func RecordEncryptionConfigAutomaticReloadSuccess(apiServerID string) { apiServerIDHash := getHash(apiServerID) encryptionConfigAutomaticReloadsTotal.WithLabelValues("success", apiServerIDHash).Inc() - deprecatedEncryptionConfigAutomaticReloadSuccessTotal.WithLabelValues(apiServerIDHash).Inc() recordEncryptionConfigAutomaticReloadTimestamp("success", apiServerIDHash) } diff --git a/pkg/server/options/encryptionconfig/metrics/metrics_test.go b/pkg/server/options/encryptionconfig/metrics/metrics_test.go index 30adf0d8d..281ed9608 100644 --- a/pkg/server/options/encryptionconfig/metrics/metrics_test.go +++ b/pkg/server/options/encryptionconfig/metrics/metrics_test.go @@ -20,7 +20,7 @@ import ( "strings" "testing" - "k8s.io/component-base/metrics" + "k8s.io/component-base/metrics/legacyregistry" "k8s.io/component-base/metrics/testutil" ) @@ -29,53 +29,27 @@ const ( testAPIServerIDHash = "sha256:14f9d63e669337ac6bfda2e2162915ee6a6067743eddd4e5c374b572f951ff37" ) -func testMetricsRegistry(t *testing.T) metrics.KubeRegistry { - // setting the version to 1.30.0 to test deprecation - // of deprecatedEncryptionConfigAutomaticReloadFailureTotal and deprecatedEncryptionConfigAutomaticReloadSuccessTotal - registry := testutil.NewFakeKubeRegistry("1.30.0") - registry.MustRegister(encryptionConfigAutomaticReloadsTotal) - registry.MustRegister(deprecatedEncryptionConfigAutomaticReloadFailureTotal) - registry.MustRegister(deprecatedEncryptionConfigAutomaticReloadSuccessTotal) - registry.MustRegister(encryptionConfigAutomaticReloadLastTimestampSeconds) - - t.Cleanup(func() { registry.Reset() }) - - return registry -} - func TestRecordEncryptionConfigAutomaticReloadFailure(t *testing.T) { - registry := testMetricsRegistry(t) - expectedValue := ` - # HELP apiserver_encryption_config_controller_automatic_reload_failures_total [ALPHA] (Deprecated since 1.30.0) Total number of failed automatic reloads of encryption configuration split by apiserver identity. - # TYPE apiserver_encryption_config_controller_automatic_reload_failures_total counter - apiserver_encryption_config_controller_automatic_reload_failures_total {apiserver_id_hash="sha256:14f9d63e669337ac6bfda2e2162915ee6a6067743eddd4e5c374b572f951ff37"} 1 # HELP apiserver_encryption_config_controller_automatic_reloads_total [ALPHA] Total number of reload successes and failures of encryption configuration split by apiserver identity. # TYPE apiserver_encryption_config_controller_automatic_reloads_total counter apiserver_encryption_config_controller_automatic_reloads_total {apiserver_id_hash="sha256:14f9d63e669337ac6bfda2e2162915ee6a6067743eddd4e5c374b572f951ff37",status="failure"} 1 ` metricNames := []string{ - namespace + "_" + subsystem + "_automatic_reload_failures_total", namespace + "_" + subsystem + "_automatic_reloads_total", } - deprecatedEncryptionConfigAutomaticReloadFailureTotal.Reset() encryptionConfigAutomaticReloadsTotal.Reset() RegisterMetrics() RecordEncryptionConfigAutomaticReloadFailure(testAPIServerID) - if err := testutil.GatherAndCompare(registry, strings.NewReader(expectedValue), metricNames...); err != nil { + if err := testutil.GatherAndCompare(legacyregistry.DefaultGatherer, strings.NewReader(expectedValue), metricNames...); err != nil { t.Fatal(err) } } func TestRecordEncryptionConfigAutomaticReloadSuccess(t *testing.T) { - registry := testMetricsRegistry(t) - expectedValue := ` - # HELP apiserver_encryption_config_controller_automatic_reload_success_total [ALPHA] (Deprecated since 1.30.0) Total number of successful automatic reloads of encryption configuration split by apiserver identity. - # TYPE apiserver_encryption_config_controller_automatic_reload_success_total counter - apiserver_encryption_config_controller_automatic_reload_success_total {apiserver_id_hash="sha256:14f9d63e669337ac6bfda2e2162915ee6a6067743eddd4e5c374b572f951ff37"} 1 # HELP apiserver_encryption_config_controller_automatic_reloads_total [ALPHA] Total number of reload successes and failures of encryption configuration split by apiserver identity. # TYPE apiserver_encryption_config_controller_automatic_reloads_total counter apiserver_encryption_config_controller_automatic_reloads_total {apiserver_id_hash="sha256:14f9d63e669337ac6bfda2e2162915ee6a6067743eddd4e5c374b572f951ff37",status="success"} 1 @@ -85,12 +59,11 @@ func TestRecordEncryptionConfigAutomaticReloadSuccess(t *testing.T) { namespace + "_" + subsystem + "_automatic_reloads_total", } - deprecatedEncryptionConfigAutomaticReloadSuccessTotal.Reset() encryptionConfigAutomaticReloadsTotal.Reset() RegisterMetrics() RecordEncryptionConfigAutomaticReloadSuccess(testAPIServerID) - if err := testutil.GatherAndCompare(registry, strings.NewReader(expectedValue), metricNames...); err != nil { + if err := testutil.GatherAndCompare(legacyregistry.DefaultGatherer, strings.NewReader(expectedValue), metricNames...); err != nil { t.Fatal(err) } } @@ -127,12 +100,10 @@ func TestEncryptionConfigAutomaticReloadLastTimestampSeconds(t *testing.T) { RegisterMetrics() for _, tc := range testCases { - registry := testMetricsRegistry(t) - encryptionConfigAutomaticReloadLastTimestampSeconds.Reset() encryptionConfigAutomaticReloadLastTimestampSeconds.WithLabelValues(tc.resultLabel, testAPIServerIDHash).Set(float64(tc.timestamp)) - if err := testutil.GatherAndCompare(registry, strings.NewReader(tc.expectedValue), metricNames...); err != nil { + if err := testutil.GatherAndCompare(legacyregistry.DefaultGatherer, strings.NewReader(tc.expectedValue), metricNames...); err != nil { t.Fatal(err) } }