Skip to content

Commit 0c0d1b5

Browse files
committed
fix clickhouse_backup_number_backups_remote and last_backup_size_remote metrics behavior in watch command, fix #1152
Signed-off-by: Slach <[email protected]>
1 parent 2464b73 commit 0c0d1b5

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v2.6.19
2+
BUG FIXES
3+
- fix `clickhouse_backup_number_backups_remote` and `last_backup_size_remote` metrics behavior in `watch` command, fix [1152](https://github.com/Altinity/clickhouse-backup/issues/1152)
4+
15
# v2.6.18
26
IMPROVEMENTS
37
- add support multipart upload and multipart download for COS storage, add COS_ALLOW_MULTIPART_DOWNLOAD and COS_CONCURRENCY to config, fix [1074](https://github.com/Altinity/clickhouse-backup/issues/1074)

pkg/backup/watch.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (b *Backuper) ValidateWatchParams(watchInterval, fullInterval, watchBackupN
6666
//
6767
// - each watch-interval, run create_remote increment --diff-from=prev-name + delete local increment, even when upload failed
6868
// - save previous backup type incremental, next try will also incremental, until reach full interval
69-
func (b *Backuper) Watch(watchInterval, fullInterval, watchBackupNameTemplate, tablePattern string, partitions, skipProjections []string, schemaOnly, backupRBAC, backupConfigs, skipCheckPartsColumns, deleteSource bool, version string, commandId int, metrics metrics.APIMetricsInterface, cliCtx *cli.Context) error {
69+
func (b *Backuper) Watch(watchInterval, fullInterval, watchBackupNameTemplate, tablePattern string, partitions, skipProjections []string, schemaOnly, backupRBAC, backupConfigs, skipCheckPartsColumns, deleteSource bool, version string, commandId int, metrics *metrics.APIMetrics, cliCtx *cli.Context) error {
7070
ctx, cancel, err := status.Current.GetContextWithCancel(commandId)
7171
if err != nil {
7272
return err
@@ -205,6 +205,20 @@ func (b *Backuper) Watch(watchInterval, fullInterval, watchBackupNameTemplate, t
205205
lastFullBackup = now
206206
}
207207
}
208+
// https://github.com/Altinity/clickhouse-backup/issues/1152
209+
go func() {
210+
remoteBackups, listRemoteErr := b.GetRemoteBackups(ctx, false)
211+
if listRemoteErr == nil && len(remoteBackups) > 0 {
212+
numberBackupsRemote := len(remoteBackups)
213+
lastBackupInstance := remoteBackups[numberBackupsRemote-1]
214+
lastSizeRemote := lastBackupInstance.GetFullSize()
215+
metrics.LastBackupSizeRemote.Set(float64(lastSizeRemote))
216+
metrics.NumberBackupsRemote.Set(float64(numberBackupsRemote))
217+
} else {
218+
metrics.LastBackupSizeRemote.Set(0)
219+
metrics.NumberBackupsRemote.Set(0)
220+
}
221+
}()
208222
}
209223
if b.ch.IsOpen {
210224
b.ch.Close()

pkg/server/metrics/metrics.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ import (
88
"github.com/rs/zerolog/log"
99
)
1010

11-
type APIMetricsInterface interface {
12-
Start(command string, startTime time.Time)
13-
Finish(command string, startTime time.Time)
14-
Success(command string)
15-
Failure(command string)
16-
ExecuteWithMetrics(command string, errCounter int, f func() error) (error, int)
17-
}
18-
1911
type APIMetrics struct {
2012
SuccessfulCounter map[string]prometheus.Counter
2113
FailedCounter map[string]prometheus.Counter

0 commit comments

Comments
 (0)