Skip to content

Automatically pause pipelines - #7876

Merged
taylorsilva merged 3 commits into
masterfrom
auto-pause-pipelines
Dec 29, 2021
Merged

taylorsilva merged 3 commits into
masterfrom
auto-pause-pipelines

Conversation

@taylorsilva

@taylorsilva taylorsilva commented Dec 9, 2021 •

Copy link
Copy Markdown
Member

Changes proposed by this PR

Adds a component that runs once every 24hrs and checks for any pipelines that
haven't run in more than X days. Setting the days to zero disables the component.

Thought of adding this feature after reading this discord message:
https://discord.com/channels/219899946617274369/413771057686773770/912836796348497932
image

Where the user created some scripts to do this for their Concourse instance.
Their reported paused/unpaused ratio was at 50%. This made me think there's a
lot of Concourse pipelines out there doing resource checks when they could be
doing nothing and saving compute power. Thus this feature, to bring it to all
Concourse users.

The database already has all the info needed to find pipelines to pause, so
users can get a benefit from this feature immediately as it will retroactively
pause pipelines on its first run.

Release Note

  • Adds a new component that will automatically pause pipelines that have not run in more than the configured number of days. The number of days can be configured with CONCOURSE_PAUSE_PIPELINES_AFTER. A value of zero (the default) disables this component. On first run it will retroactively pause pipelines that already fall out of the given day range.
    • Exceptions: Pipelines that have no builds falling within the day range but have been updated in <24hrs will not be automatically paused. This is to cover the case where someone sets a new pipeline and hasn't run any jobs for it yet.

@taylorsilva
taylorsilva requested a review from a team December 9, 2021 22:26
@maxknee

maxknee commented Dec 10, 2021

Copy link
Copy Markdown

Oh this will be great to have, we do this manually.

@taylorsilva

taylorsilva commented Dec 14, 2021 •

Copy link
Copy Markdown
Member Author

testflight is flaky af 😡


EDIT: tests were not flakey, human is stupid and introduced bug 🙃

@xtremerui

Copy link
Copy Markdown
Contributor

the runc bump in our main CI caused the failure. Now it is pinned to previous version. Once dev-image is rebuilt it should fix PR pipelines.

pauses pipelines that have had no builds run in greater than some number
of days. Pipelines this component pauses will be marked as paused by
"automatic-pipeline-pauser" which will be visible from the web UI

Signed-off-by: Taylor Silva <[email protected]>
Calls the db pauser. Short circuts if the days is set to zero.
Essentially turns the feature off.

Signed-off-by: Taylor Silva <[email protected]>
The pauser only needs to run once a day so its interal is 24h

Signed-off-by: Taylor Silva <[email protected]>

@xtremerui xtremerui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@taylorsilva
taylorsilva merged commit 32105fc into master Dec 29, 2021
@taylorsilva
taylorsilva deleted the auto-pause-pipelines branch December 29, 2021 19:00
taylorsilva added a commit to concourse/concourse-bosh-release that referenced this pull request Dec 30, 2021
taylorsilva added a commit to concourse/concourse-chart that referenced this pull request Dec 30, 2021
@xtremerui xtremerui added this to the v7.7.0 milestone Jan 4, 2022

@clarafu clarafu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@taylorsilva Sorry for my super late review, had to finish up some bug fix for the 7.4.x series! I know it is merged already but I had one thing I wanted to run by you!

Comment thread atc/db/pipeline_pauser.go Resolved
Comment thread atc/db/pipeline_pauser.go Resolved
@taylorsilva taylorsilva mentioned this pull request Jan 4, 2022
1 task done
@xtremerui

Copy link
Copy Markdown
Contributor

@taylorsilva would you be able to also add CONCOURSE_PAUSE_PIPELINES_AFTER to bosh and helm release?

@taylorsilva

Copy link
Copy Markdown
Member Author

@xtremerui already did. The PRs should be referenced somewhere above.

@clarafu

clarafu commented Jan 5, 2022 •

Copy link
Copy Markdown
Contributor

Hmm @xtremerui @taylorsilva I'm curious to know if you have tried running this manually and saw it pause pipelines that have not run in the configured amount of days? I'm thinking that using last_scheduled on the job might not work because the last_scheduled column is updated every time the job scheduler component runs for this job. Even if the scheduler has run for the job, that does not guarantee that a build was created for it. That means the last_scheduled can be updated constantly without any builds actually being created and ran for the job. Sorry maybe the last_scheduled column is named confusingly, I think what it means by last_scheduled is that this was the last time the scheduler ran for this job rather than the last time a build was scheduled for this job!

I think this could also benefit from some integration tests in the integration test suite!

@taylorsilva

Copy link
Copy Markdown
Member Author

No, did not manually test this.

I get what you're saying, that last_scheduled does not mean a build ran, but I also don't understand when that would be there case where the job was scheduled but a build was not created? I'd assume something else is going horribly wrong if jobs are being scheduled and no build is actually being made.

Okay diving into the code more cause I don't know the scheduler stuff very well, and this bit interests me:

jobInputs, err := job.AlgorithmInputs()
if err != nil {
return false, fmt.Errorf("inputs: %w", err)
}
inputMapping, resolved, runAgain, err := s.Algorithm.Compute(ctx, job, jobInputs)
if err != nil {
return false, fmt.Errorf("compute inputs: %w", err)
}
if runAgain {
err = job.RequestSchedule()
if err != nil {
return false, fmt.Errorf("request schedule: %w", err)
}
}
err = job.SaveNextInputMapping(inputMapping, resolved)
if err != nil {
return false, fmt.Errorf("save next input mapping: %w", err)
}
err = s.ensurePendingBuildExists(ctx, logger, job, jobInputs)
if err != nil {
return false, err
}

These are various cases where the scheduler/algorithm can error and return a bool that indicates whether a retry is needed (true) or not (false). I guess these are the cases you are talking about?

And then diving over to

func (j *jobFactory) JobsToSchedule() (SchedulerJobs, error) {
tx, err := j.conn.Begin()
if err != nil {
return nil, err
}
defer tx.Rollback()
rows, err := jobsQuery.
Where(sq.Expr("j.schedule_requested > j.last_scheduled")).

where yes, this column does not look like the data I want! I'll make changes in #7914

@clarafu

clarafu commented Jan 5, 2022

Copy link
Copy Markdown
Contributor

Oh the cases where the scheduler was run and a build is not created is pretty common! For example, it could be when a resource version is disabled and it will trigger a request to schedule the job.

err = requestScheduleForJobsUsingResource(tx, r.id)
if err != nil {
return err
}

This disabled resource version can be a super old one and when the scheduler runs, it determines the same set of inputs as it did in the latest build and therefore does not create a new build. Here lists all the cases where a request to schedule will be done https://concourse-ci.org/scheduler.html#scheduling-on-demand.

One way I can think of to get this to work is we might want to have this pipeline pausing component determine when it needs to be paused based off the creation time of the latest build of its jobs?

clarafu added a commit that referenced this pull request Feb 2, 2022
@clarafu clarafu changed the title atc: Automatically pause pipelines Automatically pause pipelines Mar 8, 2022
wanderanimrod pushed a commit to wanderanimrod/concourse-chart that referenced this pull request May 12, 2022
wanderanimrod pushed a commit to wanderanimrod/concourse-chart that referenced this pull request May 20, 2022
@taylorsilva taylorsilva mentioned this pull request Apr 22, 2026
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.

4 participants