Skip to content

Follow-up for #7876 - #7914

Merged
clarafu merged 10 commits into
masterfrom
followup-7876
Feb 2, 2022
Merged

clarafu merged 10 commits into
masterfrom
followup-7876

Conversation

@taylorsilva

@taylorsilva taylorsilva commented Jan 4, 2022 •

Copy link
Copy Markdown
Member

Follow-up for #7876

Implement Clara's suggestion. Got rid of the stupid second query! Thanks @clarafu!

TODO:

  • add integration test but my cat wants to play so for another time!

got rid of the stupid second query! Thanks Clara!

Signed-off-by: Taylor Silva <[email protected]>
The last_scheduled column represents the last time that the job was
checked by the scheduler/algorithm, which does not always result in a
new build being made.

The updated query now checks when the latest_completed_build_id for jobs
in a pipeline was last finished.

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

Copy link
Copy Markdown
Member Author

@clarafu made a change to the query to not use last_scheduled

I have an idea for integration tests that I'll add soon.

@taylorsilva

Copy link
Copy Markdown
Member Author

Vague idea of running an integration test that relies on changing postgres's time:

@evanchaoli

Copy link
Copy Markdown
Contributor

@taylorsilva I just read the original PR #7876, can you please add a info log when pauses a pipeline? When user reports any issue, for example, if a user escalates that his pipeline is pauses, the first we do would search for ATC logs for clues.

@taylorsilva

Copy link
Copy Markdown
Member Author

@evanchaoli That's fine, can add that. In that PR though, when this component pauses a pipeline it does show that it was paused by this component:

err = pipeline.Pause("automatic-pipeline-pauser")

So a user will see Paused by automatic-pipeline-pauser <some-date> in the header of their pipeline overview.

We don't even assert anything after running it. Must have been a bad
copy-paste.

Signed-off-by: Taylor Silva <[email protected]>
A user will see on the UI "Paused by automatic-pipeline-pauser
<some-date>"

Signed-off-by: Taylor Silva <[email protected]>
It will log each pipeline that it pauses.
Logs at the info level for successful pipelines.
Logs at the error level if it failes to pause the pipeline.

Signed-off-by: Taylor Silva <[email protected]>
This commit contains a failing test.

I realized that a pipeline that was set but never ran, like a newly set
pipeline, would result in the pipeline being paused. I wrote a test and
made a change to the query to fix that.

I then realized that this change makes it so any pipeline that has a job
with zero builds impossible for the pauser to ever pause the pipeline. I
added a test for this and it is the failing test in this commit. I
currently can't think of a query to get around this issue. Depending on
discussion this test or the first test may be removed.

For the first test I added I see this as kinda an edge case. I feel like
it's extremely unlikely that someone will set a pipeline AND unpause it
at the exact time the pauser runs, which is currently once every 24hrs.
I ran into this when trying to setup an integration test for the pauser
and found that the pauser kept pausing my newly set pipeline before I
could trigger my pipelines job. That's the context on how I found this
issue.

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

taylorsilva commented Jan 10, 2022 •

Copy link
Copy Markdown
Member Author

@clarafu My idea to use libfaketime worked for postgres but doesn't work for golang: wolfcw/libfaketime#195
I can't think of any other way of adjusting the time on the golang side without doing some re-work on the component stuff to fake out time. And even bubbling that up to an integration level feels pretty sus. Any ideas on how to write this integration test?
What I did write up is on this branch: https://github.com/concourse/concourse/tree/followup-7876-integration-test/integration/pauser - (commit: c547b8f)


I did end up finding other issues while building out the integration. From my latest commit:

This commit contains a failing test.

I realized that a pipeline that was set but never ran, like a newly set
pipeline, would result in the pipeline being paused. I wrote a test and
made a change to the query to fix that.

I then realized that this change makes it so any pipeline that has a job
with zero builds impossible for the pauser to ever pause the pipeline. I
added a test for this and it is the failing test in this commit. I
currently can't think of a query to get around this issue. Depending on
discussion this test or the first test may be removed.

For the first test I added I see this as kinda an edge case. I feel like
it's extremely unlikely that someone will set a pipeline AND unpause it
at the exact time the pauser runs, which is currently once every 24hrs.
I ran into this when trying to setup an integration test for the pauser
and found that the pauser kept pausing my newly set pipeline before I
could trigger my pipelines job. That's the context on how I found this
issue.

Any ideas for a query that can pass both tests?

@evanchaoli

Copy link
Copy Markdown
Contributor

So a user will see Paused by automatic-pipeline-pauser <some-date> in the header of their pipeline overview.

That's cool, didn't realize that, while I think a log line will be still helpful for daily OPs.

@clarafu

clarafu commented Jan 11, 2022

Copy link
Copy Markdown
Contributor

Hmm I'm not too familiar with how to fake it out but one thing I can think (but might not be the best if you don't want to add more flags) is to add a flag that allows the user to configure the interval time for this pipeline pauser component. For example, we have the build tracker that runs every 10s on default but you can change that interval time

BuildTrackerInterval time.Duration `long:"build-tracker-interval" default:"10s" description:"Interval on which to run build tracking."`
I'm not sure if you would want to do that though?

@taylorsilva

Copy link
Copy Markdown
Member Author

yeahhh I had that thought earlier too. I think there's a flag for that library that lets me hide it too. That'll probably be the way to go for that.

The pipeline pauser will pause any pipelines that have zero builds
across all active jobs. This is unlikely to be an issue for most users
since the pauser is designed to only run once per day.

Signed-off-by: Taylor Silva <[email protected]>
WHAT A PAIN IT WAS TO WRITE THIS.

So first, getting faketime with postgres was an ADVENTURE. Faketime only
works the first time you bring prostgres up, after that it borks and
time goes back to now instead of whatever future/present time you set.
Therefore the test HAS to start in the past.

Second PIA was that having the db in the past breaks the component
runner because it uses the date from postgres and go's time.Now() to
deteremine if the interval has elapsed. So having postgres in the past
means EVERY component runs every 10s. I had to set the pauser interval
to a crazy high number to ensure it'll only run once on startup and then
not run again.

Also Go doesn't work with faketime so that's why postgres is using it
and not Concourse. Apparently Go does some assembly nonsense to figure
out the time instead of making kernel syscalls

tldr: time is really hard to fake

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

Copy link
Copy Markdown
Member Author

@clarafu I DID IT! This was the biggest PIA test to write 😭 but it works! It passes!

This is good to review and imo good to ship.

Comment thread atc/atccmd/command.go
ResourceWithWebhookCheckingInterval time.Duration `long:"resource-with-webhook-checking-interval" default:"1m" description:"Interval on which to check for new versions of resources that has webhook defined."`
MaxChecksPerSecond int `long:"max-checks-per-second" description:"Maximum number of checks that can be started per second. If not specified, this will be calculated as (# of resources)/(resource checking interval). -1 value will remove this maximum limit of checks per second."`
PausePipelinesAfter int `long:"pause-pipelines-after" default:"0" description:"The number of days after which a pipeline will be automatically paused if none of its jobs have run in more than the given number of days. A value of zero disables this component."`
PipelinePauserInterval time.Duration `long:"pipeline-pauser-interval" default:"24h" hidden:"true" description:"The frequency on which the Pipeline Pauser component will be run to check if any pipelines need to be paused."`

@taylorsilva taylorsilva Jan 21, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this flag is hidden so it doesn't need to be added to the chart and bosh release. Only exposed to make integration testing possible.

@taylorsilva taylorsilva added this to the v7.7.0 milestone Jan 27, 2022
After many days of this being in the back of my mind I thought of a
solution I liked to fix the edge case where someone just set a pipeline
and none of its builds have run.

Previously a pipeline in that state would be paused. This is no longer
the case. I added an additional clause to the query to only get
pipelines that were also last_updated more than 24hrs ago. 24hrs should
be long enough for someone to have created at least one build for their
pipeline.

Also made the integration test simpler, no more goroutine to continously
pause the pipeline. I also realized this was a race condition for any
test if the pauser was configured. This should make the pauser
friendlier to use.

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

Copy link
Copy Markdown
Member Author

Went back to that edge case and fixed it. Added a clause so it only pauses pipelines that were updated more than 24hrs ago.

@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.

Wow thanks for all the work for adding the integration test for this!! :D

Comment thread atc/db/pipeline_pauser.go Resolved
j.next_build_id contains the ID of the currently running build. This ID
is cleared when the build is marked as finished.

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

Copy link
Copy Markdown
Member Author

Good catch @clarafu
Added a test for that case and updated the query to pass the test.

@taylorsilva

Copy link
Copy Markdown
Member Author

Tests are failing with yarn build. Some packages have potentially gone rogue?

@xtremerui

Copy link
Copy Markdown
Contributor

#8029 @taylorsilva

@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.

Thanks for all the work on the tests and fixes!! I just ran some acceptance testing against it and everything works great :D

These were the cases that I covered in my manual testing:

  • pipeline was paused for job that had a build older than configured pause pipelines after interval
  • pipeline was not paused when they had a running/pending build
  • pipeline was not paused when configured within 1 day

@clarafu
clarafu merged commit 21061dd into master Feb 2, 2022
@clarafu
clarafu deleted the followup-7876 branch February 2, 2022 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants