-
Notifications
You must be signed in to change notification settings - Fork 26
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
Refs 4739: metric check for failing snap tasks on RH repos #833
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -142,3 +142,24 @@ func (d metricsDaoImpl) PendingTasksOldestTask(ctx context.Context) float64 { | |||||
} | ||||||
return time.Since(*task.Queued).Seconds() | ||||||
} | ||||||
|
||||||
func (d metricsDaoImpl) RHReposNoSuccessfulSnapshotTaskIn36Hours(ctx context.Context) int64 { | ||||||
var output int64 = -1 | ||||||
date := time.Now().Add(-36 * time.Hour).Format(time.RFC3339) | ||||||
|
||||||
subQuery := d.db.WithContext(ctx). | ||||||
Model(&models.RepositoryConfiguration{}). | ||||||
Select("repository_configurations.uuid, bool_or(tasks.status ILIKE ? AND tasks.finished_at > ?) AS has_successful_tasks", fmt.Sprintf("%%%s%%", config.TaskStatusCompleted), date). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
this can be simplified slightly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This query looks good. I believe it would miss the (very unlikely) case where there's no snapshot tasks for a repository. I don't think this would happen naturally, but maybe could happen if there's a bug with task cleanup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about handling that case? I could see just adding a second query and adding the two counts together as a simple solution. |
||||||
Joins("LEFT OUTER JOIN tasks ON repository_configurations.repository_uuid = tasks.object_uuid"). | ||||||
Where("repository_configurations.org_id = ?", config.RedHatOrg). | ||||||
Where("repository_configurations.snapshot IS TRUE"). | ||||||
Where("tasks.type = ?", config.RepositorySnapshotTask). | ||||||
Group("repository_configurations.uuid") | ||||||
|
||||||
d.db.WithContext(ctx). | ||||||
Table("(?) AS sq", subQuery). | ||||||
Where("sq.has_successful_tasks IS FALSE"). | ||||||
Count(&output) | ||||||
|
||||||
return output | ||||||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nitpick, but what do you think about renaming this metric?
"No" can also be an abbreviation for "number", so "RHReposNoSuccessfulSnapshotTaskIn36Hours" could be interpreted as "Number of sucessful snapshot tasks"