Skip to content

Commit 139d714

Browse files
committed
Change some metrics type from count to gauge
- certmanager_csi_managed_volume_count_total → certmanager_csi_managed_volume_count - certmanager_csi_managed_certificate_request_count_total → certmanager_csi_managed_certificate_request_count Signed-off-by: Jing Liu <jingliu@apple.com>
1 parent f231d25 commit 139d714

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

metrics/certificaterequest_collector.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ var (
3939
certRequestReadyStatusMetric = prometheus.NewDesc("certmanager_csi_certificate_request_ready_status", "The ready status of the certificate request.", []string{"name", "namespace", "condition", "issuer_name", "issuer_kind", "issuer_group"}, nil)
4040
certRequestExpirationTimestampSeconds = prometheus.NewDesc("certmanager_csi_certificate_request_expiration_timestamp_seconds", "The timestamp after which the certificate request expires, expressed in Unix Epoch Time.", []string{"name", "namespace", "issuer_name", "issuer_kind", "issuer_group"}, nil)
4141
certRequestRenewalTimestampSeconds = prometheus.NewDesc("certmanager_csi_certificate_request_renewal_timestamp_seconds", "The timestamp after which the certificate request should be renewed, expressed in Unix Epoch Time.", []string{"name", "namespace", "issuer_name", "issuer_kind", "issuer_group"}, nil)
42-
managedVolumeCountTotal = prometheus.NewDesc("certmanager_csi_managed_volume_count_total", "The total number of managed volumes by the csi driver.", []string{"node"}, nil)
43-
managedCertRequestCountTotal = prometheus.NewDesc("certmanager_csi_managed_certificate_request_count_total", "The total number of managed certificate requests by the csi driver.", []string{"node"}, nil)
42+
managedVolumeCount = prometheus.NewDesc("certmanager_csi_managed_volume_count", "The number of managed volumes by the csi driver.", []string{"node"}, nil)
43+
managedCertRequestCount = prometheus.NewDesc("certmanager_csi_managed_certificate_request_count", "The number of managed certificate requests by the csi driver.", []string{"node"}, nil)
4444
)
4545

4646
type CertificateRequestCollector struct {
@@ -50,8 +50,8 @@ type CertificateRequestCollector struct {
5050
certificateRequestReadyStatusMetric *prometheus.Desc
5151
certificateRequestExpirationTimestampSeconds *prometheus.Desc
5252
certificateRequestRenewalTimestampSeconds *prometheus.Desc
53-
managedVolumeCountTotal *prometheus.Desc
54-
managedCertificateRequestCountTotal *prometheus.Desc
53+
managedVolumeCount *prometheus.Desc
54+
managedCertificateRequestCount *prometheus.Desc
5555
}
5656

5757
func NewCertificateRequestCollector(nodeNameHash string, metadataReader storage.MetadataReader, certificateRequestLister cmlisters.CertificateRequestLister) prometheus.Collector {
@@ -62,17 +62,17 @@ func NewCertificateRequestCollector(nodeNameHash string, metadataReader storage.
6262
certificateRequestReadyStatusMetric: certRequestReadyStatusMetric,
6363
certificateRequestExpirationTimestampSeconds: certRequestExpirationTimestampSeconds,
6464
certificateRequestRenewalTimestampSeconds: certRequestRenewalTimestampSeconds,
65-
managedVolumeCountTotal: managedVolumeCountTotal,
66-
managedCertificateRequestCountTotal: managedCertRequestCountTotal,
65+
managedVolumeCount: managedVolumeCount,
66+
managedCertificateRequestCount: managedCertRequestCount,
6767
}
6868
}
6969

7070
func (cc *CertificateRequestCollector) Describe(ch chan<- *prometheus.Desc) {
7171
ch <- cc.certificateRequestReadyStatusMetric
7272
ch <- cc.certificateRequestExpirationTimestampSeconds
7373
ch <- cc.certificateRequestRenewalTimestampSeconds
74-
ch <- cc.managedVolumeCountTotal
75-
ch <- cc.managedCertificateRequestCountTotal
74+
ch <- cc.managedVolumeCount
75+
ch <- cc.managedCertificateRequestCount
7676
}
7777

7878
func (cc *CertificateRequestCollector) Collect(ch chan<- prometheus.Metric) {
@@ -228,8 +228,8 @@ func (cc *CertificateRequestCollector) getNextIssuanceTimeMapFromMetadata() (map
228228

229229
func (cc *CertificateRequestCollector) updateManagedVolumeCount(count int, ch chan<- prometheus.Metric) {
230230
metric := prometheus.MustNewConstMetric(
231-
cc.managedVolumeCountTotal,
232-
prometheus.CounterValue,
231+
cc.managedVolumeCount,
232+
prometheus.GaugeValue,
233233
float64(count),
234234
cc.nodeNameHash,
235235
)
@@ -239,8 +239,8 @@ func (cc *CertificateRequestCollector) updateManagedVolumeCount(count int, ch ch
239239

240240
func (cc *CertificateRequestCollector) updateManagedCertificateRequestCount(count int, ch chan<- prometheus.Metric) {
241241
metric := prometheus.MustNewConstMetric(
242-
cc.managedCertificateRequestCountTotal,
243-
prometheus.CounterValue,
242+
cc.managedCertificateRequestCount,
243+
prometheus.GaugeValue,
244244
float64(count),
245245
cc.nodeNameHash,
246246
)

test/integration/metrics_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ func TestMetricsServer(t *testing.T) {
185185

186186
// Should expose no additional metrics
187187
metricsEndpoint := fmt.Sprintf("http://%s/metrics", metricsServer.Addr)
188-
waitForMetrics(t, ctx, metricsEndpoint, `# HELP certmanager_csi_managed_certificate_request_count_total The total number of managed certificate requests by the csi driver.
189-
# TYPE certmanager_csi_managed_certificate_request_count_total counter
190-
certmanager_csi_managed_certificate_request_count_total{node="f56fd9f8b"} 0
191-
# HELP certmanager_csi_managed_volume_count_total The total number of managed volumes by the csi driver.
192-
# TYPE certmanager_csi_managed_volume_count_total counter
193-
certmanager_csi_managed_volume_count_total{node="f56fd9f8b"} 0
188+
waitForMetrics(t, ctx, metricsEndpoint, `# HELP certmanager_csi_managed_certificate_request_count The number of managed certificate requests by the csi driver.
189+
# TYPE certmanager_csi_managed_certificate_request_count gauge
190+
certmanager_csi_managed_certificate_request_count{node="f56fd9f8b"} 0
191+
# HELP certmanager_csi_managed_volume_count The number of managed volumes by the csi driver.
192+
# TYPE certmanager_csi_managed_volume_count gauge
193+
certmanager_csi_managed_volume_count{node="f56fd9f8b"} 0
194194
`)
195195

196196
// Create a self-signed Certificate and wait for it to be issued
@@ -247,12 +247,12 @@ certmanager_csi_certificate_request_renewal_timestamp_seconds{issuer_group="test
247247
# HELP certmanager_csi_issue_requests_total The number of issue() calls made by the driver.
248248
# TYPE certmanager_csi_issue_requests_total counter
249249
certmanager_csi_issue_requests_total{node="f56fd9f8b",volume="test-vol"} 1
250-
# HELP certmanager_csi_managed_certificate_request_count_total The total number of managed certificate requests by the csi driver.
251-
# TYPE certmanager_csi_managed_certificate_request_count_total counter
252-
certmanager_csi_managed_certificate_request_count_total{node="f56fd9f8b"} 1
253-
# HELP certmanager_csi_managed_volume_count_total The total number of managed volumes by the csi driver.
254-
# TYPE certmanager_csi_managed_volume_count_total counter
255-
certmanager_csi_managed_volume_count_total{node="f56fd9f8b"} 1
250+
# HELP certmanager_csi_managed_certificate_request_count The number of managed certificate requests by the csi driver.
251+
# TYPE certmanager_csi_managed_certificate_request_count gauge
252+
certmanager_csi_managed_certificate_request_count{node="f56fd9f8b"} 1
253+
# HELP certmanager_csi_managed_volume_count The number of managed volumes by the csi driver.
254+
# TYPE certmanager_csi_managed_volume_count gauge
255+
certmanager_csi_managed_volume_count{node="f56fd9f8b"} 1
256256
`
257257
waitForMetrics(t, ctx, metricsEndpoint, strings.ReplaceAll(expectedOutputTemplate, "test-cr-name", req.Name))
258258

@@ -273,12 +273,12 @@ certmanager_csi_managed_volume_count_total{node="f56fd9f8b"} 1
273273
waitForMetrics(t, ctx, metricsEndpoint, `# HELP certmanager_csi_issue_requests_total The number of issue() calls made by the driver.
274274
# TYPE certmanager_csi_issue_requests_total counter
275275
certmanager_csi_issue_requests_total{node="f56fd9f8b",volume="test-vol"} 1
276-
# HELP certmanager_csi_managed_certificate_request_count_total The total number of managed certificate requests by the csi driver.
277-
# TYPE certmanager_csi_managed_certificate_request_count_total counter
278-
certmanager_csi_managed_certificate_request_count_total{node="f56fd9f8b"} 0
279-
# HELP certmanager_csi_managed_volume_count_total The total number of managed volumes by the csi driver.
280-
# TYPE certmanager_csi_managed_volume_count_total counter
281-
certmanager_csi_managed_volume_count_total{node="f56fd9f8b"} 0
276+
# HELP certmanager_csi_managed_certificate_request_count The number of managed certificate requests by the csi driver.
277+
# TYPE certmanager_csi_managed_certificate_request_count gauge
278+
certmanager_csi_managed_certificate_request_count{node="f56fd9f8b"} 0
279+
# HELP certmanager_csi_managed_volume_count The number of managed volumes by the csi driver.
280+
# TYPE certmanager_csi_managed_volume_count gauge
281+
certmanager_csi_managed_volume_count{node="f56fd9f8b"} 0
282282
`)
283283

284284
}

0 commit comments

Comments
 (0)