Skip to content

Commit cd097df

Browse files
committed
Renaming metrics
1 parent 7b18cbe commit cd097df

File tree

4 files changed

+98
-98
lines changed

4 files changed

+98
-98
lines changed

e2e/backup/backup_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,27 @@ func formatBackupMetrics(backups []string) string {
8383
metrics += fmt.Sprintf("rancher_backup_count %d", len(backups))
8484

8585
rancherBackupsAttemptedHeader := fmt.Sprint(`
86-
# HELP rancher_backups_attempted Number of Rancher Backups processed by this operator
87-
# TYPE rancher_backups_attempted counter
86+
# HELP rancher_backups_attempted_total Number of Rancher Backups processed by this operator
87+
# TYPE rancher_backups_attempted_total counter
8888
`)
8989

9090
metrics += rancherBackupsAttemptedHeader
9191
for _, b := range backups {
9292
if b == s3Recurring {
93-
metrics += fmt.Sprintf("rancher_backups_attempted{name=\"%s\"} 2\n", b)
93+
metrics += fmt.Sprintf("rancher_backups_attempted_total{name=\"%s\"} 2\n", b)
9494
} else {
95-
metrics += fmt.Sprintf("rancher_backups_attempted{name=\"%s\"} 1\n", b)
95+
metrics += fmt.Sprintf("rancher_backups_attempted_total{name=\"%s\"} 1\n", b)
9696
}
9797
}
9898

9999
rancherBackupsFailedHeader := fmt.Sprint(`
100-
# HELP rancher_backups_failed Number of failed Rancher Backups processed by this operator
101-
# TYPE rancher_backups_failed counter
100+
# HELP rancher_backups_failed_total Number of failed Rancher Backups processed by this operator
101+
# TYPE rancher_backups_failed_total counter
102102
`)
103103

104104
metrics += rancherBackupsFailedHeader
105105
for _, b := range backups {
106-
metrics += fmt.Sprintf("rancher_backups_failed{name=\"%s\"} 0\n", b)
106+
metrics += fmt.Sprintf("rancher_backups_failed_total{name=\"%s\"} 0\n", b)
107107
}
108108

109109
return metrics + "\n"
@@ -248,8 +248,8 @@ var _ = Describe("Backup e2e remote", Ordered, Label("integration"), func() {
248248

249249
return promtestutil.ScrapeAndCompare(metricsURL, strings.NewReader(expected),
250250
"rancher_backup_count",
251-
"rancher_backups_attempted",
252-
"rancher_backups_failed",
251+
"rancher_backups_attempted_total",
252+
"rancher_backups_failed_total",
253253
)
254254
}).Should(Succeed())
255255
})
@@ -293,8 +293,8 @@ var _ = Describe("Backup e2e remote", Ordered, Label("integration"), func() {
293293

294294
return promtestutil.ScrapeAndCompare(metricsURL, strings.NewReader(expected),
295295
"rancher_backup_count",
296-
"rancher_backups_attempted",
297-
"rancher_backups_failed",
296+
"rancher_backups_attempted_total",
297+
"rancher_backups_failed_total",
298298
)
299299
}).Should(Succeed())
300300
})
@@ -379,8 +379,8 @@ var _ = Describe("Backup e2e remote", Ordered, Label("integration"), func() {
379379

380380
return promtestutil.ScrapeAndCompare(metricsURL, strings.NewReader(expected),
381381
"rancher_backup_count",
382-
"rancher_backups_attempted",
383-
"rancher_backups_failed",
382+
"rancher_backups_attempted_total",
383+
"rancher_backups_failed_total",
384384
)
385385
}).Should(Succeed())
386386
})
@@ -452,8 +452,8 @@ var _ = Describe("Backup e2e remote", Ordered, Label("integration"), func() {
452452

453453
return promtestutil.ScrapeAndCompare(metricsURL, strings.NewReader(expected),
454454
"rancher_backup_count",
455-
"rancher_backups_attempted",
456-
"rancher_backups_failed",
455+
"rancher_backups_attempted_total",
456+
"rancher_backups_failed_total",
457457
)
458458
}).Should(Succeed())
459459
})
@@ -528,8 +528,8 @@ var _ = Describe("Backup e2e remote", Ordered, Label("integration"), func() {
528528

529529
return promtestutil.ScrapeAndCompare(metricsURL, strings.NewReader(expected),
530530
"rancher_backup_count",
531-
"rancher_backups_attempted",
532-
"rancher_backups_failed",
531+
"rancher_backups_attempted_total",
532+
"rancher_backups_failed_total",
533533
)
534534
}).Should(Succeed())
535535
})

pkg/controllers/backup/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (h *handler) OnBackupChange(_ string, backup *v1.Backup) (*v1.Backup, error
147147
backupStartTS := time.Now()
148148
defer func() {
149149
backupDoneTS := time.Now()
150-
monitoring.UpdateTimeSensitiveBackupMetrics(backup.Name, backupDoneTS.Unix(), backupDoneTS.Sub(backupStartTS).Milliseconds())
150+
monitoring.UpdateTimeSensitiveBackupMetrics(backup.Name, float64(backupDoneTS.Unix()), backupDoneTS.Sub(backupStartTS).Seconds())
151151
monitoring.UpdateProcessedBackupMetrics(backup.Name, &err)
152152
}()
153153
}

pkg/monitoring/metrics.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
var (
2222
backup = promauto.NewGaugeVec(
2323
prometheus.GaugeOpts{
24-
Name: "rancher_backup",
24+
Name: "rancher_backup_info",
2525
Help: "Details on a specific Rancher Backup CR",
2626
}, []string{"name", "status", "resourceSetName", "retentionCount", "backupType", "filename", "storageLocation", "nextSnapshot", "lastSnapshot"},
2727
)
@@ -35,36 +35,36 @@ var (
3535

3636
backupsAttempted = promauto.NewCounterVec(
3737
prometheus.CounterOpts{
38-
Name: "rancher_backups_attempted",
38+
Name: "rancher_backups_attempted_total",
3939
Help: "Number of Rancher Backups processed by this operator",
4040
}, []string{"name"},
4141
)
4242

4343
backupsFailed = promauto.NewCounterVec(
4444
prometheus.CounterOpts{
45-
Name: "rancher_backups_failed",
45+
Name: "rancher_backups_failed_total",
4646
Help: "Number of failed Rancher Backups processed by this operator",
4747
}, []string{"name"},
4848
)
4949

5050
backupDuration = promauto.NewHistogramVec(
5151
prometheus.HistogramOpts{
52-
Name: "rancher_backup_duration_ms",
53-
Help: "Duration of each backup processed by this operator in ms",
54-
Buckets: []float64{500, 1000, 2500, 5000, 7500, 10000, 30000, 60000, 120000},
52+
Name: "rancher_backup_duration_seconds",
53+
Help: "Duration of each backup processed by this operator in seconds",
54+
Buckets: []float64{0.5, 1, 2.5, 5, 7.5, 10, 30, 60, 120},
5555
}, []string{"name"},
5656
)
5757

5858
backupLastProcessed = promauto.NewGaugeVec(
5959
prometheus.GaugeOpts{
60-
Name: "rancher_backup_last_processed",
60+
Name: "rancher_backup_last_processed_timestamp_seconds",
6161
Help: "Unix time of when the last Backup was processed (in seconds)",
6262
}, []string{"name"},
6363
)
6464

6565
restore = promauto.NewGaugeVec(
6666
prometheus.GaugeOpts{
67-
Name: "rancher_restore",
67+
Name: "rancher_restore_info",
6868
Help: "Details on a specific Rancher Restore CR",
6969
}, []string{"name", "status", "fileName", "prune", "storageLocation", "restoreTime"},
7070
)
@@ -145,9 +145,9 @@ func UpdateProcessedBackupMetrics(backup string, err *error) {
145145
backupsFailed.WithLabelValues(backup)
146146
}
147147

148-
func UpdateTimeSensitiveBackupMetrics(backup string, endTime int64, totalTime int64) {
149-
backupDuration.WithLabelValues(backup).Observe(float64(totalTime))
150-
backupLastProcessed.WithLabelValues(backup).Set(float64(endTime))
148+
func UpdateTimeSensitiveBackupMetrics(backup string, endTime float64, totalTime float64) {
149+
backupDuration.WithLabelValues(backup).Observe(totalTime)
150+
backupLastProcessed.WithLabelValues(backup).Set(endTime)
151151
}
152152

153153
func StartRestoreMetricsCollection(

pkg/monitoring/metrics_test.go

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ func TestUpdateTimeSensitiveBackupMetrics(t *testing.T) {
2121
t.Cleanup(resetMetrics)
2222

2323
mockBackupName := "backup1"
24-
mockEndTime := time.Now().Unix()
25-
mockTotalTime := int64(1500) // 1.5 seconds
24+
mockEndTime := float64(time.Now().Unix())
25+
mockTotalTime := float64(1.5)
2626

2727
UpdateTimeSensitiveBackupMetrics(mockBackupName, mockEndTime, mockTotalTime)
2828

2929
const expectedDuration = `
3030
# HELP rancher_backup_duration_ms Duration of each backup processed by this operator in ms
3131
# TYPE rancher_backup_duration_ms histogram
32-
rancher_backup_duration_ms_bucket{name="backup1",le="500"} 0
33-
rancher_backup_duration_ms_bucket{name="backup1",le="1000"} 0
34-
rancher_backup_duration_ms_bucket{name="backup1",le="2500"} 1
35-
rancher_backup_duration_ms_bucket{name="backup1",le="5000"} 1
36-
rancher_backup_duration_ms_bucket{name="backup1",le="7500"} 1
37-
rancher_backup_duration_ms_bucket{name="backup1",le="10000"} 1
38-
rancher_backup_duration_ms_bucket{name="backup1",le="30000"} 1
39-
rancher_backup_duration_ms_bucket{name="backup1",le="60000"} 1
40-
rancher_backup_duration_ms_bucket{name="backup1",le="120000"} 1
41-
rancher_backup_duration_ms_bucket{name="backup1",le="+Inf"} 1
42-
rancher_backup_duration_ms_sum{name="backup1"} 1500
43-
rancher_backup_duration_ms_count{name="backup1"} 1
32+
rancher_backup_duration_seconds_bucket{name="backup1",le="0.5"} 0
33+
rancher_backup_duration_seconds_bucket{name="backup1",le="1"} 0
34+
rancher_backup_duration_seconds_bucket{name="backup1",le="2.5"} 1
35+
rancher_backup_duration_seconds_bucket{name="backup1",le="5"} 1
36+
rancher_backup_duration_seconds_bucket{name="backup1",le="7.5"} 1
37+
rancher_backup_duration_seconds_bucket{name="backup1",le="10"} 1
38+
rancher_backup_duration_seconds_bucket{name="backup1",le="30"} 1
39+
rancher_backup_duration_seconds_bucket{name="backup1",le="60"} 1
40+
rancher_backup_duration_seconds_bucket{name="backup1",le="120"} 1
41+
rancher_backup_duration_seconds_bucket{name="backup1",le="+Inf"} 1
42+
rancher_backup_duration_seconds_sum{name="backup1"} 1.5
43+
rancher_backup_duration_seconds_count{name="backup1"} 1
4444
`
4545

4646
err := promtestutil.CollectAndCompare(backupDuration, strings.NewReader(expectedDuration), "rancher_backup_duration_ms")
@@ -49,65 +49,65 @@ rancher_backup_duration_ms_count{name="backup1"} 1
4949
}
5050

5151
const expectedLastTemplate = `
52-
# HELP rancher_backup_last_processed Unix time of when the last Backup was processed (in seconds)
53-
# TYPE rancher_backup_last_processed gauge
54-
rancher_backup_last_processed{name="backup1"} %v
52+
# HELP rancher_backup_last_processed_timestamp_seconds Unix time of when the last Backup was processed (in seconds)
53+
# TYPE rancher_backup_last_processed_timestamp_seconds gauge
54+
rancher_backup_last_processed_timestamp_seconds{name="backup1"} %v
5555
`
5656
expectedLast := fmt.Sprintf(expectedLastTemplate, float64(mockEndTime))
5757

58-
err = promtestutil.CollectAndCompare(backupLastProcessed, strings.NewReader(expectedLast), "rancher_backup_last_processed")
58+
err = promtestutil.CollectAndCompare(backupLastProcessed, strings.NewReader(expectedLast), "rancher_backup_last_processed_timestamp_seconds")
5959
if err != nil {
60-
t.Error("error when comparing resulting rancher_backup_last_processed to expected values:", err)
60+
t.Error("error when comparing resulting rancher_backup_last_processed_timestamp_seconds to expected values:", err)
6161
}
6262
}
6363

6464
func TestUpdateTimeSensitiveBackupMetricsRecurring(t *testing.T) {
6565
t.Cleanup(resetMetrics)
6666

6767
backupName := "backup2"
68-
endTime := time.Now().Unix()
69-
totalTime := int64(1500) // 1.5 seconds
68+
endTime := float64(time.Now().Unix())
69+
totalTime := float64(1.5)
7070

7171
UpdateTimeSensitiveBackupMetrics(backupName, endTime, totalTime)
7272

7373
// Simulate a recurring backup by updating the metrics again
74-
endTime = time.Now().Unix()
75-
totalTime = int64(2700) // 2.7 seconds
74+
endTime = float64(time.Now().Unix())
75+
totalTime = float64(2.7)
7676

7777
UpdateTimeSensitiveBackupMetrics(backupName, endTime, totalTime)
7878

7979
const expectedDuration = `
80-
# HELP rancher_backup_duration_ms Duration of each backup processed by this operator in ms
81-
# TYPE rancher_backup_duration_ms histogram
82-
rancher_backup_duration_ms_bucket{name="backup2",le="500"} 0
83-
rancher_backup_duration_ms_bucket{name="backup2",le="1000"} 0
84-
rancher_backup_duration_ms_bucket{name="backup2",le="2500"} 1
85-
rancher_backup_duration_ms_bucket{name="backup2",le="5000"} 2
86-
rancher_backup_duration_ms_bucket{name="backup2",le="7500"} 2
87-
rancher_backup_duration_ms_bucket{name="backup2",le="10000"} 2
88-
rancher_backup_duration_ms_bucket{name="backup2",le="30000"} 2
89-
rancher_backup_duration_ms_bucket{name="backup2",le="60000"} 2
90-
rancher_backup_duration_ms_bucket{name="backup2",le="120000"} 2
91-
rancher_backup_duration_ms_bucket{name="backup2",le="+Inf"} 2
92-
rancher_backup_duration_ms_sum{name="backup2"} 4200
93-
rancher_backup_duration_ms_count{name="backup2"} 2
80+
# HELP rancher_backup_duration_seconds Duration of each backup processed by this operator in seconds
81+
# TYPE rancher_backup_duration_seconds histogram
82+
rancher_backup_duration_seconds_bucket{name="backup2",le="0.5"} 0
83+
rancher_backup_duration_seconds_bucket{name="backup2",le="1"} 0
84+
rancher_backup_duration_seconds_bucket{name="backup2",le="2.5"} 1
85+
rancher_backup_duration_seconds_bucket{name="backup2",le="5"} 2
86+
rancher_backup_duration_seconds_bucket{name="backup2",le="7.5"} 2
87+
rancher_backup_duration_seconds_bucket{name="backup2",le="10"} 2
88+
rancher_backup_duration_seconds_bucket{name="backup2",le="30"} 2
89+
rancher_backup_duration_seconds_bucket{name="backup2",le="60"} 2
90+
rancher_backup_duration_seconds_bucket{name="backup2",le="120"} 2
91+
rancher_backup_duration_seconds_bucket{name="backup2",le="+Inf"} 2
92+
rancher_backup_duration_seconds_sum{name="backup2"} 4.2
93+
rancher_backup_duration_seconds_count{name="backup2"} 2
9494
`
9595

9696
err := promtestutil.CollectAndCompare(backupDuration, strings.NewReader(expectedDuration))
9797
if err != nil {
98-
t.Error("error when comparing resulting rancher_backup_duration_ms to expected values:", err)
98+
t.Error("error when comparing resulting rancher_backup_duration_seconds to expected values:", err)
9999
}
100100

101101
const expectedLastTemplate = `
102-
# HELP rancher_backup_last_processed Unix time of when the last Backup was processed (in seconds)
103-
# TYPE rancher_backup_last_processed gauge
104-
rancher_backup_last_processed{name="backup2"} %v
102+
# HELP rancher_backup_last_processed_timestamp_seconds Unix time of when the last Backup was processed (in seconds)
103+
# TYPE rancher_backup_last_processed_timestamp_seconds gauge
104+
rancher_backup_last_processed_timestamp_seconds{name="backup2"} %v
105105
`
106106
expectedLast := fmt.Sprintf(expectedLastTemplate, float64(endTime))
107107

108108
err = promtestutil.CollectAndCompare(backupLastProcessed, strings.NewReader(expectedLast))
109109
if err != nil {
110-
t.Error("error when comparing resulting rancher_backup_last_processed to expected values:", err)
110+
t.Error("error when comparing resulting rancher_backup_last_processed_timestamp_seconds to expected values:", err)
111111
}
112112
}
113113

@@ -122,34 +122,34 @@ func TestUpdateProcessedBackupMetrics(t *testing.T) {
122122
UpdateProcessedBackupMetrics(backupName, &err)
123123

124124
const expectedAttempted = `
125-
# HELP rancher_backups_attempted Number of Rancher Backups processed by this operator
126-
# TYPE rancher_backups_attempted counter
127-
rancher_backups_attempted{name="backup1"} 2
125+
# HELP rancher_backups_attempted_total Number of Rancher Backups processed by this operator
126+
# TYPE rancher_backups_attempted_total counter
127+
rancher_backups_attempted_total{name="backup1"} 2
128128
`
129-
if err := promtestutil.CollectAndCompare(backupsAttempted, strings.NewReader(expectedAttempted), "rancher_backups_attempted"); err != nil {
130-
t.Error("error when comparing resulting rancher_backups_attempted to expected values:", err)
129+
if err := promtestutil.CollectAndCompare(backupsAttempted, strings.NewReader(expectedAttempted), "rancher_backups_attempted_total"); err != nil {
130+
t.Error("error when comparing resulting rancher_backups_attempted_total to expected values:", err)
131131
}
132132

133133
const expectedFailed = `
134-
# HELP rancher_backups_failed Number of failed Rancher Backups processed by this operator
135-
# TYPE rancher_backups_failed counter
136-
rancher_backups_failed{name="backup1"} 0
134+
# HELP rancher_backups_failed_total Number of failed Rancher Backups processed by this operator
135+
# TYPE rancher_backups_failed_total counter
136+
rancher_backups_failed_total{name="backup1"} 0
137137
`
138-
if err := promtestutil.CollectAndCompare(backupsFailed, strings.NewReader(expectedFailed), "rancher_backups_failed"); err != nil {
139-
t.Error("error when comparing resulting rancher_backups_failed to expected values:", err)
138+
if err := promtestutil.CollectAndCompare(backupsFailed, strings.NewReader(expectedFailed), "rancher_backups_failed_total"); err != nil {
139+
t.Error("error when comparing resulting rancher_backups_failed_total to expected values:", err)
140140
}
141141

142142
// Test case: Failed backup
143143
err = fmt.Errorf("backup failed2")
144144
UpdateProcessedBackupMetrics(backupName, &err)
145145

146146
const expectedFailedAfterError = `
147-
# HELP rancher_backups_failed Number of failed Rancher Backups processed by this operator
148-
# TYPE rancher_backups_failed counter
149-
rancher_backups_failed{name="backup1"} 1
147+
# HELP rancher_backups_failed_total Number of failed Rancher Backups processed by this operator
148+
# TYPE rancher_backups_failed_total counter
149+
rancher_backups_failed_total{name="backup1"} 1
150150
`
151-
if err := promtestutil.CollectAndCompare(backupsFailed, strings.NewReader(expectedFailedAfterError), "rancher_backups_failed"); err != nil {
152-
t.Error("error when comparing resulting rancher_backups_failed to expected values:", err)
151+
if err := promtestutil.CollectAndCompare(backupsFailed, strings.NewReader(expectedFailedAfterError), "rancher_backups_failed_total"); err != nil {
152+
t.Error("error when comparing resulting rancher_backups_failed_total to expected values:", err)
153153
}
154154
}
155155

@@ -201,13 +201,13 @@ rancher_restore_count 2
201201
}
202202

203203
const expectedRestore = `
204-
# HELP rancher_restore Details on a specific Rancher Restore CR
205-
# TYPE rancher_restore gauge
206-
rancher_restore{fileName="backup1.tar.gz",name="restore1",prune="true",restoreTime="1627849200",status="Restore completed successfully",storageLocation="s3"} 1
207-
rancher_restore{fileName="backup2.tar.gz",name="restore2",prune="false",restoreTime="1627849300",status="Restore failed",storageLocation="s3"} 1
204+
# HELP rancher_restore_info Details on a specific Rancher Restore CR
205+
# TYPE rancher_restore_info gauge
206+
rancher_restore_info{fileName="backup1.tar.gz",name="restore1",prune="true",restoreTime="1627849200",status="Restore completed successfully",storageLocation="s3"} 1
207+
rancher_restore_info{fileName="backup2.tar.gz",name="restore2",prune="false",restoreTime="1627849300",status="Restore failed",storageLocation="s3"} 1
208208
`
209-
if err := promtestutil.CollectAndCompare(restore, strings.NewReader(expectedRestore), "rancher_restore"); err != nil {
210-
t.Error("error when comparing resulting rancher_restore to expected values:", err)
209+
if err := promtestutil.CollectAndCompare(restore, strings.NewReader(expectedRestore), "rancher_restore_info"); err != nil {
210+
t.Error("error when comparing resulting rancher_restore_info to expected values:", err)
211211
}
212212
}
213213

@@ -263,12 +263,12 @@ rancher_backup_count 2
263263
}
264264

265265
const expectedBackup = `
266-
# HELP rancher_backup Details on a specific Rancher Backup CR
267-
# TYPE rancher_backup gauge
268-
rancher_backup{backupType="One-time",filename="backup1.tar.gz",lastSnapshot="1627849200",name="backup1",nextSnapshot="N/A - One-time Backup",resourceSetName="resourceSet1",retentionCount="3",status="Backup completed successfully",storageLocation="s3"} 1
269-
rancher_backup{backupType="Scheduled",filename="backup2.tar.gz",lastSnapshot="1627849300",name="backup2",nextSnapshot="1627849300",resourceSetName="resourceSet2",retentionCount="5",status="Backup failed",storageLocation="s3"} 1
266+
# HELP rancher_backup_info Details on a specific Rancher Backup CR
267+
# TYPE rancher_backup_info gauge
268+
rancher_backup_info{backupType="One-time",filename="backup1.tar.gz",lastSnapshot="1627849200",name="backup1",nextSnapshot="N/A - One-time Backup",resourceSetName="resourceSet1",retentionCount="3",status="Backup completed successfully",storageLocation="s3"} 1
269+
rancher_backup_info{backupType="Scheduled",filename="backup2.tar.gz",lastSnapshot="1627849300",name="backup2",nextSnapshot="1627849300",resourceSetName="resourceSet2",retentionCount="5",status="Backup failed",storageLocation="s3"} 1
270270
`
271-
if err := promtestutil.CollectAndCompare(backup, strings.NewReader(expectedBackup), "rancher_backup"); err != nil {
272-
t.Error("error when comparing resulting rancher_backup to expected values:", err)
271+
if err := promtestutil.CollectAndCompare(backup, strings.NewReader(expectedBackup), "rancher_backup_info"); err != nil {
272+
t.Error("error when comparing resulting rancher_backup_info to expected values:", err)
273273
}
274274
}

0 commit comments

Comments
 (0)