Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maintenance history for backupRepository CRs #8532

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Lyndon-Li
Copy link
Contributor

Fix issue #7810, add maintenance history for backupRepository CRs

@Lyndon-Li Lyndon-Li force-pushed the isolate-message-in-backup-repo branch from 8fa1215 to 3b2c50b Compare December 19, 2024 08:20
@@ -88,8 +88,8 @@ spec:
description: BackupRepositoryStatus is the current status of a BackupRepository.
properties:
lastMaintenanceTime:
description: LastMaintenanceTime is the last time maintenance was
run.
description: LastMaintenanceTime is the last time repo maintenance
Copy link
Contributor Author

@Lyndon-Li Lyndon-Li Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LastMaintenanceTime should be used to record the completion time of a successful maintenance.
Previously, it is used to record the start time of a successful maintenance, which is not reasonable. E.g., I run a maintenance which takes more than 1 hour; since the default frequency for quick maintenance is 1 hour, the next maintenance will be launched immediately after the first one completes, but actually it is a wasting one as data has just been maintained.
Previously, the description in the CRD is ambiguous, it could mean the completion time or start time.

So in this PR, both the description and the value set to LastMaintenanceTime as changed.

@Lyndon-Li Lyndon-Li marked this pull request as ready for review December 19, 2024 08:35
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.

Project coverage is 59.17%. Comparing base (010fd1c) to head (3b2c50b).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
pkg/controller/backup_repository_controller.go 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8532      +/-   ##
==========================================
- Coverage   59.18%   59.17%   -0.01%     
==========================================
  Files         369      369              
  Lines       39329    39355      +26     
==========================================
+ Hits        23276    23289      +13     
- Misses      14585    14597      +12     
- Partials     1468     1469       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +330 to +352
func updateRepoMaintenanceHistory(repo *velerov1api.BackupRepository, result velerov1api.BackupRepositoryMaintenanceResult, startTime time.Time, completionTime time.Time, message string) {
length := defaultMaintenanceStatusQueueLength
if len(repo.Status.RecentMaintenanceStatus) < defaultMaintenanceStatusQueueLength {
length = len(repo.Status.RecentMaintenanceStatus) + 1
}

lru := make([]velerov1api.BackupRepositoryMaintenanceStatus, length)

if len(repo.Status.RecentMaintenanceStatus) >= defaultMaintenanceStatusQueueLength {
copy(lru[:length-1], repo.Status.RecentMaintenanceStatus[len(repo.Status.RecentMaintenanceStatus)-defaultMaintenanceStatusQueueLength+1:])
} else {
copy(lru[:length-1], repo.Status.RecentMaintenanceStatus[:])
}

lru[length-1] = velerov1api.BackupRepositoryMaintenanceStatus{
Result: result,
StartTimestamp: &metav1.Time{Time: startTime},
CompleteTimestamp: &metav1.Time{Time: completionTime},
Message: message,
}

repo.Status.RecentMaintenanceStatus = lru
}
Copy link
Member

@kaovilai kaovilai Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func updateRepoMaintenanceHistory(repo *velerov1api.BackupRepository, result velerov1api.BackupRepositoryMaintenanceResult, startTime time.Time, completionTime time.Time, message string) {
length := defaultMaintenanceStatusQueueLength
if len(repo.Status.RecentMaintenanceStatus) < defaultMaintenanceStatusQueueLength {
length = len(repo.Status.RecentMaintenanceStatus) + 1
}
lru := make([]velerov1api.BackupRepositoryMaintenanceStatus, length)
if len(repo.Status.RecentMaintenanceStatus) >= defaultMaintenanceStatusQueueLength {
copy(lru[:length-1], repo.Status.RecentMaintenanceStatus[len(repo.Status.RecentMaintenanceStatus)-defaultMaintenanceStatusQueueLength+1:])
} else {
copy(lru[:length-1], repo.Status.RecentMaintenanceStatus[:])
}
lru[length-1] = velerov1api.BackupRepositoryMaintenanceStatus{
Result: result,
StartTimestamp: &metav1.Time{Time: startTime},
CompleteTimestamp: &metav1.Time{Time: completionTime},
Message: message,
}
repo.Status.RecentMaintenanceStatus = lru
}
func addRepoMaintenanceHistory(repo *velerov1api.BackupRepository, result velerov1api.BackupRepositoryMaintenanceResult, startTime time.Time, completionTime time.Time, message string) {
length := defaultMaintenanceStatusQueueLength
resultStatus := velerov1api.BackupRepositoryMaintenanceStatus{
Result: result,
StartTimestamp: &metav1.Time{Time: startTime},
CompleteTimestamp: &metav1.Time{Time: completionTime},
Message: message,
}
startingPos := 0
if len(repo.Status.RecentMaintenanceStatus) >= length {
// discard old element(s)
startingPos = len(repo.Status.RecentMaintenanceStatus) - length + 1
}
repo.Status.RecentMaintenanceStatus = append(repo.Status.RecentMaintenanceStatus[startingPos:], resultStatus)
}

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants