Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updating deployment status start and end time #6171

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/app/AppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/adapter/cdWorkflow"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/timelineStatus"
cdWorkflow2 "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow"
"github.com/devtron-labs/devtron/pkg/argoApplication/helper"
installedAppReader "github.com/devtron-labs/devtron/pkg/appStore/installedApp/read"
common2 "github.com/devtron-labs/devtron/pkg/deployment/common"
bean2 "github.com/devtron-labs/devtron/pkg/deployment/common/bean"
Expand Down Expand Up @@ -550,7 +551,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
// creating cd pipeline status timeline
timeline := &pipelineConfig.PipelineStatusTimeline{
CdWorkflowRunnerId: runnerHistoryId,
StatusTime: statusTime,
StatusTime: helper.GetSyncStartTime(app, statusTime),
AuditLog: sql.AuditLog{
CreatedBy: 1,
CreatedOn: time.Now(),
Expand Down Expand Up @@ -583,6 +584,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
timeline.Id = 0
timeline.Status = timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED
timeline.StatusDetail = app.Status.OperationState.Message
timeline.StatusTime = helper.GetSyncFinishTime(app, statusTime)
// checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times
err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil)
if err != nil {
Expand Down Expand Up @@ -662,7 +664,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
// creating installedAppVersionHistory status timeline
timeline := &pipelineConfig.PipelineStatusTimeline{
InstalledAppVersionHistoryId: runnerHistoryId,
StatusTime: statusTime,
StatusTime: helper.GetSyncStartTime(app, statusTime),
AuditLog: sql.AuditLog{
CreatedBy: 1,
CreatedOn: time.Now(),
Expand Down Expand Up @@ -695,6 +697,7 @@ func (impl *AppServiceImpl) UpdatePipelineStatusTimelineForApplicationChanges(ap
timeline.Id = 0
timeline.Status = timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED
timeline.StatusDetail = app.Status.OperationState.Message
timeline.StatusTime = helper.GetSyncFinishTime(app, statusTime)
// checking and saving if this timeline is present or not because kubewatch may stream same objects multiple times
err = impl.pipelineStatusTimelineService.SaveTimeline(timeline, nil)
if err != nil {
Expand Down
39 changes: 39 additions & 0 deletions pkg/argoApplication/helper/deploymentStatusHelper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package helper

import (
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"time"
)

// GetSyncStartTime assumes that it is always called for calculating start time of latest git hash
func GetSyncStartTime(app *v1alpha1.Application, defaultStartTime time.Time) time.Time {
startTime := metav1.NewTime(defaultStartTime)
gitHash := app.Status.Sync.Revision
if app.Status.OperationState != nil {
startTime = app.Status.OperationState.StartedAt
} else if app.Status.History != nil {
for _, history := range app.Status.History {
if history.Revision == gitHash {
startTime = *history.DeployStartedAt
}
}
}
return startTime.Time
}

// GetSyncFinishTime assumes that it is always called for calculating finish time of latest git hash
func GetSyncFinishTime(app *v1alpha1.Application, defaultEndTime time.Time) time.Time {
finishTime := metav1.NewTime(defaultEndTime)
gitHash := app.Status.Sync.Revision
if app.Status.OperationState != nil && app.Status.OperationState.FinishedAt != nil {
finishTime = *app.Status.OperationState.FinishedAt
} else if app.Status.History != nil {
for _, history := range app.Status.History {
if history.Revision == gitHash {
finishTime = history.DeployedAt
}
}
}
return finishTime.Time
}
Loading