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

Handle skipped stage by piped #3525

Merged
merged 3 commits into from Apr 15, 2022
Merged

Handle skipped stage by piped #3525

merged 3 commits into from Apr 15, 2022

Conversation

knanao
Copy link
Member

@knanao knanao commented Apr 12, 2022

What this PR does / why we need it:
This makes piped enable to handle the skipped stage.
And add the notification of this in another PR.

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 35.62%. This pull request decreases coverage by -0.07%.

File Function Base Head Diff
pkg/app/piped/executor/analysis/analysis.go Executor.checkSkipped -- 0.00% +0.00%
pkg/app/piped/executor/analysis/analysis.go Executor.Execute 0.00% 0.00% +0.00%

continue
}
status = model.StageStatus_STAGE_SKIPPED
ctxWithTimeout.Done()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this stage has already been skipped, all of the analysis should be stopped gracefully.
Thus, call ctxWithTimeout.Done() in order to stop all stages of the analysis.

defer close(doneCh)
go func() {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all stages of the analysis have already been done, this should be stopped gracefully too.

@knanao
Copy link
Member Author

knanao commented Apr 12, 2022

let me fix it to save the commander who skipped the stage as metadata.
/hold

@knanao
Copy link
Member Author

knanao commented Apr 12, 2022

/hold cancel

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 35.61%. This pull request decreases coverage by -0.08%.

File Function Base Head Diff
pkg/app/piped/executor/analysis/analysis.go Executor.checkSkipped -- 0.00% +0.00%
pkg/app/piped/executor/analysis/analysis.go Executor.Execute 0.00% 0.00% +0.00%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 35.61%. This pull request decreases coverage by -0.08%.

File Function Base Head Diff
pkg/app/piped/executor/analysis/analysis.go Executor.checkSkipped -- 0.00% +0.00%
pkg/app/piped/executor/analysis/analysis.go Executor.Execute 0.00% 0.00% +0.00%

Copy link
Member Author

@knanao knanao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nghialv @khanhtc1202
Sorry, I fixed some points.
So, PTAL when you have enough time.

@nghialv
Copy link
Member

nghialv commented Apr 13, 2022

Sure.

Comment on lines 103 to 111
// Sync the skip command.
var (
status = model.StageStatus_STAGE_NOT_STARTED_YET
doneCh = make(chan struct{})
)
defer close(doneCh)
go func() {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the errgroup is being used so how about running the checker inside a new goroutine of that errgroup instead of using a raw goroutine + doneCh?
https://pkg.go.dev/golang.org/x/sync/errgroup#Group.Go

the checker can return a "skipError" to check at Wait function.

Copy link
Member Author

@knanao knanao Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry if my recognition is wrong.
I dare to generate a goroutine separately from the errgroup since the goroutine generated by the errgroup waits until all routines are completed.
Hence, I think it seems to be difficult to stop gracefully the goroutine which runs checkStopped in that implementation. wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://pkg.go.dev/golang.org/x/sync/errgroup#Group.Go

The first call to return a non-nil error cancels the group; its error will be returned by Wait.

And the Wait waits for the completion of all its goroutines.
But I think that is what we are expecting.
Once it got a "SKIP" command and the executing goroutines receive the cancel signal and stop their work.
And then the stage waits for the canceling of all its analyses before returning a completion status.

Copy link
Member Author

@knanao knanao Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that when we received the skipped command but I wonder how to handle simply whether the all of analyses were already done or not in order to pass through the Wait section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got your point. It would be complex to cancel the goroutine which is handling the command checker once all analyses are completed normally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got your point. It would be complex to cancel the goroutine which is handling the command checker once all analyses are completed normally.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 35.62%. This pull request decreases coverage by -0.07%.

File Function Base Head Diff
pkg/app/piped/executor/analysis/analysis.go Executor.checkSkipped -- 0.00% +0.00%
pkg/app/piped/executor/analysis/analysis.go Executor.Execute 0.00% 0.00% +0.00%

@nghialv
Copy link
Member

nghialv commented Apr 15, 2022

Nice adding!

/lgtm

1 similar comment
@nghialv
Copy link
Member

nghialv commented Apr 15, 2022

Nice adding!

/lgtm

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by khanhtc1202.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants