Skip to content

Commit

Permalink
fix(application): fix application install metrics (#1985)
Browse files Browse the repository at this point in the history
Co-authored-by: xdonggao <xdonggao@tencent.com>
  • Loading branch information
GaoXiaodong and xdonggao committed May 31, 2022
1 parent b57bc60 commit caa7c32
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/application/controller/app/action/install.go
Expand Up @@ -58,7 +58,7 @@ func Install(ctx context.Context,
if updateStatusFunc != nil {
if app.Status.Phase == applicationv1.AppPhaseInstallFailed {
log.Error(fmt.Sprintf("install app failed, helm pull err: %s", err.Error()))
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
// delayed retry, queue.AddRateLimited does not meet the demand
return app, nil
}
Expand All @@ -67,7 +67,7 @@ func Install(ctx context.Context,
newStatus.Reason = err.Error()
newStatus.LastTransitionTime = metav1.Now()
_, updateStatusErr := updateStatusFunc(ctx, app, &app.Status, newStatus)
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
if updateStatusErr != nil {
return nil, updateStatusErr
}
Expand Down Expand Up @@ -104,20 +104,21 @@ func Install(ctx context.Context,
if err != nil {
if app.Status.Phase == applicationv1.AppPhaseInstallFailed {
log.Error(fmt.Sprintf("install app failed, helm install err: %s", err.Error()))
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
// delayed retry, queue.AddRateLimited does not meet the demand
return app, nil
}
newStatus.Phase = applicationv1.AppPhaseInstallFailed
newStatus.Message = "install app failed"
newStatus.Reason = err.Error()
newStatus.LastTransitionTime = metav1.Now()
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
} else {
newStatus.Phase = applicationv1.AppPhaseSucceeded
newStatus.Message = ""
newStatus.Reason = ""
newStatus.LastTransitionTime = metav1.Now()
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
}
newApp, updateStatusErr = updateStatusFunc(ctx, newApp, &newApp.Status, newStatus)
if updateStatusErr != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/application/controller/app/action/rollback.go
Expand Up @@ -70,6 +70,7 @@ func Rollback(ctx context.Context,
newStatus.Reason = ""
newStatus.LastTransitionTime = metav1.Now()
newStatus.RollbackRevision = 0 // clean revision
metrics.GaugeApplicationRollbackFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
}
app, updateStatusErr = updateStatusFunc(ctx, app, &app.Status, newStatus)
if updateStatusErr != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/application/controller/app/action/upgrade.go
Expand Up @@ -119,6 +119,7 @@ func Upgrade(ctx context.Context,
newStatus.Message = ""
newStatus.Reason = ""
newStatus.LastTransitionTime = metav1.Now()
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(0)
}
newApp, updateStatusErr = updateStatusFunc(ctx, newApp, &newApp.Status, newStatus)
if updateStatusErr != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/application/controller/app/app_controller.go
Expand Up @@ -404,6 +404,7 @@ func (c *Controller) syncAppFromRelease(ctx context.Context, cachedApp *cachedAp
newStatus.Message = ""
newStatus.Reason = ""
newStatus.LastTransitionTime = metav1.Now()
metrics.GaugeApplicationSyncFailed.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 caa7c32

Please sign in to comment.