Skip to content

Commit

Permalink
TtlStrategy -> TTLStrategy
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Qian <kevin.qian@databricks.com>
  • Loading branch information
kevinqian-db committed Jan 29, 2024
1 parent 5a20756 commit c20482c
Show file tree
Hide file tree
Showing 9 changed files with 921 additions and 921 deletions.
14 changes: 7 additions & 7 deletions analysis/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ func (c *Controller) maybeGarbageCollectAnalysisRun(run *v1alpha1.AnalysisRun, l

func isAnalysisRunTtlExceeded(run *v1alpha1.AnalysisRun) bool {
// TTL only counted for completed runs with TTL strategy.
if !run.Status.Phase.Completed() || run.Spec.TtlStrategy == nil {
if !run.Status.Phase.Completed() || run.Spec.TTLStrategy == nil {
return false
}
// Cannot determine TTL if run has no completion time.
Expand All @@ -787,12 +787,12 @@ func isAnalysisRunTtlExceeded(run *v1alpha1.AnalysisRun) bool {
}
secondsCompleted := timeutil.MetaNow().Sub(run.Status.CompletedAt.Time).Seconds()
var ttlSeconds *int32
if run.Status.Phase == v1alpha1.AnalysisPhaseSuccessful && run.Spec.TtlStrategy.SecondsAfterSuccess != nil {
ttlSeconds = run.Spec.TtlStrategy.SecondsAfterSuccess
} else if run.Status.Phase == v1alpha1.AnalysisPhaseFailed && run.Spec.TtlStrategy.SecondsAfterFailure != nil {
ttlSeconds = run.Spec.TtlStrategy.SecondsAfterFailure
} else if run.Spec.TtlStrategy.SecondsAfterCompletion != nil {
ttlSeconds = run.Spec.TtlStrategy.SecondsAfterCompletion
if run.Status.Phase == v1alpha1.AnalysisPhaseSuccessful && run.Spec.TTLStrategy.SecondsAfterSuccess != nil {
ttlSeconds = run.Spec.TTLStrategy.SecondsAfterSuccess
} else if run.Status.Phase == v1alpha1.AnalysisPhaseFailed && run.Spec.TTLStrategy.SecondsAfterFailure != nil {
ttlSeconds = run.Spec.TTLStrategy.SecondsAfterFailure
} else if run.Spec.TTLStrategy.SecondsAfterCompletion != nil {
ttlSeconds = run.Spec.TTLStrategy.SecondsAfterCompletion
}
if ttlSeconds == nil {
return false
Expand Down
38 changes: 19 additions & 19 deletions analysis/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1998,9 +1998,9 @@ func TestExceededTtlChecked(t *testing.T) {
defer f.Close()
c, _, _ := f.newController(noResyncPeriodFunc)

testTtlStrategy := func(
testTTLStrategy := func(
t *testing.T,
ttlStrategy *v1alpha1.TtlStrategy,
ttlStrategy *v1alpha1.TTLStrategy,
expiredStatus *v1alpha1.AnalysisRunStatus,
notExpiredStatus *v1alpha1.AnalysisRunStatus) {
testId := string(uuid.NewUUID())
Expand All @@ -2010,7 +2010,7 @@ func TestExceededTtlChecked(t *testing.T) {
Namespace: metav1.NamespaceDefault,
},
Spec: v1alpha1.AnalysisRunSpec{
TtlStrategy: ttlStrategy,
TTLStrategy: ttlStrategy,
},
Status: *expiredStatus,
}
Expand All @@ -2022,7 +2022,7 @@ func TestExceededTtlChecked(t *testing.T) {
Namespace: metav1.NamespaceDefault,
},
Spec: v1alpha1.AnalysisRunSpec{
TtlStrategy: ttlStrategy,
TTLStrategy: ttlStrategy,
},
Status: *notExpiredStatus,
}
Expand All @@ -2043,7 +2043,7 @@ func TestExceededTtlChecked(t *testing.T) {
secondsOfOneDay := int32(86400)

// Test completed TTL.
testTtlStrategy(t, &v1alpha1.TtlStrategy{
testTTLStrategy(t, &v1alpha1.TTLStrategy{
SecondsAfterCompletion: &secondsOfOneDay,
}, &v1alpha1.AnalysisRunStatus{
CompletedAt: timePtr(metav1.NewTime(ttlExpiredCompletedTime)),
Expand All @@ -2052,7 +2052,7 @@ func TestExceededTtlChecked(t *testing.T) {
CompletedAt: timePtr(metav1.NewTime(ttlNotExpiredCompletedTime)),
Phase: v1alpha1.AnalysisPhaseSuccessful,
})
testTtlStrategy(t, &v1alpha1.TtlStrategy{
testTTLStrategy(t, &v1alpha1.TTLStrategy{
SecondsAfterCompletion: &secondsOfOneDay,
}, &v1alpha1.AnalysisRunStatus{
CompletedAt: timePtr(metav1.NewTime(ttlExpiredCompletedTime)),
Expand All @@ -2061,7 +2061,7 @@ func TestExceededTtlChecked(t *testing.T) {
CompletedAt: timePtr(metav1.NewTime(ttlNotExpiredCompletedTime)),
Phase: v1alpha1.AnalysisPhaseFailed,
})
testTtlStrategy(t, &v1alpha1.TtlStrategy{
testTTLStrategy(t, &v1alpha1.TTLStrategy{
SecondsAfterCompletion: &secondsOfOneDay,
}, &v1alpha1.AnalysisRunStatus{
CompletedAt: timePtr(metav1.NewTime(ttlExpiredCompletedTime)),
Expand All @@ -2071,7 +2071,7 @@ func TestExceededTtlChecked(t *testing.T) {
Phase: v1alpha1.AnalysisPhaseError,
})
// Test successful TTL.
testTtlStrategy(t, &v1alpha1.TtlStrategy{
testTTLStrategy(t, &v1alpha1.TTLStrategy{
SecondsAfterSuccess: &secondsOfOneDay,
}, &v1alpha1.AnalysisRunStatus{
CompletedAt: timePtr(metav1.NewTime(ttlExpiredCompletedTime)),
Expand All @@ -2081,7 +2081,7 @@ func TestExceededTtlChecked(t *testing.T) {
Phase: v1alpha1.AnalysisPhaseSuccessful,
})
// Test failed TTL.
testTtlStrategy(t, &v1alpha1.TtlStrategy{
testTTLStrategy(t, &v1alpha1.TTLStrategy{
SecondsAfterFailure: &secondsOfOneDay,
}, &v1alpha1.AnalysisRunStatus{
CompletedAt: timePtr(metav1.NewTime(ttlExpiredCompletedTime)),
Expand All @@ -2092,7 +2092,7 @@ func TestExceededTtlChecked(t *testing.T) {
})

// Test success TTL does not affect failed run.
testTtlStrategy(t, &v1alpha1.TtlStrategy{
testTTLStrategy(t, &v1alpha1.TTLStrategy{
SecondsAfterSuccess: &secondsOfOneDay,
}, &v1alpha1.AnalysisRunStatus{
CompletedAt: timePtr(metav1.NewTime(ttlExpiredCompletedTime)),
Expand All @@ -2102,7 +2102,7 @@ func TestExceededTtlChecked(t *testing.T) {
Phase: v1alpha1.AnalysisPhaseFailed,
})
// Test failed TTL does not affect successful run.
testTtlStrategy(t, &v1alpha1.TtlStrategy{
testTTLStrategy(t, &v1alpha1.TTLStrategy{
SecondsAfterFailure: &secondsOfOneDay,
}, &v1alpha1.AnalysisRunStatus{
CompletedAt: timePtr(metav1.NewTime(ttlExpiredCompletedTime)),
Expand All @@ -2112,7 +2112,7 @@ func TestExceededTtlChecked(t *testing.T) {
Phase: v1alpha1.AnalysisPhaseSuccessful,
})
// Test success TTL overrides completed TTL.
testTtlStrategy(t, &v1alpha1.TtlStrategy{
testTTLStrategy(t, &v1alpha1.TTLStrategy{
SecondsAfterCompletion: pointer.Int32Ptr(100000),
SecondsAfterSuccess: &secondsOfOneDay,
}, &v1alpha1.AnalysisRunStatus{
Expand All @@ -2123,7 +2123,7 @@ func TestExceededTtlChecked(t *testing.T) {
Phase: v1alpha1.AnalysisPhaseSuccessful,
})
// Test failed TTL overrides completed TTL.
testTtlStrategy(t, &v1alpha1.TtlStrategy{
testTTLStrategy(t, &v1alpha1.TTLStrategy{
SecondsAfterCompletion: pointer.Int32Ptr(100000),
SecondsAfterFailure: &secondsOfOneDay,
}, &v1alpha1.AnalysisRunStatus{
Expand All @@ -2134,7 +2134,7 @@ func TestExceededTtlChecked(t *testing.T) {
Phase: v1alpha1.AnalysisPhaseFailed,
})
// Test completed TTL still evaluated when non-matching overrides exist.
testTtlStrategy(t, &v1alpha1.TtlStrategy{
testTTLStrategy(t, &v1alpha1.TTLStrategy{
SecondsAfterCompletion: &secondsOfOneDay,
SecondsAfterFailure: pointer.Int32Ptr(86401),
}, &v1alpha1.AnalysisRunStatus{
Expand Down Expand Up @@ -2251,7 +2251,7 @@ func TestReconcileAnalysisRunOnRunNotFound(t *testing.T) {
Namespace: metav1.NamespaceDefault,
},
Spec: v1alpha1.AnalysisRunSpec{
TtlStrategy: &v1alpha1.TtlStrategy{
TTLStrategy: &v1alpha1.TTLStrategy{
SecondsAfterCompletion: pointer.Int32Ptr(1),
},
},
Expand Down Expand Up @@ -2288,7 +2288,7 @@ func TestReconcileAnalysisRunOnOtherRunErrors(t *testing.T) {
Namespace: metav1.NamespaceDefault,
},
Spec: v1alpha1.AnalysisRunSpec{
TtlStrategy: &v1alpha1.TtlStrategy{
TTLStrategy: &v1alpha1.TTLStrategy{
SecondsAfterCompletion: pointer.Int32Ptr(1),
},
},
Expand Down Expand Up @@ -2327,7 +2327,7 @@ func TestMaybeGarbageCollectAnalysisRunNoGCIfNotCompleted(t *testing.T) {
assert.Empty(t, f.client.Fake.Actions())
}

func TestMaybeGarbageCollectAnalysisRunNoGCIfNoTtlStrategy(t *testing.T) {
func TestMaybeGarbageCollectAnalysisRunNoGCIfNoTTLStrategy(t *testing.T) {
f := newFixture(t)
defer f.Close()
c, _, _ := f.newController(noResyncPeriodFunc)
Expand Down Expand Up @@ -2360,7 +2360,7 @@ func TestMaybeGarbageCollectAnalysisRunNoGCIfWithDeletionTimestamp(t *testing.T)
DeletionTimestamp: timePtr(metav1.NewTime(f.now)),
},
Spec: v1alpha1.AnalysisRunSpec{
TtlStrategy: &v1alpha1.TtlStrategy{
TTLStrategy: &v1alpha1.TTLStrategy{
SecondsAfterCompletion: pointer.Int32Ptr(1),
},
},
Expand All @@ -2387,7 +2387,7 @@ func TestMaybeGarbageCollectAnalysisRunNoGCIfNoCompletedAt(t *testing.T) {
Namespace: metav1.NamespaceDefault,
},
Spec: v1alpha1.AnalysisRunSpec{
TtlStrategy: &v1alpha1.TtlStrategy{
TTLStrategy: &v1alpha1.TTLStrategy{
SecondsAfterCompletion: pointer.Int32Ptr(1),
},
},
Expand Down
46 changes: 23 additions & 23 deletions pkg/apiclient/rollout/rollout.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@
"title": "MeasurementRetention object contains the settings for retaining the number of measurements during the analysis\n+patchMergeKey=metricName\n+patchStrategy=merge\n+optional"
},
"ttlStrategy": {
"$ref": "#/definitions/github.com.argoproj.argo_rollouts.pkg.apis.rollouts.v1alpha1.TtlStrategy",
"title": "TtlStrategy object contains the strategy for the time to live depending on if the analysis succeeded or failed\n+optional"
"$ref": "#/definitions/github.com.argoproj.argo_rollouts.pkg.apis.rollouts.v1alpha1.TTLStrategy",
"title": "TTLStrategy object contains the strategy for the time to live depending on if the analysis succeeded or failed\n+optional"
}
},
"title": "AnalysisRunSpec is the spec for a AnalysisRun resource"
Expand Down Expand Up @@ -2542,6 +2542,27 @@
},
"description": "TLSRoute holds the information on the virtual service's TLS/HTTPS routes that are desired to be matched for changing weights."
},
"github.com.argoproj.argo_rollouts.pkg.apis.rollouts.v1alpha1.TTLStrategy": {
"type": "object",
"properties": {
"secondsAfterCompletion": {
"type": "integer",
"format": "int32",
"description": "SecondsAfterCompletion is the number of seconds to live after completion."
},
"secondsAfterFailure": {
"type": "integer",
"format": "int32",
"description": "SecondsAfterFailure is the number of seconds to live after failure."
},
"secondsAfterSuccess": {
"type": "integer",
"format": "int32",
"description": "SecondsAfterSuccess is the number of seconds to live after success."
}
},
"title": "TTLStrategy defines the strategy for the time to live depending on if the analysis succeeded or failed"
},
"github.com.argoproj.argo_rollouts.pkg.apis.rollouts.v1alpha1.TemplateService": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -2586,27 +2607,6 @@
},
"title": "TrafficWeights describes the current status of how traffic has been split"
},
"github.com.argoproj.argo_rollouts.pkg.apis.rollouts.v1alpha1.TtlStrategy": {
"type": "object",
"properties": {
"secondsAfterCompletion": {
"type": "integer",
"format": "int32",
"description": "SecondsAfterCompletion is the number of seconds to live after completion."
},
"secondsAfterFailure": {
"type": "integer",
"format": "int32",
"description": "SecondsAfterFailure is the number of seconds to live after failure."
},
"secondsAfterSuccess": {
"type": "integer",
"format": "int32",
"description": "SecondsAfterSuccess is the number of seconds to live after success."
}
},
"title": "TtlStrategy defines the strategy for the time to live depending on if the analysis succeeded or failed"
},
"github.com.argoproj.argo_rollouts.pkg.apis.rollouts.v1alpha1.ValueFrom": {
"type": "object",
"properties": {
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/rollouts/v1alpha1/analysis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ type MeasurementRetention struct {
Limit int32 `json:"limit" protobuf:"varint,2,opt,name=limit"`
}

// TtlStrategy defines the strategy for the time to live depending on if the analysis succeeded or failed
type TtlStrategy struct {
// TTLStrategy defines the strategy for the time to live depending on if the analysis succeeded or failed
type TTLStrategy struct {
// SecondsAfterCompletion is the number of seconds to live after completion.
SecondsAfterCompletion *int32 `json:"secondsAfterCompletion,omitempty" protobuf:"varint,1,opt,name=secondsAfterCompletion"`
// SecondsAfterFailure is the number of seconds to live after failure.
Expand Down Expand Up @@ -388,9 +388,9 @@ type AnalysisRunSpec struct {
// +patchStrategy=merge
// +optional
MeasurementRetention []MeasurementRetention `json:"measurementRetention,omitempty" patchStrategy:"merge" patchMergeKey:"metricName" protobuf:"bytes,5,rep,name=measurementRetention"`
// TtlStrategy object contains the strategy for the time to live depending on if the analysis succeeded or failed
// TTLStrategy object contains the strategy for the time to live depending on if the analysis succeeded or failed
// +optional
TtlStrategy *TtlStrategy `json:"ttlStrategy,omitempty" protobuf:"bytes,6,opt,name=ttlStrategy"`
TTLStrategy *TTLStrategy `json:"ttlStrategy,omitempty" protobuf:"bytes,6,opt,name=ttlStrategy"`
}

// Argument is an argument to an AnalysisRun
Expand Down

0 comments on commit c20482c

Please sign in to comment.