Skip to content

Commit

Permalink
fix bug on monthly deploy stat (#3974)
Browse files Browse the repository at this point in the history
* fix bug on monthly deploy stat

Signed-off-by: Min Min <[email protected]>

* debug

Signed-off-by: Min Min <[email protected]>

* fix monthly data not being created

Signed-off-by: Min Min <[email protected]>

---------

Signed-off-by: Min Min <[email protected]>
  • Loading branch information
jamsman94 authored Jan 26, 2025
1 parent 9aa7247 commit abec18b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ func (c *MonthlyDeployStatColl) CalculateStat(startTime, endTime int64, projects
"timeout": "$total_timeout",
},
})
pipeline = append(pipeline, bson.M{
"$sort": bson.M{
"date": 1,
},
})

cursor, err := c.Aggregate(context.TODO(), pipeline)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/microservice/aslan/core/stat/service/deploy_stat_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ func GetDeployMonthlyTrend(startTime, endTime int64, projects []string, producti

// then calculate the start time of this week, append it to the end of the array
firstDayOfMonth := util.GetFirstOfMonthDay(time.Now())
firstDayOfEndTimeMonth := util.GetFirstOfMonthDay(time.Unix(endTime, 0))
if firstDayOfEndTimeMonth < firstDayOfMonth {
return monthlystats, nil
}

allDeployJobs, err := commonrepo.NewJobInfoColl().GetDeployJobs(firstDayOfMonth, time.Now().Unix(), projects, production)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/microservice/cron/core/service/client/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *Client) InitStatData(log *zap.SugaredLogger) error {

// if it is the first day of a month, do the monthly deploy stats
if time.Now().Day() == 1 {
url = fmt.Sprintf("%s/api/stat/v2/quality/deploy/weekly", configbase.AslanServiceAddress())
url = fmt.Sprintf("%s/api/stat/v2/quality/deploy/monthly", configbase.AslanServiceAddress())
log.Info("start creating monthly deploy stats..")
_, err = c.sendPostRequest(url, nil, log)
if err != nil {
Expand Down

0 comments on commit abec18b

Please sign in to comment.