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

Integrate Experiments with Analysis #210

Merged
merged 14 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove ExperimentCompleted helper
  • Loading branch information
jessesuen committed Oct 27, 2019
commit 3cc3be0007fd8e9b2add4a7b63746873ba37df91
2 changes: 1 addition & 1 deletion experiments/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func calculateExperimentConditions(experiment *v1alpha1.Experiment, newStatus v1
}

switch {
case conditions.ExperimentCompleted(newStatus):
case newStatus.Status.Completed() && newStatus.Status == v1alpha1.AnalysisStatusSuccessful:
msg := fmt.Sprintf(conditions.ExperimentCompletedMessage, experiment.Name)
condition := conditions.NewExperimentConditions(v1alpha1.ExperimentProgressing, corev1.ConditionFalse, conditions.ExperimentCompleteReason, msg)
conditions.SetExperimentCondition(&newStatus, *condition)
Expand Down
8 changes: 4 additions & 4 deletions experiments/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func TestScaleDownRSAfterFinish(t *testing.T) {
assert.NotNil(t, updatedRs2)
assert.Equal(t, int32(0), *updatedRs2.Spec.Replicas)

expPatch := f.getPatchedExperiment(expPatchIndex)
assert.Equal(t, `{"status":{"status":"Successful"}}`, expPatch)
expPatchObj := f.getPatchedExperimentAsObj(expPatchIndex)
assert.Equal(t, v1alpha1.AnalysisStatusSuccessful, expPatchObj.Status.Status)
}

func TestSetAvailableAt(t *testing.T) {
Expand Down Expand Up @@ -194,12 +194,12 @@ func TestSuccessAfterDurationPasses(t *testing.T) {
generateTemplatesStatus("bar", 1, 1, v1alpha1.TemplateStatusSuccessful, now()),
generateTemplatesStatus("baz", 1, 1, v1alpha1.TemplateStatusSuccessful, now()),
}

cond := newCondition(conditions.ExperimentCompleteReason, e)
expectedPatch := calculatePatch(e, `{
"status":{
"status": "Successful"
}
}`, templateStatuses, nil)
}`, templateStatuses, cond)
assert.Equal(t, expectedPatch, patch)
}

Expand Down
2 changes: 1 addition & 1 deletion rollout/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func completedCurrentCanaryStep(roCtx *canaryContext) bool {
return true
}
experiment := roCtx.CurrentExperiment()
if currentStep.Experiment != nil && experiment != nil && conditions.ExperimentCompleted(experiment.Status) && experiment.Status.Status == v1alpha1.AnalysisStatusSuccessful {
if currentStep.Experiment != nil && experiment != nil && experiment.Status.Status.Completed() && experiment.Status.Status == v1alpha1.AnalysisStatusSuccessful {
return true
}
currentArs := roCtx.CurrentAnalysisRuns()
Expand Down
27 changes: 0 additions & 27 deletions utils/conditions/experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,33 +119,6 @@ func ExperimentProgressing(experiment *v1alpha1.Experiment, newStatus v1alpha1.E
return false
}

// ExperimentCompleted Indicates when the experiment has finished and completely scaled down
func ExperimentCompleted(newStatus v1alpha1.ExperimentStatus) bool {
if !newStatus.Status.Completed() {
return false
}
if newStatus.AvailableAt == nil {
return false
}
new := experimentutil.GetTemplateStatusMapping(newStatus)
for i := range new {
status := new[i]
if status.Replicas != int32(0) {
return false
}
if status.UpdatedReplicas != int32(0) {
return false
}
if status.AvailableReplicas != int32(0) {
return false
}
if status.ReadyReplicas != int32(0) {
return false
}
}
return true
}

// ExperimentRunning indicates when a experiment has become healthy and started to run for the `spec.duration` time
func ExperimentRunning(experiment *v1alpha1.Experiment) bool {
passedDuration, _ := experimentutil.PassedDurations(experiment)
Expand Down
75 changes: 0 additions & 75 deletions utils/conditions/experiments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,81 +302,6 @@ func TestExperimentProgressing(t *testing.T) {

}

func TestExperimentComplete(t *testing.T) {
now := metav1.Now()
experiment := func(current, updated, available, ready int32, status v1alpha1.AnalysisStatus, availableAt *metav1.Time) *v1alpha1.Experiment {
e := &v1alpha1.Experiment{
Spec: v1alpha1.ExperimentSpec{},
Status: v1alpha1.ExperimentStatus{
TemplateStatuses: []v1alpha1.TemplateStatus{{
Name: "test",
Replicas: current,
UpdatedReplicas: updated,
AvailableReplicas: available,
ReadyReplicas: ready,
}},
Status: status,
AvailableAt: availableAt,
},
}
return e
}

tests := []struct {
name string
e *v1alpha1.Experiment
expected bool
}{

{
name: "Experiment not running",
e: experiment(0, 0, 0, 0, "", &now),
expected: false,
},
{
name: "Experiment not finished: running set to true",
e: experiment(0, 0, 0, 0, v1alpha1.AnalysisStatusRunning, &now),
expected: false,
},
{
name: "Experiment not finished: not available yet",
e: experiment(0, 0, 0, 0, v1alpha1.AnalysisStatusPending, nil),
expected: false,
},
{
name: "Experiment not finished: waiting for no ready replicas",
e: experiment(0, 0, 0, 5, v1alpha1.AnalysisStatusRunning, &now),
expected: false,
},
{
name: "Experiment not finished: waiting for no available replicas",
e: experiment(0, 0, 5, 0, v1alpha1.AnalysisStatusRunning, &now),
expected: false,
},
{
name: "Experiment not finished: waiting for no updated replicas",
e: experiment(0, 5, 0, 0, v1alpha1.AnalysisStatusRunning, &now),
expected: false,
},
{
name: "Experiment not finished: waiting for no replicas",
e: experiment(5, 0, 0, 0, v1alpha1.AnalysisStatusSuccessful, &now),
expected: false,
},
{
name: "Experiment Completed",
e: experiment(0, 0, 0, 0, v1alpha1.AnalysisStatusSuccessful, &now),
expected: true,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
assert.Equal(t, test.expected, ExperimentCompleted(test.e.Status))
})
}
}

func TestExperimentRunning(t *testing.T) {
e := &v1alpha1.Experiment{}
assert.False(t, ExperimentRunning(e))
Expand Down