Skip to content

Commit

Permalink
fix(application): restore metrics when app status is successed (#2016)
Browse files Browse the repository at this point in the history
Co-authored-by: xdonggao <[email protected]>
  • Loading branch information
GaoXiaodong and xdonggao authored Aug 4, 2022
1 parent 159feb8 commit 446af1b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/application/controller/app/action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ func Install(ctx context.Context,
newStatus.Reason = ""
newStatus.LastTransitionTime = metav1.Now()
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationRollbackFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
}
newApp, updateStatusErr = updateStatusFunc(ctx, newApp, &newApp.Status, newStatus)
if updateStatusErr != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/application/controller/app/action/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func Rollback(ctx context.Context,
newStatus.Reason = ""
newStatus.LastTransitionTime = metav1.Now()
newStatus.RollbackRevision = 0 // clean revision
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationRollbackFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
}
app, updateStatusErr = updateStatusFunc(ctx, app, &app.Status, newStatus)
Expand Down
2 changes: 2 additions & 0 deletions pkg/application/controller/app/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func Upgrade(ctx context.Context,
newStatus.Message = ""
newStatus.Reason = ""
newStatus.LastTransitionTime = metav1.Now()
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationRollbackFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
}
newApp, updateStatusErr = updateStatusFunc(ctx, newApp, &newApp.Status, newStatus)
if updateStatusErr != nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/application/controller/app/app_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ func (c *Controller) syncItem(key string) error {
log.String("name", name))
_ = c.processDeletion(key)
err = c.appResourcesDeleter.Delete(context.Background(), namespace, name)
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationRollbackFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationSyncFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
// If err is not nil, do not update object status when phase is Terminating.
// DeletionTimestamp is not empty and object will be deleted when you request updateStatus
} else {
Expand Down Expand Up @@ -405,6 +409,9 @@ func (c *Controller) syncAppFromRelease(ctx context.Context, cachedApp *cachedAp
newStatus.Reason = ""
newStatus.LastTransitionTime = metav1.Now()
metrics.GaugeApplicationSyncFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
metrics.GaugeApplicationRollbackFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)

newStatus.ReleaseStatus = string(rel.Info.Status)
newStatus.Revision = int64(rel.Version)
Expand Down

0 comments on commit 446af1b

Please sign in to comment.