Skip to content

Commit

Permalink
feat: show specific deploy error message (#35)
Browse files Browse the repository at this point in the history
* feat:add deploy failcase to metaData

* feat: dice2.0 add deploy failcase to metaData

* style: remove useless comments

* perf: remove develop log

* perf: error format

* perf: error format
  • Loading branch information
CeerDecy authored Mar 6, 2024
1 parent 1329655 commit 384b187
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
12 changes: 10 additions & 2 deletions actions/dice/1.0/internal/dice/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/erda-project/erda-actions/pkg/log"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/pkg/filehelper"
"github.com/erda-project/erda/pkg/http/httpclient"
"github.com/erda-project/erda/pkg/http/httputil"
"github.com/erda-project/erda/pkg/retry"

"github.com/erda-project/erda-actions/pkg/log"
)

func Run() error {
Expand Down Expand Up @@ -119,7 +120,7 @@ func storeMetaFileWithErr(conf *conf, runtimeID int64, deploymentID int64, deplo
if deployResult == nil {
return storeMetaFile(conf, runtimeID, deploymentID)
}
if len(deployResult.Data.MoudleErrMsg) == 0 {
if len(deployResult.Data.MoudleErrMsg) == 0 && deployResult.Data.FailCause == "" {
return storeMetaFile(conf, runtimeID, deploymentID)
}
metaData := generateMetadata(conf, runtimeID, deploymentID)
Expand All @@ -129,6 +130,13 @@ func storeMetaFileWithErr(conf *conf, runtimeID int64, deploymentID int64, deplo
Value: v,
})
}
if deployResult.Data.FailCause != "" {
*metaData = append(*metaData, metadata.MetadataField{
Name: "FailCause",
Value: deployResult.Data.FailCause,
Level: metadata.MetadataLevelError,
})
}
// remove that the value is empty
newMetadata := make([]metadata.MetadataField, 0)
for _, v := range *metaData {
Expand Down
30 changes: 17 additions & 13 deletions actions/dice/2.0/internal/pkg/dice/deploy/status_check.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package deploy

import (
"context"
"fmt"
"time"
"sync"
"context"
"time"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/erda-project/erda/pkg/http/httpclient"

"github.com/erda-project/erda-actions/actions/dice/2.0/internal/common"
"github.com/erda-project/erda-actions/actions/dice/2.0/internal/pkg/utils"
"github.com/erda-project/erda-actions/actions/dice/2.0/internal/pkg/dice/callback"
"github.com/erda-project/erda-actions/actions/dice/2.0/internal/pkg/utils"
)

var (
Expand Down Expand Up @@ -75,7 +76,7 @@ func (d *deploy) statusCheckLoop(ctx context.Context, drMap map[string]*common.D
case <-ticker.C:
isDeploying, err := d.check(drMap)
if err != nil {
logrus.Error("failed to check deploy", err)
logrus.Errorf("failed to check deploy, err: %v", err)
return err
}
// deploy done
Expand All @@ -96,7 +97,7 @@ func (d *deploy) checkBatchStatusLoop(ctx context.Context, orderId string) error
case <-ticker.C:
isDeploying, err := d.checkBatch(orderId)
if err != nil {
logrus.Error("failed to check deploy", err)
logrus.Errorf("failed to check deploy, err: %v", err)
return err
}
// deploy done
Expand Down Expand Up @@ -162,6 +163,16 @@ func (d *deploy) check(drMap map[string]*common.DeployResult) (bool, error) {
needPrint, isErr, isDeploying bool
)

defer func() {
// error message will store meta and report
if isErr {
err := d.store.BatchStoreMetaFile(statusResult)
if err != nil {
logrus.Errorf("failed to batch store meta file, err: %v", err)
}
}
}()

// analyse status check results
for appName, data := range statusResult {
if data == nil {
Expand All @@ -188,6 +199,7 @@ func (d *deploy) check(drMap map[string]*common.DeployResult) (bool, error) {
tmpIsDeploying, err := parseStatus(data)
if err != nil {
logrus.Debug(err)
isErr = true
return isDeploying, err
}

Expand All @@ -202,14 +214,6 @@ func (d *deploy) check(drMap map[string]*common.DeployResult) (bool, error) {
utils.BatchPrintStatusCheckResult(statusResult)
}

// error message will store meta and report
if isErr {
err := d.store.BatchStoreMetaFile(statusResult)
if err != nil {
logrus.Errorf("failed to batch store meta file, err: %v", err)
}
}

return isDeploying, nil
}

Expand Down
11 changes: 9 additions & 2 deletions actions/dice/2.0/internal/pkg/dice/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"strconv"
"strings"

"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/pkg/metadata"
"github.com/pkg/errors"

"github.com/erda-project/erda-actions/actions/dice/2.0/internal/common"
"github.com/erda-project/erda-actions/actions/dice/2.0/internal/conf"
"github.com/erda-project/erda-actions/actions/dice/2.0/internal/pkg/utils"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/pkg/metadata"
)

type Store interface {
Expand Down Expand Up @@ -98,6 +98,13 @@ func (s *store) BatchStoreMetaFile(statusResp map[string]*common.DeploymentStatu
}...)
break
}
if resp.Data.FailCause != "" {
metaData = append(metaData, metadata.MetadataField{
Name: "FailCause",
Value: resp.Data.FailCause,
Level: metadata.MetadataLevelError,
})
}
}

return s.storeMetaFile(metaData)
Expand Down

0 comments on commit 384b187

Please sign in to comment.