Skip to content

Commit d9d90ba

Browse files
authored
chore: updating deployment status start and end time (#6171)
* updating deployment status start and end time * adding comment
1 parent a99af2e commit d9d90ba

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

pkg/app/AppService.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/adapter/cdWorkflow"
2828
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/timelineStatus"
2929
cdWorkflow2 "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow"
30+
"github.com/devtron-labs/devtron/pkg/argoApplication/helper"
3031
installedAppReader "github.com/devtron-labs/devtron/pkg/appStore/installedApp/read"
3132
common2 "github.com/devtron-labs/devtron/pkg/deployment/common"
3233
bean2 "github.com/devtron-labs/devtron/pkg/deployment/common/bean"
@@ -550,7 +551,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
550551
// creating cd pipeline status timeline
551552
timeline := &pipelineConfig.PipelineStatusTimeline{
552553
CdWorkflowRunnerId: runnerHistoryId,
553-
StatusTime: statusTime,
554+
StatusTime: helper.GetSyncStartTime(app, statusTime),
554555
AuditLog: sql.AuditLog{
555556
CreatedBy: 1,
556557
CreatedOn: time.Now(),
@@ -583,6 +584,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
583584
timeline.Id = 0
584585
timeline.Status = timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED
585586
timeline.StatusDetail = app.Status.OperationState.Message
587+
timeline.StatusTime = helper.GetSyncFinishTime(app, statusTime)
586588
// checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times
587589
err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil)
588590
if err != nil {
@@ -662,7 +664,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
662664
// creating installedAppVersionHistory status timeline
663665
timeline := &pipelineConfig.PipelineStatusTimeline{
664666
InstalledAppVersionHistoryId: runnerHistoryId,
665-
StatusTime: statusTime,
667+
StatusTime: helper.GetSyncStartTime(app, statusTime),
666668
AuditLog: sql.AuditLog{
667669
CreatedBy: 1,
668670
CreatedOn: time.Now(),
@@ -695,6 +697,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
695697
timeline.Id = 0
696698
timeline.Status = timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED
697699
timeline.StatusDetail = app.Status.OperationState.Message
700+
timeline.StatusTime = helper.GetSyncFinishTime(app, statusTime)
698701
// checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times
699702
err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil)
700703
if err != nil {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package helper
2+
3+
import (
4+
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
"time"
7+
)
8+
9+
// GetSyncStartTime assumes that it is always called for calculating start time of latest git hash
10+
func GetSyncStartTime(app *v1alpha1.Application, defaultStartTime time.Time) time.Time {
11+
startTime := metav1.NewTime(defaultStartTime)
12+
gitHash := app.Status.Sync.Revision
13+
if app.Status.OperationState != nil {
14+
startTime = app.Status.OperationState.StartedAt
15+
} else if app.Status.History != nil {
16+
for _, history := range app.Status.History {
17+
if history.Revision == gitHash {
18+
startTime = *history.DeployStartedAt
19+
}
20+
}
21+
}
22+
return startTime.Time
23+
}
24+
25+
// GetSyncFinishTime assumes that it is always called for calculating finish time of latest git hash
26+
func GetSyncFinishTime(app *v1alpha1.Application, defaultEndTime time.Time) time.Time {
27+
finishTime := metav1.NewTime(defaultEndTime)
28+
gitHash := app.Status.Sync.Revision
29+
if app.Status.OperationState != nil && app.Status.OperationState.FinishedAt != nil {
30+
finishTime = *app.Status.OperationState.FinishedAt
31+
} else if app.Status.History != nil {
32+
for _, history := range app.Status.History {
33+
if history.Revision == gitHash {
34+
finishTime = history.DeployedAt
35+
}
36+
}
37+
}
38+
return finishTime.Time
39+
}

0 commit comments

Comments
 (0)