From d37d3ed124e545e1a9c0d82b0b5509dd150e22a3 Mon Sep 17 00:00:00 2001 From: Ethan Mosbaugh Date: Wed, 20 Nov 2024 14:57:28 -0800 Subject: [PATCH] f --- pkg/embeddedcluster/metrics.go | 6 +++++- pkg/operator/operator.go | 6 ++++-- pkg/upgradeservice/deploy/deploy.go | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/embeddedcluster/metrics.go b/pkg/embeddedcluster/metrics.go index 695b86693a..03fd113cfe 100644 --- a/pkg/embeddedcluster/metrics.go +++ b/pkg/embeddedcluster/metrics.go @@ -9,6 +9,7 @@ import ( "time" embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1" + "github.com/replicatedhq/kots/pkg/logger" ) // UpgradeStartedEvent is send back home when the upgrade starts. @@ -46,7 +47,7 @@ func NotifyUpgradeStarted(ctx context.Context, baseURL string, ins, prev *embedd } // NotifyUpgradeFailed notifies the metrics server that an upgrade has failed. -func NotifyUpgradeFailed(ctx context.Context, baseURL string, ins, prev *embeddedclusterv1beta1.Installation) error { +func NotifyUpgradeFailed(ctx context.Context, baseURL string, ins, prev *embeddedclusterv1beta1.Installation, reason string) error { if ins.Spec.AirGap { return nil } @@ -54,6 +55,7 @@ func NotifyUpgradeFailed(ctx context.Context, baseURL string, ins, prev *embedde ClusterID: ins.Spec.ClusterID, TargetVersion: ins.Spec.Config.Version, InitialVersion: prev.Spec.Config.Version, + Reason: reason, }) } @@ -73,6 +75,8 @@ func NotifyUpgradeSucceeded(ctx context.Context, baseURL string, ins, prev *embe func sendEvent(ctx context.Context, evname, baseURL string, ev interface{}) error { url := fmt.Sprintf("%s/embedded_cluster_metrics/%s", baseURL, evname) + logger.Infof("Sending event %s to %s", evname, url) + body := map[string]interface{}{"event": ev} buf := bytes.NewBuffer(nil) if err := json.NewEncoder(buf).Encode(body); err != nil { diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 569860bfbb..e5def5d443 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -1044,19 +1044,21 @@ func (o *Operator) waitForClusterUpgrade(appID string, appSlug string) error { if err != nil { return errors.Wrap(err, "failed to get kube client") } - logger.Infof("waiting for cluster upgrade to finish") + logger.Infof("Waiting for cluster upgrade to finish") for { ins, err := embeddedcluster.GetCurrentInstallation(ctx, kbClient) if err != nil { return errors.Wrap(err, "failed to wait for embedded cluster installation") } if embeddedcluster.InstallationSucceeded(ctx, ins) { + logger.Infof("Cluster upgrade succeeded") if err := o.notifyUpgradeSucceeded(ctx, kbClient, ins, appID); err != nil { logger.Errorf("Failed to notify upgrade succeeded: %v", err) } return nil } if embeddedcluster.InstallationFailed(ctx, ins) { + logger.Infof("Cluster upgrade failed") if err := o.notifyUpgradeFailed(ctx, kbClient, ins, appID); err != nil { logger.Errorf("Failed to notify upgrade failed: %v", err) } @@ -1115,7 +1117,7 @@ func (o *Operator) notifyUpgradeFailed(ctx context.Context, kbClient kbclient.Cl return errors.New("previous installation not found") } - err = embeddedcluster.NotifyUpgradeFailed(ctx, license.Spec.Endpoint, ins, prev) + err = embeddedcluster.NotifyUpgradeFailed(ctx, license.Spec.Endpoint, ins, prev, ins.Status.Reason) if err != nil { return errors.Wrap(err, "failed to send event") } diff --git a/pkg/upgradeservice/deploy/deploy.go b/pkg/upgradeservice/deploy/deploy.go index 39a56c5a44..427b3adba6 100644 --- a/pkg/upgradeservice/deploy/deploy.go +++ b/pkg/upgradeservice/deploy/deploy.go @@ -120,7 +120,7 @@ func Deploy(opts DeployOptions) error { go func() (finalError error) { defer func() { if finalError != nil { - if err := notifyUpgradeFailed(context.Background(), kbClient, opts); err != nil { + if err := notifyUpgradeFailed(context.Background(), kbClient, opts, finalError.Error()); err != nil { logger.Errorf("Failed to notify upgrade failed: %v", err) } if err := task.SetStatusUpgradeFailed(opts.Params.AppSlug, finalError.Error()); err != nil { @@ -184,7 +184,7 @@ func notifyUpgradeStarted(ctx context.Context, kbClient kbclient.Client, opts De } // notifyUpgradeFailed sends a metrics event to the api that the upgrade failed. -func notifyUpgradeFailed(ctx context.Context, kbClient kbclient.Client, opts DeployOptions) error { +func notifyUpgradeFailed(ctx context.Context, kbClient kbclient.Client, opts DeployOptions, reason string) error { ins, err := embeddedcluster.GetCurrentInstallation(ctx, kbClient) if err != nil { return fmt.Errorf("failed to get current installation: %w", err) @@ -201,7 +201,7 @@ func notifyUpgradeFailed(ctx context.Context, kbClient kbclient.Client, opts Dep return errors.New("previous installation not found") } - err = embeddedcluster.NotifyUpgradeFailed(ctx, opts.KotsKinds.License.Spec.Endpoint, ins, prev) + err = embeddedcluster.NotifyUpgradeFailed(ctx, opts.KotsKinds.License.Spec.Endpoint, ins, prev, reason) if err != nil { return errors.Wrap(err, "failed to send event") }