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

golines #1279

Merged
merged 1 commit into from
Jan 20, 2025
Merged

golines #1279

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion job/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import (
"github.com/google/uuid"
)

func CleanupStaleHistory(ctx context.Context, age time.Duration, name, resourceID string, statuses ...string) (int, error) {
func CleanupStaleHistory(
ctx context.Context,
age time.Duration,
name, resourceID string,
statuses ...string,
) (int, error) {
ctx = ctx.WithName(fmt.Sprintf("job=%s", name)).WithName(fmt.Sprintf("resourceID=%s", resourceID))

query := ctx.FastDB("jobs").Where("NOW() - time_start >= ?", age)
Expand Down
3 changes: 2 additions & 1 deletion job/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

func CleanupSoftDeletedComponents(ctx context.Context, olderThan time.Duration) (int, error) {
tx := ctx.DB().Exec("DELETE FROM components WHERE deleted_at < NOW() - interval '1 SECONDS' * ?", int64(olderThan.Seconds()))
tx := ctx.DB().
Exec("DELETE FROM components WHERE deleted_at < NOW() - interval '1 SECONDS' * ?", int64(olderThan.Seconds()))
if tx.Error != nil {
return 0, tx.Error
}
Expand Down
16 changes: 13 additions & 3 deletions job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ func (j *Job) GetContext() map[string]any {
}

func (j *Job) PK() string {
return strings.TrimSuffix(strings.TrimSpace(fmt.Sprintf("%s/%s", j.Name, lo.CoalesceOrEmpty(j.ID, j.ResourceID))), "/")
return strings.TrimSuffix(
strings.TrimSpace(fmt.Sprintf("%s/%s", j.Name, lo.CoalesceOrEmpty(j.ID, j.ResourceID))),
"/",
)
}

type StatusRing struct {
Expand Down Expand Up @@ -282,7 +285,8 @@ func (j *JobRuntime) end() {
}
j.Job.statusRing.Add(j.History)

j.Context.Counter("job", "name", j.Job.Name, "id", j.Job.ResourceID, "resource", j.Job.ResourceType, "status", j.History.Status).Add(1)
j.Context.Counter("job", "name", j.Job.Name, "id", j.Job.ResourceID, "resource", j.Job.ResourceType, "status", j.History.Status).
Add(1)
j.Context.Histogram("job_duration", context.LongLatencyBuckets, "name", j.Job.Name, "id", j.Job.ResourceID, "resource", j.Job.ResourceType, "status", j.History.Status).
Since(j.History.TimeStart)
}
Expand Down Expand Up @@ -323,7 +327,13 @@ func (j *Job) FindHistory(statuses ...string) ([]models.JobHistory, error) {
var items []models.JobHistory
var err error
if len(statuses) == 0 {
err = j.WithoutTracing().WithDBLogger("jobs", logger.Trace1).DB().Where("name = ?", j.Name).Order("time_start DESC").Find(&items).Error
err = j.WithoutTracing().
WithDBLogger("jobs", logger.Trace1).
DB().
Where("name = ?", j.Name).
Order("time_start DESC").
Find(&items).
Error
} else {
err = j.WithoutTracing().WithDBLogger("jobs", logger.Trace1).DB().Where("name = ? and status in ?", j.Name, statuses).Order("time_start DESC").Find(&items).Error
}
Expand Down
16 changes: 13 additions & 3 deletions kubernetes/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ type kubeCacheData struct {
Config *rest.Config
}

func cacheResult(key string, k kubernetes.Interface, c *rest.Config, e error) (kubernetes.Interface, *rest.Config, error) {
func cacheResult(
key string,
k kubernetes.Interface,
c *rest.Config,
e error,
) (kubernetes.Interface, *rest.Config, error) {
if e != nil {
return nil, nil, e
}
Expand Down Expand Up @@ -101,7 +106,10 @@ func NewClientWithConfig(logger logger.Logger, kubeConfig []byte) (kubernetes.In
}
}

func NewClientFromPathOrConfig(logger logger.Logger, kubeconfigOrPath string) (kubernetes.Interface, *rest.Config, error) {
func NewClientFromPathOrConfig(
logger logger.Logger,
kubeconfigOrPath string,
) (kubernetes.Interface, *rest.Config, error) {
var client kubernetes.Interface
var rest *rest.Config
var err error
Expand Down Expand Up @@ -156,7 +164,9 @@ func GetClusterName(config *rest.Config) string {
if err != nil {
return ""
}
kubeadmConfig, err := clientset.CoreV1().ConfigMaps("kube-system").Get(context.TODO(), "kubeadm-config", metav1.GetOptions{})
kubeadmConfig, err := clientset.CoreV1().
ConfigMaps("kube-system").
Get(context.TODO(), "kubeadm-config", metav1.GetOptions{})
if err != nil {
return ""
}
Expand Down
Loading