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

feat: separate build worker status timeline #6320

Merged
merged 28 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9d3473a
oss changes for build worker status
ayu-devtron Jan 24, 2025
ad4f89f
oss code changes for ent
ayu-devtron Jan 27, 2025
bbec402
update sql script number
ayu-devtron Jan 27, 2025
063a657
update sql script
ayu-devtron Jan 27, 2025
74adbb7
add flag to enable new workflow stage history
ayu-devtron Jan 28, 2025
11c2f50
save workflow before stage in saving
ayu-devtron Jan 28, 2025
249ae53
return cancelled for wf status in case of aborted
ayu-devtron Jan 28, 2025
fe0250b
add in terminal state for cancelled
ayu-devtron Jan 28, 2025
941a95d
add comment and flag description
ayu-devtron Jan 28, 2025
a71d16f
fix for aborted and cancelled
ayu-devtron Jan 28, 2025
2bdc693
add cancel in terminal status
ayu-devtron Jan 28, 2025
0e8c54e
import cycle fix
ayu-devtron Jan 28, 2025
d9995c3
bug fix for cancel and abort
ayu-devtron Jan 28, 2025
279a3de
bug fix updating workflow
ayu-devtron Jan 28, 2025
302f92b
review comments -1
ayu-devtron Jan 31, 2025
1e7491a
ci refactor flow to ci service
ayu-devtron Feb 2, 2025
6cfcda5
move cd functions to cdworkflow runner service
ayu-devtron Feb 2, 2025
5c07fc7
status_type to status_for
ayu-devtron Feb 3, 2025
2630542
Merge branch 'develop' of github.com:devtron-labs/devtron into build-…
ayu-devtron Feb 3, 2025
4741208
Merge branch 'main' of github.com:devtron-labs/devtron into build-wor…
ayu-devtron Feb 4, 2025
06d4e95
merge conflicts + code refactor
ayu-devtron Feb 4, 2025
f91859d
Merge branch 'develop' of github.com:devtron-labs/devtron into build-…
ayu-devtron Feb 5, 2025
d414d6f
handle failure cases before scheduling
ayu-devtron Feb 7, 2025
1d68416
updated sql scripts number
ayu-devtron Feb 7, 2025
2a3a987
merge fix
ayu-devtron Feb 7, 2025
a1f79f1
default flag true & avoid already commited log
ayu-devtron Feb 7, 2025
0ed86d5
update error message
ayu-devtron Feb 7, 2025
361cab8
Merge branch 'develop' into build-worker-status
ayu-devtron Feb 7, 2025
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: 7 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ import (
repository3 "github.com/devtron-labs/devtron/pkg/pipeline/history/repository"
repository5 "github.com/devtron-labs/devtron/pkg/pipeline/repository"
"github.com/devtron-labs/devtron/pkg/pipeline/types"
"github.com/devtron-labs/devtron/pkg/pipeline/workflowStatus"
repository6 "github.com/devtron-labs/devtron/pkg/pipeline/workflowStatus/repository"
"github.com/devtron-labs/devtron/pkg/plugin"
"github.com/devtron-labs/devtron/pkg/policyGovernance"
resourceGroup2 "github.com/devtron-labs/devtron/pkg/resourceGroup"
Expand Down Expand Up @@ -471,6 +473,11 @@ func InitializeApp() (*App, error) {
pipeline.NewCiServiceImpl,
wire.Bind(new(pipeline.CiService), new(*pipeline.CiServiceImpl)),

workflowStatus.NewWorkflowStageFlowStatusServiceImpl,
wire.Bind(new(workflowStatus.WorkFlowStageStatusService), new(*workflowStatus.WorkFlowStageStatusServiceImpl)),
repository6.NewWorkflowStageRepositoryImpl,
wire.Bind(new(repository6.WorkflowStageRepository), new(*repository6.WorkflowStageRepositoryImpl)),

pipelineConfig.NewCiWorkflowRepositoryImpl,
wire.Bind(new(pipelineConfig.CiWorkflowRepository), new(*pipelineConfig.CiWorkflowRepositoryImpl)),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/devtron-labs/devtron/internal/sql/constants"
"github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging"
bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
constants2 "github.com/devtron-labs/devtron/pkg/pipeline/constants"
"github.com/devtron-labs/devtron/util/stringsUtil"
"golang.org/x/exp/maps"
"io"
Expand All @@ -45,7 +46,6 @@ import (
"github.com/devtron-labs/devtron/internal/util"
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
"github.com/devtron-labs/devtron/pkg/bean"
"github.com/devtron-labs/devtron/pkg/pipeline"
bean1 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
"github.com/devtron-labs/devtron/pkg/pipeline/types"
resourceGroup "github.com/devtron-labs/devtron/pkg/resourceGroup"
Expand Down Expand Up @@ -663,7 +663,7 @@ func (handler *PipelineConfigRestHandlerImpl) validateCiTriggerRBAC(token string
// This is being done for jobs, jobs execute in default-env (devtron-ci) namespace by default. so considering DefaultCiNamespace as env for rbac enforcement
envName := ""
if triggerEnvironmentId == 0 {
envName = pipeline.DefaultCiWorkflowNamespace
envName = constants2.DefaultCiWorkflowNamespace
}
appObject := handler.enforcerUtil.GetAppRBACNameByAppId(ciPipeline.AppId)
workflowObject := handler.enforcerUtil.GetWorkflowRBACByCiPipelineId(ciPipelineId, workflowName)
Expand Down
2 changes: 1 addition & 1 deletion env_gen.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions env_gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
| DEFAULT_TARGET_PLATFORM | string | | | | false |
| DOCKER_BUILD_CACHE_PATH | string |/var/lib/docker | | | false |
| ENABLE_BUILD_CONTEXT | bool |false | | | false |
| ENABLE_WORKFLOW_EXECUTION_STAGE | bool |true | if enabled then we will display build stages separately for CI/Job/Pre-Post CD | true | false |
| EXTERNAL_BLOB_STORAGE_CM_NAME | string |blob-storage-cm | | | false |
| EXTERNAL_BLOB_STORAGE_SECRET_NAME | string |blob-storage-secret | | | false |
| EXTERNAL_CD_NODE_LABEL_SELECTOR | | | | | false |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type CdWorkflowRepository interface {
FindCdWorkflowMetaByEnvironmentId(appId int, environmentId int, offset int, size int) ([]CdWorkflowRunner, error)
FindCdWorkflowMetaByPipelineId(pipelineId int, offset int, size int) ([]CdWorkflowRunner, error)
FindArtifactByPipelineIdAndRunnerType(pipelineId int, runnerType apiBean.WorkflowType, limit int, runnerStatuses []string) ([]CdWorkflowRunner, error)
SaveWorkFlowRunner(wfr *CdWorkflowRunner) (*CdWorkflowRunner, error)
UpdateWorkFlowRunner(wfr *CdWorkflowRunner) error
SaveWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) (*CdWorkflowRunner, error)
UpdateWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) error
UpdateIsArtifactUploaded(wfrId int, isArtifactUploaded workflow.ArtifactUploadedType) error
GetPreviousQueuedRunners(cdWfrId, pipelineId int) ([]*CdWorkflowRunner, error)
UpdateRunnerStatusToFailedForIds(errMsg string, triggeredBy int32, cdWfrIds ...int) error
Expand Down Expand Up @@ -451,14 +451,14 @@ func (impl *CdWorkflowRepositoryImpl) FindLastPreOrPostTriggeredByEnvironmentId(
return wfr, err
}

func (impl *CdWorkflowRepositoryImpl) SaveWorkFlowRunner(wfr *CdWorkflowRunner) (*CdWorkflowRunner, error) {
err := impl.dbConnection.Insert(wfr)
func (impl *CdWorkflowRepositoryImpl) SaveWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) (*CdWorkflowRunner, error) {
err := tx.Insert(wfr)
return wfr, err
}

func (impl *CdWorkflowRepositoryImpl) UpdateWorkFlowRunner(wfr *CdWorkflowRunner) error {
func (impl *CdWorkflowRepositoryImpl) UpdateWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) error {
wfr.Message = util.GetTruncatedMessage(wfr.Message, 1000)
err := impl.dbConnection.Update(wfr)
err := tx.Update(wfr)
return err
}

Expand Down
12 changes: 6 additions & 6 deletions internal/sql/repository/pipelineConfig/CiWorkflowRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
)

type CiWorkflowRepository interface {
SaveWorkFlow(wf *CiWorkflow) error
SaveWorkFlowWithTx(wf *CiWorkflow, tx *pg.Tx) error
FindLastTriggeredWorkflow(pipelineId int) (*CiWorkflow, error)
UpdateWorkFlow(wf *CiWorkflow) error
UpdateWorkFlowWithTx(wf *CiWorkflow, tx *pg.Tx) error
UpdateArtifactUploaded(id int, isUploaded workflow.ArtifactUploadedType) error
FindByStatusesIn(activeStatuses []string) ([]*CiWorkflow, error)
FindByPipelineId(pipelineId int, offset int, size int) ([]WorkflowWithArtifact, error)
Expand Down Expand Up @@ -263,13 +263,13 @@ func (impl *CiWorkflowRepositoryImpl) FindCiWorkflowGitTriggersByIds(ids []int)
return workflows, err
}

func (impl *CiWorkflowRepositoryImpl) SaveWorkFlow(wf *CiWorkflow) error {
err := impl.dbConnection.Insert(wf)
func (impl *CiWorkflowRepositoryImpl) SaveWorkFlowWithTx(wf *CiWorkflow, tx *pg.Tx) error {
err := tx.Insert(wf)
return err
}

func (impl *CiWorkflowRepositoryImpl) UpdateWorkFlow(wf *CiWorkflow) error {
err := impl.dbConnection.Update(wf)
func (impl *CiWorkflowRepositoryImpl) UpdateWorkFlowWithTx(wf *CiWorkflow, tx *pg.Tx) error {
err := tx.Update(wf)
return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/devtron-labs/devtron/client/argocdServer/bean"
)

var WfrTerminalStatusList = []string{WorkflowAborted, WorkflowFailed, WorkflowSucceeded, bean.HIBERNATING, string(health.HealthStatusHealthy), string(health.HealthStatusDegraded)}
var WfrTerminalStatusList = []string{WorkflowAborted, WorkflowFailed, WorkflowSucceeded, bean.HIBERNATING, string(health.HealthStatusHealthy), string(health.HealthStatusDegraded), WorkflowTimedOut, WorkflowCancel}

type WorkflowStatus int

Expand Down Expand Up @@ -34,6 +34,7 @@ const (
WorkflowTypeDeploy = "DEPLOY"
WorkflowTypePre = "PRE"
WorkflowTypePost = "POST"
WorkflowWaitingToStart = "WaitingToStart"
)

func (a WorkflowStatus) String() string {
Expand All @@ -60,3 +61,6 @@ type CdWorkflowRunnerArtifactMetadata struct {
ParentCiArtifact int `pg:"parent_ci_artifact"`
Scanned bool `pg:"scanned"`
}

const WorkflowCancel = "CANCELLED"
const POD_DELETED_MESSAGE = "pod deleted"
8 changes: 6 additions & 2 deletions pkg/app/AppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
bean6 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/bean"
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/read"
bean4 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean"
"github.com/devtron-labs/devtron/pkg/workflow/cd"
"io/ioutil"
"net/url"
"path"
Expand Down Expand Up @@ -125,6 +126,7 @@ type AppServiceImpl struct {
appListingService AppListingService
deploymentConfigService common2.DeploymentConfigService
envConfigOverrideReadService read.EnvConfigOverrideService
cdWorkflowRunnerService cd.CdWorkflowRunnerService
}

type AppService interface {
Expand Down Expand Up @@ -164,7 +166,8 @@ func NewAppService(
deploymentTemplateService deploymentTemplate.DeploymentTemplateService,
appListingService AppListingService,
deploymentConfigService common2.DeploymentConfigService,
envConfigOverrideReadService read.EnvConfigOverrideService) *AppServiceImpl {
envConfigOverrideReadService read.EnvConfigOverrideService,
cdWorkflowRunnerService cd.CdWorkflowRunnerService) *AppServiceImpl {
appServiceImpl := &AppServiceImpl{
mergeUtil: mergeUtil,
pipelineOverrideRepository: pipelineOverrideRepository,
Expand Down Expand Up @@ -194,6 +197,7 @@ func NewAppService(
appListingService: appListingService,
deploymentConfigService: deploymentConfigService,
envConfigOverrideReadService: envConfigOverrideReadService,
cdWorkflowRunnerService: cdWorkflowRunnerService,
}
return appServiceImpl
}
Expand Down Expand Up @@ -1005,7 +1009,7 @@ func (impl *AppServiceImpl) UpdateCdWorkflowRunnerByACDObject(app *v1alpha1.Appl
}
wfr.UpdatedBy = 1
wfr.UpdatedOn = time.Now()
err = impl.cdWorkflowRepository.UpdateWorkFlowRunner(wfr)
err = impl.cdWorkflowRunnerService.UpdateCdWorkflowRunnerWithStage(wfr)
if err != nil {
impl.logger.Errorw("error on update cd workflow runner", "wfr", wfr, "app", app, "err", err)
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (impl *TriggerServiceImpl) TriggerPostStage(request bean.TriggerRequest) (*
runner.Status = cdWorkflow.WorkflowFailed
runner.Message = err.Error()
runner.FinishedOn = time.Now()
_ = impl.cdWorkflowRepository.UpdateWorkFlowRunner(runner)
_ = impl.cdWorkflowRunnerService.UpdateCdWorkflowRunnerWithStage(runner)
return nil, err
}

Expand All @@ -129,7 +129,7 @@ func (impl *TriggerServiceImpl) TriggerPostStage(request bean.TriggerRequest) (*
runner.Status = cdWorkflow.WorkflowFailed
runner.Message = err.Error()
runner.FinishedOn = time.Now()
_ = impl.cdWorkflowRepository.UpdateWorkFlowRunner(runner)
_ = impl.cdWorkflowRunnerService.UpdateCdWorkflowRunnerWithStage(runner)
return nil, err
}
manifestPushTempate, err := impl.getManifestPushTemplateForPostStage(request, envDevploymentConfig, jobHelmPackagePath, cdStageWorkflowRequest, cdWf, runner, pipeline, triggeredBy, triggeredAt)
Expand All @@ -143,7 +143,7 @@ func (impl *TriggerServiceImpl) TriggerPostStage(request bean.TriggerRequest) (*
return nil, err
}
wfr.ImagePathReservationIds = pluginImagePathReservationIds
err = impl.cdWorkflowRepository.UpdateWorkFlowRunner(&wfr)
err = impl.cdWorkflowRunnerService.UpdateCdWorkflowRunnerWithStage(&wfr)
if err != nil {
impl.logger.Error("error in updating image path reservation ids in cd workflow runner", "err", "err")
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/deployment/trigger/devtronApps/PreStageTriggerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
blob_storage "github.com/devtron-labs/common-lib/blob-storage"
commonBean "github.com/devtron-labs/common-lib/workflow"
bean2 "github.com/devtron-labs/devtron/api/bean"
Expand Down Expand Up @@ -135,11 +136,11 @@ func (impl *TriggerServiceImpl) TriggerPreStage(request bean.TriggerRequest) (*b
runner.Status = cdWorkflow.WorkflowFailed
runner.Message = err.Error()
runner.FinishedOn = time.Now()
_ = impl.cdWorkflowRepository.UpdateWorkFlowRunner(runner)
_ = impl.cdWorkflowRunnerService.UpdateCdWorkflowRunnerWithStage(runner)
return nil, err
} else {
runner.ImagePathReservationIds = imagePathReservationIds
_ = impl.cdWorkflowRepository.UpdateWorkFlowRunner(runner)
_ = impl.cdWorkflowRunnerService.UpdateCdWorkflowRunnerWithStage(runner)
}

_, span = otel.Tracer("orchestrator").Start(ctx, "cdWorkflowService.SubmitWorkflow")
Expand All @@ -152,7 +153,7 @@ func (impl *TriggerServiceImpl) TriggerPreStage(request bean.TriggerRequest) (*b
runner.Status = cdWorkflow.WorkflowFailed
runner.Message = err.Error()
runner.FinishedOn = time.Now()
_ = impl.cdWorkflowRepository.UpdateWorkFlowRunner(runner)
_ = impl.cdWorkflowRunnerService.UpdateCdWorkflowRunnerWithStage(runner)
return nil, err
}
manifestPushTemplate, err := impl.getManifestPushTemplateForPreStage(ctx, envDeploymentConfig, pipeline, artifact, jobHelmPackagePath, cdWf, runner, triggeredBy, triggeredAt, request)
Expand Down Expand Up @@ -251,6 +252,7 @@ func (impl *TriggerServiceImpl) createStartingWfAndRunner(request bean.TriggerRe
WorkflowType: request.WorkflowType,
ExecutorType: impl.config.GetWorkflowExecutorType(),
Status: cdWorkflow.WorkflowStarting, // starting PreStage
PodStatus: string(v1alpha1.NodePending),
TriggeredBy: triggeredBy,
StartedOn: triggeredAt,
Namespace: request.RunStageInEnvNamespace,
Expand All @@ -262,7 +264,7 @@ func (impl *TriggerServiceImpl) createStartingWfAndRunner(request bean.TriggerRe
ReferenceId: request.TriggerContext.ReferenceId,
}
_, span := otel.Tracer("orchestrator").Start(ctx, "cdWorkflowRepository.SaveWorkFlowRunner")
_, err = impl.cdWorkflowRepository.SaveWorkFlowRunner(runner)
_, err = impl.cdWorkflowRunnerService.SaveCDWorkflowRunnerWithStage(runner)
span.End()
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -311,7 +313,7 @@ func (impl *TriggerServiceImpl) checkVulnerabilityStatusAndFailWfIfNeeded(ctx co
runner.FinishedOn = time.Now()
runner.UpdatedOn = time.Now()
runner.UpdatedBy = triggeredBy
err = impl.cdWorkflowRepository.UpdateWorkFlowRunner(runner)
err = impl.cdWorkflowRunnerService.UpdateCdWorkflowRunnerWithStage(runner)
if err != nil {
impl.logger.Errorw("error in updating wfr status due to vulnerable image", "err", err)
return err
Expand Down
7 changes: 5 additions & 2 deletions pkg/deployment/trigger/devtronApps/TriggerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type TriggerServiceImpl struct {
gitOperationService git.GitOperationService
attributeService attributes.AttributesService
clusterRepository repository5.ClusterRepository
cdWorkflowRunnerService cd.CdWorkflowRunnerService
}

func NewTriggerServiceImpl(logger *zap.SugaredLogger,
Expand Down Expand Up @@ -230,6 +231,7 @@ func NewTriggerServiceImpl(logger *zap.SugaredLogger,
gitOperationService git.GitOperationService,
attributeService attributes.AttributesService,
clusterRepository repository5.ClusterRepository,
cdWorkflowRunnerService cd.CdWorkflowRunnerService,
) (*TriggerServiceImpl, error) {
impl := &TriggerServiceImpl{
logger: logger,
Expand Down Expand Up @@ -292,6 +294,7 @@ func NewTriggerServiceImpl(logger *zap.SugaredLogger,
ciCdPipelineOrchestrator: ciCdPipelineOrchestrator,
gitOperationService: gitOperationService,
attributeService: attributeService,
cdWorkflowRunnerService: cdWorkflowRunnerService,

clusterRepository: clusterRepository,
}
Expand Down Expand Up @@ -518,7 +521,7 @@ func (impl *TriggerServiceImpl) ManualCdTrigger(triggerContext bean.TriggerConte
AuditLog: sql.AuditLog{CreatedOn: triggeredAt, CreatedBy: overrideRequest.UserId, UpdatedOn: triggeredAt, UpdatedBy: overrideRequest.UserId},
ReferenceId: triggerContext.ReferenceId,
}
savedWfr, err := impl.cdWorkflowRepository.SaveWorkFlowRunner(runner)
savedWfr, err := impl.cdWorkflowRunnerService.SaveCDWorkflowRunnerWithStage(runner)
if err != nil {
impl.logger.Errorw("err in creating cdWorkflowRunner, ManualCdTrigger", "cdWorkflowId", cdWorkflowId, "err", err)
return 0, "", nil, err
Expand Down Expand Up @@ -649,7 +652,7 @@ func (impl *TriggerServiceImpl) TriggerAutomaticDeployment(request bean.TriggerR
AuditLog: sql.AuditLog{CreatedOn: triggeredAt, CreatedBy: triggeredBy, UpdatedOn: triggeredAt, UpdatedBy: triggeredBy},
ReferenceId: request.TriggerContext.ReferenceId,
}
savedWfr, err := impl.cdWorkflowRepository.SaveWorkFlowRunner(runner)
savedWfr, err := impl.cdWorkflowRunnerService.SaveCDWorkflowRunnerWithStage(runner)
if err != nil {
return err
}
Expand Down
Loading