Skip to content

Run checks as builds - #6022

Merged
vito merged 51 commits into
concourse:masterfrom
vito:checks-as-builds
Oct 5, 2020
Merged

vito merged 51 commits into
concourse:masterfrom
vito:checks-as-builds

Conversation

@vito

@vito vito commented Aug 27, 2020 •

Copy link
Copy Markdown
Contributor

What does this PR accomplish?

Feature

This PR removes the checks table and LIDAR checker and runs checks as builds instead. They can now be viewed in the web UI, and fly check-resource and fly check-resource-type will stream the build logs. It's kind of neat!

image

image

TODO

  • Check rate limiting
  • Migration to make builds.id a bigint
  • Restore span context flow so versions can be traced from builds that saved them to builds that were created from them

Changes proposed by this PR:

Side note: I would recommend reading each commit's message.

The following is a broad overview of the changes.

  • Removes resource_types.unique_version_history. This is a breaking change but it should have little to no real-world impact.

    • Motivation: as I was going through the code for constructing resource config scopes, I noticed that this property means that we have to hoist atc.VersionedResourceTypes around. This felt unnecessarily complicated for something that's never really used.
  • Modifies the check step to adopt more of the functionality previously implemented by the LIDAR checker or other components.

    • Enforce rate limiting for periodic checks.
    • No-op if the resource has already been checked within its interval.
    • Use the latest version as the cursor version if no cursor is specified.
    • Update the resource [type] to point to the resource config scope.
    • Update the resource config scope check start/end time.
    • Lock to ensure only one check is running per scope.
    • Set the resource's checking error.
    • Motivation: I want to be able to use the check step more liberally, for example for image resource fetching. By pushing more behavior down into it, we can reuse it more easily while having it "do the right thing."
  • Removes the LIDAR checker, the checks API, the checks table, and the db.Check type.

    • Motivation: in order to use the check step for image fetching it needs to be able to exist in an atc.Plan which also has a get step (for fetching the image) and whatever step needs to run (a task or a resource using a resource type).

      They way the code was structured before, a check step could only be run for a db.Check, and the LIDAR checker could only run if the plan had a single CheckPlan as the only step. (It would actually panic if it was anything but.)

  • Modifies the LIDAR scanner (and check factory) to create a db.Build instead of db.Check.

    • Admittedly it's a little strange that the db.CheckFactory type now creates a db.Build. I think this can be cleaned up in a future refactor which cleans up the job + resource/resource type build scheduling patterns.
    • Motivation: with the check step capable of doing all that on its own, all LIDAR has to do is queue up a build that runs it. The build will be run by the build tracker.
  • Simplifies resource config GC - rather than referencing resource_config_check_sessions, add a time-based "last referenced" GC.

    • Motivation: now that the check step creates its own config + scope, I needed a way to ensure the config doesn't get GC'd before it's assigned to the resource. A simple timestamp seems to do the trick, and allows the config GC query to be simplified a bit - we don't need to reference resource_config_check_sessions anymore, because the "last referenced" timestamp will always be bumped by the check step anyway.
  • Adds support for rendering check steps in the web UI and sending check output to the build event stream.

    • Motivation: 'cause it's cool.
  • Consolidates build tracing/logging data into (db.Build).TracingAttrs and (db.Build).LagerData.

    • Motivation: previously we had many places that would set a build's job name in logging/tracing data. This has always been awkward because one-off builds do not have a job. Now that builds may also be for resources, this seemed like a good time to clean this up and add the resource to the data at the same time.

Notes to reviewer:

Sorry this is so big - this is actually split out from a bigger refactor to replace the special-cased image fetching path with a composition of check and get steps. I found that this was not possible to do because check steps could only be run for a db.Check and not within a db.Build, so here I am!

There are a ton of changes here - I would recommend reviewing commit-by-commit. I spent a lot of time rebasing and amending to make sure each commit can be reviewed in isolation.

Release Note

  • Breaking change: unique_version_history can no longer be configured on resource types. No one seemed to be using it, and it made internal architecture unnecessarily complicated. The need for it should go away entirely as we make progress on the v10 roadmap.
  • Resource check operations, which collect and save versions for pipeline resources, are now run as builds.
    • This is largely an internal architecture refactor, but it also improves UX - check output can now be viewed on the resource page!
  • fly check-resource and fly check-resource-type now stream the checking output to the user, just like fly watch and fly trigger-job.
  • This change includes a migration to convert id column of the builds table and all tables referencing build_id to a bigint. This is unfortunately a slow migration, so please anticipate downtime proportional to the amount of builds in your database.
    • If the migration fails with deadlock detected, shut down the other web nodes first.
    • Our large-ish scale test environment took about an hour.

Contributor Checklist

Reviewer Checklist

  • Code reviewed
  • Tests reviewed
  • Documentation reviewed
  • Release notes reviewed
  • PR acceptance performed
  • New config flags added? Ensure that they are added to the
    BOSH and
    Helm packaging; otherwise, ignored for
    the integration
    tests

    (for example, if they are Garden configs that are not displayed in the
    --help text).

@vito
vito force-pushed the checks-as-builds branch 3 times, most recently from 243a13f to 07ad3c5 Compare August 28, 2020 00:12
@vito
vito force-pushed the checks-as-builds branch 5 times, most recently from f6f7beb to 9ff72a8 Compare September 12, 2020 23:34
@vito
vito marked this pull request as ready for review September 12, 2020 23:38
@xtreme-sameer-vohra xtreme-sameer-vohra self-assigned this Sep 15, 2020
aoldershaw added a commit that referenced this pull request Sep 21, 2020
Previously, we were constructing step delegates and passing them into
the step directly. This commit instead passes in a step delegate
factory, and the steps construct the step delegate at runtime.

p.s. there was a delegate factory that existed before, but it was kinda
useless - #6022 got rid of it entirely.

This may seem like a useless change, and for the time being it is. The
motivation for this is to allow the step delegate to be constructed
using information that can only exist at runtime.

In particular, the step delegates currently require vars.BuildVariables
in order to:
1. Expose creds and local variables to the steps
2. Perform secret redaction

In coming commits, I plan to extend the `RunState` that's passed into
every `Step` to also deal with variables, rather than relying on a step
delegate to expose this. This are a few motivations for this:
1. Allow things to be interpolated more easily - a big driving force
   behind this change is to make it possible to interpolate most
   everything in a build plan. This could've been done by injecting a
   step delegate into every step type, but that felt awkward
2. Make the across step construction less awkward - since step delegates
   had to be constructed statically with their local vars at build time,
   we needed some tricky logic in the builder to figure out what to run
   in parallel. This proved to be difficult to test, leading to a lack
   of test coverage.
3. Opens the door for the across step to run with a dynamic list of
   values. This is definitely down the line, and requires other changes
   to make it work, but requiring the variables to be set at build time
   makes this impossible. It also would mean you can't interpolate
   individual values (i.e. not the full list), which *is* something that
   should be possible with the static across step

p.s. this commit removes some test coverage for the across step around
properly setting the variable scopes. I'll add this back in a later
commit

Signed-off-by: Aidan Oldershaw <[email protected]>
vito added a commit to concourse/ci that referenced this pull request Sep 23, 2020
just grep for 'succeeded', which should continue to work with
concourse/concourse#6022

Signed-off-by: Alex Suraci <[email protected]>
vito added 10 commits September 23, 2020 10:08
this seems to unnecessarily complicate the codebase, and i don't think
many people use it or even know it exists or what it's for.

this field makes it so that, with global resources enabled, resources
using the type will have their own unique history, rather than being
global.

this is really just to support the time resource, so that all jobs don't
run on the same interval. but the time resource is built in, not a
custom type, so let's just reserve this behavior for built-in resource
types only until we eventually remove it.

note: i did a code search to see if i could find anyone using this in
the wild, and there was only result, and it was for the cron resource,
which doesn't benefit from unique history anyway (unlike the time
resource).

Signed-off-by: Alex Suraci <[email protected]>
checks are turning into builds, so clients can use the builds api to
monitor checks instead.

remove Check and AllCheckables methods from CheckFactory, since this was
the only place they were used

Signed-off-by: Alex Suraci <[email protected]>
this will no longer be necessary, as checks will be queued as builds,
and thus go through the regular old build tracker

removing this so that the StartedChecks method along with the engine
checking code can be removed.

note: will need to add rate limiting to the build tracker to preserve
rate limiting behavior

Signed-off-by: Alex Suraci <[email protected]>
previously the check step was completely reliant on the delegate and
metadata to figure out the resource config and scope to save to.

now the check step constructs its own config and scope at runtime based
on the evaluated config. this makes the check step more independent, and
makes it easier to have multiple check steps in one build plan;
previously it would only save to the scope associated with the db.Check,
but now that it's decoupled it should easier to run multiple in a
db.Build.

Signed-off-by: Alex Suraci <[email protected]>
* switch everything from db.Check to db.Build now that it's not used in
  the delegate.
* when building a plan, check for .Check field in plan and construct a
  check step - previously this was only respected when constructing a
  step for a db.Check.

Signed-off-by: Alex Suraci <[email protected]>
as long as we're still using VersionedResourceTypes, we need to make
sure that the resource_config_id column gets updated on resource_types.

right now this happens in TryCreateCheck, which is technically fine as
long as we're queuing up checks for resource types too, but that's not
the plan forever: the goal is to push all the image checking and
fetching into the build plan, including resource type images, so that
everything works the same way.

in the future, there will be builds for resources, but not resource
types. builds will check-and-fetch their types as needed, whether
they're a build for a resource check or a build for a job.

the UpdateResourceType field should be able to go away once this is all
farther along - in particular, once we're able to remove
VersionedResourceTypes by having steps refer to previous 'check' and/or
'get' steps which determine their type version and image.

Signed-off-by: Alex Suraci <[email protected]>
as-is, this will be pretty wasteful: it'll end up queueing a bunch of
redundant checks for resources with the same config/scope, and they'll
all run their checks, pretty much undoing the benefits of global
resources.

the next step is to mitigate this by having the 'check' step regulate
itself by skipping the check if its interval has not elapsed, while
locking to prevent concurrent checks of the same scope.

with that mitigation, there will still be the overhead of queueing and
builds for all resources for each scope to check, but at least the build
will do something useful: its check step will update the config/scope on
the resource or resource type.

Signed-off-by: Alex Suraci <[email protected]>
* if the interval has not elapsed since the last check end time, skip
  the check
* if the build is manually triggered, ignore the interval and run
  immediately

note: the method is called WaitAndRun because this is where we can add
back the rate limiting, which used to be done in the resource checker.

interestingly, this also lets us consider having it wait until the
interval elapses. then there'd be two kinds of rate limiting: limit each
scope to once every interval, and limit all checking overall just so
things aren't so spikey.

one neat thing that might enable in the future is to have much more
responsive webhook handling: rather than webhooks triggering builds,
they could just wake up a goroutine in a build that's already running.
that shoud have much lower latency - great for snappy webhook
responsiveness.

Signed-off-by: Alex Suraci <[email protected]>
vito added 7 commits October 3, 2020 15:10
this could be avoided by showing the resource's check build output
and/or status in the UI instead, which would also allow the resource to
still be pointed to its old scope, so at least the version history
doesn't get wiped out.

Signed-off-by: Alex Suraci <[email protected]>
also remove no-longer-used secretManager field and AcquireScanningLock
method, which was replaced by the generic component locking system.

Signed-off-by: Alex Suraci <[email protected]>
the checker no longer exists! (this commit also removes the now-unused
component const.)

note that this notification is no longer needed because
(db.Build).Start, called by TryCreateCheck, already notifies the build
tracker. this can be verified by the fact that `fly check-resource` runs
pretty much immediately even while this notification was going nowhere.

slight behavior difference from before this refactor: we now send N
notifications instead of 1 per scanner tick, but we'll see if that's
problematic. (guessing not.)

Signed-off-by: Alex Suraci <[email protected]>
no longer used; checks are builds now

Signed-off-by: Alex Suraci <[email protected]>

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

I can't find anything wrong with it - seems like a pretty awesome cleanup, and I really like the new streaming check output and the implications this brings for running checks in regular build plans

@vito
vito merged commit 37c4aeb into concourse:master Oct 5, 2020
@vito

vito commented Oct 5, 2020

Copy link
Copy Markdown
Contributor Author

@aoldershaw thanks for the feedback + review!

@vito
vito deleted the checks-as-builds branch October 5, 2020 15:02
muntac added a commit to concourse/concourse-bosh-release that referenced this pull request Oct 5, 2020
@vito vito mentioned this pull request Oct 5, 2020
2 of 11 tasks
vito added a commit to vito/concourse that referenced this pull request Oct 6, 2020
this ain't a thing anymore with concourse#6022

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit that referenced this pull request Oct 6, 2020
this ain't a thing anymore with #6022

Signed-off-by: Alex Suraci <[email protected]>
@vito vito mentioned this pull request Oct 7, 2020
3 of 11 tasks
aoldershaw added a commit that referenced this pull request Oct 26, 2020
With #6022, we delete the previous build for a resource/resource type
check when we create a new one. However, since there's no foreign key
contraint on build_events.build_id, the build events never actually get
deleted.

We actually don't want a cascading delete on build_events, though, since
deleting pipelines would become super slow (currently, we're able to
just truncate/drop the pipeline_build_events table, but if deletes
cascaded, we'd end up performing a ton of row deletions, which is much
slower in postgres). So instead, let's just delete the build events when
we delete the corresponding build.

Signed-off-by: Aidan Oldershaw <[email protected]>
aoldershaw added a commit to aoldershaw/docs that referenced this pull request May 17, 2021
it was removed in concourse/concourse#6022

Signed-off-by: Aidan Oldershaw <[email protected]>
kcbimonte pushed a commit to Aviator-Labs/docs-ci that referenced this pull request Sep 26, 2026
it was removed in concourse/concourse#6022

Signed-off-by: Aidan Oldershaw <[email protected]>
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