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

fix(experiments): move recorder event to after experiment reconciliation, fixes #4021 #4022

Merged
merged 3 commits into from
Jan 8, 2025
Merged
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
1 change: 1 addition & 0 deletions USERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Organizations below are **officially** using Argo Rollouts. Please send a PR wit
1. [Skillz](https://www.skillz.com)
1. [Spotify](https://www.spotify.com/)
1. [Synamedia](https://www.synamedia.com)
1. [Taboola](https://www.taboola.com)
1. [TBC Bank](https://tbcbank.ge/)
1. [Trustly](https://www.trustly.com/)
1. [Tuhu](https://www.tuhu.cn/)
Expand Down
17 changes: 16 additions & 1 deletion experiments/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"sync"
"time"

corev1 "k8s.io/api/core/v1"

log "github.com/sirupsen/logrus"
appsv1 "k8s.io/api/apps/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -318,6 +320,7 @@ func (ec *Controller) syncHandler(ctx context.Context, key string) error {
}

func (ec *Controller) persistExperimentStatus(orig *v1alpha1.Experiment, newStatus *v1alpha1.ExperimentStatus) error {
prevStatus := orig.Status
ctx := context.TODO()
logCtx := logutil.WithExperiment(orig)
patch, modified, err := diff.CreateTwoWayMergePatch(
Expand All @@ -336,15 +339,27 @@ func (ec *Controller) persistExperimentStatus(orig *v1alpha1.Experiment, newStat
return nil
}
logCtx.Debugf("Experiment Patch: %s", patch)
_, err = ec.argoProjClientset.ArgoprojV1alpha1().Experiments(orig.Namespace).Patch(ctx, orig.Name, patchtypes.MergePatchType, patch, metav1.PatchOptions{})
patched, err := ec.argoProjClientset.ArgoprojV1alpha1().Experiments(orig.Namespace).Patch(ctx, orig.Name, patchtypes.MergePatchType, patch, metav1.PatchOptions{})
if err != nil {
logCtx.Warningf("Error updating experiment: %v", err)
return err
}
logCtx.Info("Patch status successfully")
ec.recordEvent(patched, prevStatus, newStatus)
return nil
}

func (ec *Controller) recordEvent(ex *v1alpha1.Experiment, prevStatus v1alpha1.ExperimentStatus, newStatus *v1alpha1.ExperimentStatus) {
if prevStatus.Phase != newStatus.Phase {
eventType := corev1.EventTypeNormal
switch newStatus.Phase {
case v1alpha1.AnalysisPhaseError, v1alpha1.AnalysisPhaseFailed, v1alpha1.AnalysisPhaseInconclusive:
eventType = corev1.EventTypeWarning
}
ec.recorder.Eventf(ex, record.EventOptions{EventType: eventType, EventReason: "Experiment" + string(newStatus.Phase)}, "Experiment transitioned from %s -> %s", prevStatus.Phase, newStatus.Phase)
}
}

// enqueueIfCompleted conditionally enqueues the AnalysisRun's Experiment if the run is complete
func (ec *Controller) enqueueIfCompleted(obj any) {
run := unstructuredutil.ObjectToAnalysisRun(obj)
Expand Down
9 changes: 0 additions & 9 deletions experiments/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ func (ec *experimentContext) ResolveAnalysisRunArgs(args []v1alpha1.Argument) ([
}

func (ec *experimentContext) calculateStatus() *v1alpha1.ExperimentStatus {
prevStatus := ec.newStatus.DeepCopy()
switch ec.newStatus.Phase {
case "":
ec.newStatus.Phase = v1alpha1.AnalysisPhasePending
Expand Down Expand Up @@ -568,14 +567,6 @@ func (ec *experimentContext) calculateStatus() *v1alpha1.ExperimentStatus {
}
}
ec.newStatus = calculateExperimentConditions(ec.ex, *ec.newStatus)
if prevStatus.Phase != ec.newStatus.Phase {
eventType := corev1.EventTypeNormal
switch ec.newStatus.Phase {
case v1alpha1.AnalysisPhaseError, v1alpha1.AnalysisPhaseFailed, v1alpha1.AnalysisPhaseInconclusive:
eventType = corev1.EventTypeWarning
}
ec.recorder.Eventf(ec.ex, record.EventOptions{EventType: eventType, EventReason: "Experiment" + string(ec.newStatus.Phase)}, "Experiment transitioned from %s -> %s", prevStatus.Phase, ec.newStatus.Phase)
}
return ec.newStatus
}

Expand Down
Loading