Skip to content

Commit c0ca530

Browse files
Hellspamzachaller
andauthored
fix(experiments): move recorder event to after experiment reconciliation, fixes #4021 (#4022)
* fix: move recorder event to after experiment reconcilation, fixes #4021 Signed-off-by: Roy Arnon <[email protected]> * Add Taboola to the user list --------- Signed-off-by: Roy Arnon <[email protected]> Co-authored-by: Zach Aller <[email protected]>
1 parent 07c1028 commit c0ca530

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

USERS.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Organizations below are **officially** using Argo Rollouts. Please send a PR wit
5252
1. [Skillz](https://www.skillz.com)
5353
1. [Spotify](https://www.spotify.com/)
5454
1. [Synamedia](https://www.synamedia.com)
55+
1. [Taboola](https://www.taboola.com)
5556
1. [TBC Bank](https://tbcbank.ge/)
5657
1. [Trustly](https://www.trustly.com/)
5758
1. [Tuhu](https://www.tuhu.cn/)

experiments/controller.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"sync"
66
"time"
77

8+
corev1 "k8s.io/api/core/v1"
9+
810
log "github.com/sirupsen/logrus"
911
appsv1 "k8s.io/api/apps/v1"
1012
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -318,6 +320,7 @@ func (ec *Controller) syncHandler(ctx context.Context, key string) error {
318320
}
319321

320322
func (ec *Controller) persistExperimentStatus(orig *v1alpha1.Experiment, newStatus *v1alpha1.ExperimentStatus) error {
323+
prevStatus := orig.Status
321324
ctx := context.TODO()
322325
logCtx := logutil.WithExperiment(orig)
323326
patch, modified, err := diff.CreateTwoWayMergePatch(
@@ -336,15 +339,27 @@ func (ec *Controller) persistExperimentStatus(orig *v1alpha1.Experiment, newStat
336339
return nil
337340
}
338341
logCtx.Debugf("Experiment Patch: %s", patch)
339-
_, err = ec.argoProjClientset.ArgoprojV1alpha1().Experiments(orig.Namespace).Patch(ctx, orig.Name, patchtypes.MergePatchType, patch, metav1.PatchOptions{})
342+
patched, err := ec.argoProjClientset.ArgoprojV1alpha1().Experiments(orig.Namespace).Patch(ctx, orig.Name, patchtypes.MergePatchType, patch, metav1.PatchOptions{})
340343
if err != nil {
341344
logCtx.Warningf("Error updating experiment: %v", err)
342345
return err
343346
}
344347
logCtx.Info("Patch status successfully")
348+
ec.recordEvent(patched, prevStatus, newStatus)
345349
return nil
346350
}
347351

352+
func (ec *Controller) recordEvent(ex *v1alpha1.Experiment, prevStatus v1alpha1.ExperimentStatus, newStatus *v1alpha1.ExperimentStatus) {
353+
if prevStatus.Phase != newStatus.Phase {
354+
eventType := corev1.EventTypeNormal
355+
switch newStatus.Phase {
356+
case v1alpha1.AnalysisPhaseError, v1alpha1.AnalysisPhaseFailed, v1alpha1.AnalysisPhaseInconclusive:
357+
eventType = corev1.EventTypeWarning
358+
}
359+
ec.recorder.Eventf(ex, record.EventOptions{EventType: eventType, EventReason: "Experiment" + string(newStatus.Phase)}, "Experiment transitioned from %s -> %s", prevStatus.Phase, newStatus.Phase)
360+
}
361+
}
362+
348363
// enqueueIfCompleted conditionally enqueues the AnalysisRun's Experiment if the run is complete
349364
func (ec *Controller) enqueueIfCompleted(obj any) {
350365
run := unstructuredutil.ObjectToAnalysisRun(obj)

experiments/experiment.go

-9
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ func (ec *experimentContext) ResolveAnalysisRunArgs(args []v1alpha1.Argument) ([
523523
}
524524

525525
func (ec *experimentContext) calculateStatus() *v1alpha1.ExperimentStatus {
526-
prevStatus := ec.newStatus.DeepCopy()
527526
switch ec.newStatus.Phase {
528527
case "":
529528
ec.newStatus.Phase = v1alpha1.AnalysisPhasePending
@@ -568,14 +567,6 @@ func (ec *experimentContext) calculateStatus() *v1alpha1.ExperimentStatus {
568567
}
569568
}
570569
ec.newStatus = calculateExperimentConditions(ec.ex, *ec.newStatus)
571-
if prevStatus.Phase != ec.newStatus.Phase {
572-
eventType := corev1.EventTypeNormal
573-
switch ec.newStatus.Phase {
574-
case v1alpha1.AnalysisPhaseError, v1alpha1.AnalysisPhaseFailed, v1alpha1.AnalysisPhaseInconclusive:
575-
eventType = corev1.EventTypeWarning
576-
}
577-
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)
578-
}
579570
return ec.newStatus
580571
}
581572

0 commit comments

Comments
 (0)