Skip to content

Commit b9186ba

Browse files
committed
fix promlinter and boilerplate issues
Signed-off-by: Jing Liu <[email protected]>
1 parent 104e7b0 commit b9186ba

File tree

3 files changed

+71
-55
lines changed

3 files changed

+71
-55
lines changed

manager/manager.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func (m *Manager) issue(ctx context.Context, volumeID string) error {
400400
log.Info("Processing issuance")
401401

402402
// Increase issue count
403-
m.metrics.IncrementIssueCallCount(m.nodeNameHash, volumeID)
403+
m.metrics.IncrementIssueCallCountTotal(m.nodeNameHash, volumeID)
404404

405405
if err := m.cleanupStaleRequests(ctx, log, volumeID); err != nil {
406406
return fmt.Errorf("cleaning up stale requests: %w", err)
@@ -779,7 +779,7 @@ func (m *Manager) ManageVolumeImmediate(ctx context.Context, volumeID string) (m
779779
// how to proceed depending on the context this method was called within.
780780
if err := m.issue(ctx, volumeID); err != nil {
781781
// Increase issue error count
782-
m.metrics.IncrementIssueErrorCount(m.nodeNameHash, volumeID)
782+
m.metrics.IncrementIssueErrorCountTotal(m.nodeNameHash, volumeID)
783783
return true, err
784784
}
785785
}
@@ -808,7 +808,7 @@ func (m *Manager) manageVolumeIfNotManaged(volumeID string) (managed bool) {
808808
stopCh := make(chan struct{})
809809
m.managedVolumes[volumeID] = stopCh
810810
// Increase managed volume count for this driver
811-
m.metrics.IncrementManagedVolumeCount(m.nodeNameHash)
811+
m.metrics.IncrementManagedVolumeCountTotal(m.nodeNameHash)
812812

813813
return true
814814
}
@@ -828,7 +828,7 @@ func (m *Manager) startRenewalRoutine(volumeID string) (started bool) {
828828

829829
// Increase managed certificate count for this driver.
830830
// We assume each volume will have one certificate to be managed.
831-
m.metrics.IncrementManagedCertificateCount(m.nodeNameHash)
831+
m.metrics.IncrementManagedCertificateCountTotal(m.nodeNameHash)
832832

833833
// Create a context that will be cancelled when the stopCh is closed
834834
ctx, cancel := context.WithCancel(context.Background())
@@ -866,7 +866,7 @@ func (m *Manager) startRenewalRoutine(volumeID string) (started bool) {
866866
if err := m.issue(issueCtx, volumeID); err != nil {
867867
log.Error(err, "Failed to issue certificate, retrying after applying exponential backoff")
868868
// Increase issue error count
869-
m.metrics.IncrementIssueErrorCount(m.nodeNameHash, volumeID)
869+
m.metrics.IncrementIssueErrorCountTotal(m.nodeNameHash, volumeID)
870870
return false, nil
871871
}
872872
return true, nil

metrics/metrics.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ type Metrics struct {
3838
certificateRequestExpiryTimeSeconds *prometheus.GaugeVec
3939
certificateRequestRenewalTimeSeconds *prometheus.GaugeVec
4040
certificateRequestReadyStatus *prometheus.GaugeVec
41-
driverIssueCallCount *prometheus.CounterVec
42-
driverIssueErrorCount *prometheus.CounterVec
43-
managedVolumeCount *prometheus.CounterVec
44-
managedCertificateCount *prometheus.CounterVec
41+
driverIssueCallCountTotal *prometheus.CounterVec
42+
driverIssueErrorCountTotal *prometheus.CounterVec
43+
managedVolumeCountTotal *prometheus.CounterVec
44+
managedCertificateCountTotal *prometheus.CounterVec
4545
}
4646

4747
// New creates a Metrics struct and populates it with prometheus metric types.
@@ -77,41 +77,41 @@ func New(logger *logr.Logger, registry *prometheus.Registry) *Metrics {
7777
[]string{"name", "namespace", "condition", "issuer_name", "issuer_kind", "issuer_group"},
7878
)
7979

80-
driverIssueCallCount = prometheus.NewCounterVec(
80+
driverIssueCallCountTotal = prometheus.NewCounterVec(
8181
prometheus.CounterOpts{
8282
Namespace: namespace,
8383
Subsystem: subsystem,
84-
Name: "driver_issue_call_count",
84+
Name: "driver_issue_call_count_total",
8585
Help: "The number of issue() calls made by the driver.",
8686
},
8787
[]string{"node", "volume"},
8888
)
8989

90-
driverIssueErrorCount = prometheus.NewCounterVec(
90+
driverIssueErrorCountTotal = prometheus.NewCounterVec(
9191
prometheus.CounterOpts{
9292
Namespace: namespace,
9393
Subsystem: subsystem,
94-
Name: "driver_issue_error_count",
94+
Name: "driver_issue_error_count_total",
9595
Help: "The number of errors encountered during the driver issue() calls.",
9696
},
9797
[]string{"node", "volume"},
9898
)
9999

100-
managedVolumeCount = prometheus.NewCounterVec(
100+
managedVolumeCountTotal = prometheus.NewCounterVec(
101101
prometheus.CounterOpts{
102102
Namespace: namespace,
103103
Subsystem: subsystem,
104-
Name: "managed_volume_count",
104+
Name: "managed_volume_count_total",
105105
Help: "The number of volume managed by the csi driver.",
106106
},
107107
[]string{"node"},
108108
)
109109

110-
managedCertificateCount = prometheus.NewCounterVec(
110+
managedCertificateCountTotal = prometheus.NewCounterVec(
111111
prometheus.CounterOpts{
112112
Namespace: namespace,
113113
Subsystem: subsystem,
114-
Name: "managed_certificate_count",
114+
Name: "managed_certificate_count_total",
115115
Help: "The number of certificates managed by the csi driver.",
116116
},
117117
[]string{"node"},
@@ -126,19 +126,19 @@ func New(logger *logr.Logger, registry *prometheus.Registry) *Metrics {
126126
certificateRequestExpiryTimeSeconds: certificateRequestExpiryTimeSeconds,
127127
certificateRequestRenewalTimeSeconds: certificateRequestRenewalTimeSeconds,
128128
certificateRequestReadyStatus: certificateRequestReadyStatus,
129-
driverIssueCallCount: driverIssueCallCount,
130-
driverIssueErrorCount: driverIssueErrorCount,
131-
managedVolumeCount: managedVolumeCount,
132-
managedCertificateCount: managedCertificateCount,
129+
driverIssueCallCountTotal: driverIssueCallCountTotal,
130+
driverIssueErrorCountTotal: driverIssueErrorCountTotal,
131+
managedVolumeCountTotal: managedVolumeCountTotal,
132+
managedCertificateCountTotal: managedCertificateCountTotal,
133133
}
134134

135135
m.registry.MustRegister(m.certificateRequestExpiryTimeSeconds)
136136
m.registry.MustRegister(m.certificateRequestRenewalTimeSeconds)
137137
m.registry.MustRegister(m.certificateRequestReadyStatus)
138-
m.registry.MustRegister(m.driverIssueCallCount)
139-
m.registry.MustRegister(m.driverIssueErrorCount)
140-
m.registry.MustRegister(m.managedVolumeCount)
141-
m.registry.MustRegister(m.managedCertificateCount)
138+
m.registry.MustRegister(m.driverIssueCallCountTotal)
139+
m.registry.MustRegister(m.driverIssueErrorCountTotal)
140+
m.registry.MustRegister(m.managedVolumeCountTotal)
141+
m.registry.MustRegister(m.managedCertificateCountTotal)
142142

143143
return m
144144
}
@@ -151,22 +151,22 @@ func (m *Metrics) DefaultHandler() http.Handler {
151151
return mux
152152
}
153153

154-
// IncrementIssueCallCount will increase the issue call counter for the driver.
155-
func (m *Metrics) IncrementIssueCallCount(nodeNameHash, volumeID string) {
156-
m.driverIssueCallCount.WithLabelValues(nodeNameHash, volumeID).Inc()
154+
// IncrementIssueCallCountTotal will increase the issue call counter for the driver.
155+
func (m *Metrics) IncrementIssueCallCountTotal(nodeNameHash, volumeID string) {
156+
m.driverIssueCallCountTotal.WithLabelValues(nodeNameHash, volumeID).Inc()
157157
}
158158

159-
// IncrementIssueErrorCount will increase count of errors during issue call of the driver.
160-
func (m *Metrics) IncrementIssueErrorCount(nodeNameHash, volumeID string) {
161-
m.driverIssueErrorCount.WithLabelValues(nodeNameHash, volumeID).Inc()
159+
// IncrementIssueErrorCountTotal will increase count of errors during issue call of the driver.
160+
func (m *Metrics) IncrementIssueErrorCountTotal(nodeNameHash, volumeID string) {
161+
m.driverIssueErrorCountTotal.WithLabelValues(nodeNameHash, volumeID).Inc()
162162
}
163163

164-
// IncrementManagedVolumeCount will increase the managed volume counter for the driver.
165-
func (m *Metrics) IncrementManagedVolumeCount(nodeNameHash string) {
166-
m.managedVolumeCount.WithLabelValues(nodeNameHash).Inc()
164+
// IncrementManagedVolumeCountTotal will increase the managed volume counter for the driver.
165+
func (m *Metrics) IncrementManagedVolumeCountTotal(nodeNameHash string) {
166+
m.managedVolumeCountTotal.WithLabelValues(nodeNameHash).Inc()
167167
}
168168

169-
// IncrementManagedCertificateCount will increase the managed certificate count for the driver.
170-
func (m *Metrics) IncrementManagedCertificateCount(nodeNameHash string) {
171-
m.managedCertificateCount.WithLabelValues(nodeNameHash).Inc()
169+
// IncrementManagedCertificateCountTotal will increase the managed certificate count for the driver.
170+
func (m *Metrics) IncrementManagedCertificateCountTotal(nodeNameHash string) {
171+
m.managedCertificateCountTotal.WithLabelValues(nodeNameHash).Inc()
172172
}

test/integration/metrics_test.go

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 The cert-manager Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package integration
218

319
import (
@@ -207,15 +223,15 @@ certmanager_csi_certificate_request_ready_status{condition="Unknown",issuer_grou
207223
# HELP certmanager_csi_certificate_request_renewal_timestamp_seconds The number of seconds before expiration time the certificate request should renew.
208224
# TYPE certmanager_csi_certificate_request_renewal_timestamp_seconds gauge
209225
certmanager_csi_certificate_request_renewal_timestamp_seconds{issuer_group="test-issuer-group",issuer_kind="test-issuer-kind",issuer_name="test-issuer",name="test-cr-name",namespace="test-ns"} 200
210-
# HELP certmanager_csi_driver_issue_call_count The number of issue() calls made by the driver.
211-
# TYPE certmanager_csi_driver_issue_call_count counter
212-
certmanager_csi_driver_issue_call_count{node="f56fd9f8b",volume="test-vol"} 1
213-
# HELP certmanager_csi_managed_certificate_count The number of certificates managed by the csi driver.
214-
# TYPE certmanager_csi_managed_certificate_count counter
215-
certmanager_csi_managed_certificate_count{node="f56fd9f8b"} 1
216-
# HELP certmanager_csi_managed_volume_count The number of volume managed by the csi driver.
217-
# TYPE certmanager_csi_managed_volume_count counter
218-
certmanager_csi_managed_volume_count{node="f56fd9f8b"} 1
226+
# HELP certmanager_csi_driver_issue_call_count_total The number of issue() calls made by the driver.
227+
# TYPE certmanager_csi_driver_issue_call_count_total counter
228+
certmanager_csi_driver_issue_call_count_total{node="f56fd9f8b",volume="test-vol"} 1
229+
# HELP certmanager_csi_managed_certificate_count_total The number of certificates managed by the csi driver.
230+
# TYPE certmanager_csi_managed_certificate_count_total counter
231+
certmanager_csi_managed_certificate_count_total{node="f56fd9f8b"} 1
232+
# HELP certmanager_csi_managed_volume_count_total The number of volume managed by the csi driver.
233+
# TYPE certmanager_csi_managed_volume_count_total counter
234+
certmanager_csi_managed_volume_count_total{node="f56fd9f8b"} 1
219235
`
220236
waitForMetrics(t, ctx, metricsEndpoint, strings.ReplaceAll(expectedOutputTemplate, "test-cr-name", req.Name))
221237

@@ -229,15 +245,15 @@ certmanager_csi_managed_volume_count{node="f56fd9f8b"} 1
229245
}
230246

231247
// Should expose no CertificateRequest and only metrics counters
232-
waitForMetrics(t, ctx, metricsEndpoint, `# HELP certmanager_csi_driver_issue_call_count The number of issue() calls made by the driver.
233-
# TYPE certmanager_csi_driver_issue_call_count counter
234-
certmanager_csi_driver_issue_call_count{node="f56fd9f8b",volume="test-vol"} 1
235-
# HELP certmanager_csi_managed_certificate_count The number of certificates managed by the csi driver.
236-
# TYPE certmanager_csi_managed_certificate_count counter
237-
certmanager_csi_managed_certificate_count{node="f56fd9f8b"} 1
238-
# HELP certmanager_csi_managed_volume_count The number of volume managed by the csi driver.
239-
# TYPE certmanager_csi_managed_volume_count counter
240-
certmanager_csi_managed_volume_count{node="f56fd9f8b"} 1
248+
waitForMetrics(t, ctx, metricsEndpoint, `# HELP certmanager_csi_driver_issue_call_count_total The number of issue() calls made by the driver.
249+
# TYPE certmanager_csi_driver_issue_call_count_total counter
250+
certmanager_csi_driver_issue_call_count_total{node="f56fd9f8b",volume="test-vol"} 1
251+
# HELP certmanager_csi_managed_certificate_count_total The number of certificates managed by the csi driver.
252+
# TYPE certmanager_csi_managed_certificate_count_total counter
253+
certmanager_csi_managed_certificate_count_total{node="f56fd9f8b"} 1
254+
# HELP certmanager_csi_managed_volume_count_total The number of volume managed by the csi driver.
255+
# TYPE certmanager_csi_managed_volume_count_total counter
256+
certmanager_csi_managed_volume_count_total{node="f56fd9f8b"} 1
241257
`)
242258

243259
}

0 commit comments

Comments
 (0)