Skip to content

Commit

Permalink
add rollback in deploy stats (#3928)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zhao <[email protected]>
  • Loading branch information
PetrusZ authored Jan 3, 2025
1 parent 855269d commit 89c3c50
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
20 changes: 12 additions & 8 deletions pkg/microservice/aslan/core/common/repository/mongodb/env_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ func (c *EnvInfoColl) Create(ctx *internalhandler.Context, args *models.EnvInfo)
}

type ListEnvInfoOption struct {
PageNum int
PageSize int
ProjectName string
EnvName string
ServiceName string
StartTime int64
EndTime int64
Operation config.EnvOperation
PageNum int
PageSize int
ProjectName string
ProjectNames []string
EnvName string
ServiceName string
StartTime int64
EndTime int64
Operation config.EnvOperation
}

func (c *EnvInfoColl) List(ctx context.Context, opt *ListEnvInfoOption) ([]*models.EnvInfo, int64, error) {
Expand All @@ -112,6 +113,9 @@ func (c *EnvInfoColl) List(ctx context.Context, opt *ListEnvInfoOption) ([]*mode
if len(opt.ProjectName) > 0 {
findOption["project_name"] = opt.ProjectName
}
if len(opt.ProjectNames) > 0 {
findOption["project_name"] = bson.M{"$in": opt.ProjectNames}
}
if len(opt.EnvName) > 0 {
findOption["env_name"] = opt.EnvName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type WeeklyDeployStat struct {
ProjectKey string `bson:"project_key" json:"project_key,omitempty"`
Production bool `bson:"production" json:"production"`
Success int `bson:"success" json:"success"`
Rollback int `bson:"rollback" json:"rollback"`
Failed int `bson:"failed" json:"failed"`
Timeout int `bson:"timeout" json:"timeout"`
Date string `bson:"date" json:"date"`
Expand Down
40 changes: 33 additions & 7 deletions pkg/microservice/aslan/core/stat/service/deploy_stat_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package service

import (
"context"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -269,12 +270,14 @@ func GetDeployMonthlyTrend(startTime, endTime int64, projects []string, producti
}

var (
testSuccess = 0
testFailed = 0
testTimeout = 0
productionSuccess = 0
productionFailed = 0
productionTimeout = 0
testSuccess = 0
testRollback = 0
testFailed = 0
testTimeout = 0
productionSuccess = 0
productionRollback = 0
productionFailed = 0
productionTimeout = 0
)

// count the data for both production job
Expand All @@ -300,13 +303,34 @@ func GetDeployMonthlyTrend(startTime, endTime int64, projects []string, producti
}
}

envInfos, _, err := commonrepo.NewEnvInfoColl().List(context.Background(), &commonrepo.ListEnvInfoOption{
ProjectNames: projects,
Operation: config.EnvOperationRollback,
StartTime: startTime,
EndTime: endTime,
})
if err != nil {
err = fmt.Errorf("failed to list env info for projects: %v, error: %s", projects, err)
log.Error(err)
return nil, err
}

for _, envInfo := range envInfos {
if !envInfo.Production {
testRollback++
} else {
productionRollback++
}
}

date := time.Unix(firstDayOfMonth, 0).Format(config.Date)

switch production {
case config.Production:
monthlystats = append(monthlystats, &models.WeeklyDeployStat{
Production: true,
Success: productionSuccess,
Rollback: productionRollback,
Failed: productionFailed,
Timeout: productionTimeout,
Date: date,
Expand All @@ -315,6 +339,7 @@ func GetDeployMonthlyTrend(startTime, endTime int64, projects []string, producti
monthlystats = append(monthlystats, &models.WeeklyDeployStat{
Production: false,
Success: testSuccess,
Rollback: testRollback,
Failed: testFailed,
Timeout: testTimeout,
Date: date,
Expand All @@ -323,13 +348,15 @@ func GetDeployMonthlyTrend(startTime, endTime int64, projects []string, producti
monthlystats = append(monthlystats, &models.WeeklyDeployStat{
Production: true,
Success: productionSuccess,
Rollback: productionRollback,
Failed: productionFailed,
Timeout: productionTimeout,
Date: date,
})
monthlystats = append(monthlystats, &models.WeeklyDeployStat{
Production: false,
Success: testSuccess,
Rollback: testRollback,
Failed: testFailed,
Timeout: testTimeout,
Date: date,
Expand Down Expand Up @@ -491,7 +518,6 @@ func generateMonthlyDeployStatByProduct(projectKey string, log *zap.SugaredLogge
}

date := startTime.Format(config.Date)

testDeployStat = &models.WeeklyDeployStat{
ProjectKey: projectKey,
Production: false,
Expand Down

0 comments on commit 89c3c50

Please sign in to comment.