Merge pull request #8381 from Caprowni/master

Add resource type check interval
This commit is contained in:
Taylor Silva 2024-04-04 09:33:58 -04:00 committed by GitHub
commit 864bc19563
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 23 additions and 3 deletions

View File

@ -148,6 +148,7 @@ type RunCommand struct {
GlobalResourceCheckTimeout time.Duration `long:"global-resource-check-timeout" default:"1h" description:"Time limit on checking for new versions of resources."`
ResourceCheckingInterval time.Duration `long:"resource-checking-interval" default:"1m" description:"Interval on which to check for new versions of resources."`
ResourceTypeCheckingInterval time.Duration `long:"resource-type-checking-interval" default:"1m" description:"Interval on which to check for new versions of resource types."`
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."`
@ -539,6 +540,7 @@ func (cmd *RunCommand) Runner(positionalArguments []string) (ifrit.Runner, error
atc.EnableResourceCausality = cmd.FeatureFlags.EnableResourceCausality
atc.DefaultCheckInterval = cmd.ResourceCheckingInterval
atc.DefaultWebhookInterval = cmd.ResourceWithWebhookCheckingInterval
atc.DefaultResourceTypeInterval = cmd.ResourceTypeCheckingInterval
if cmd.BaseResourceTypeDefaults.Path() != "" {
content, err := os.ReadFile(cmd.BaseResourceTypeDefaults.Path())
@ -1104,6 +1106,15 @@ func (cmd *RunCommand) backendComponents(
cmd.ResourceWithWebhookCheckingInterval = cmd.ResourceCheckingInterval
}
if cmd.ResourceTypeCheckingInterval < cmd.ResourceCheckingInterval {
logger.Info("update-resource-type-checking-interval",
lager.Data{
"oldValue": cmd.ResourceTypeCheckingInterval,
"newValue": cmd.ResourceCheckingInterval,
})
cmd.ResourceTypeCheckingInterval = cmd.ResourceCheckingInterval
}
components := []RunnableComponent{
{
Component: atc.Component{

View File

@ -1875,6 +1875,7 @@ var factoryTests = []PlannerTest{
func (test PlannerTest) Run(s *PlannerSuite) {
atc.DefaultCheckInterval = 1 * time.Minute
atc.DefaultWebhookInterval = 2 * time.Minute
atc.DefaultResourceTypeInterval = 3 * time.Minute
factory := builds.NewPlanner(atc.NewPlanFactory(0))
@ -1913,6 +1914,7 @@ func (test PlannerTest) Run(s *PlannerSuite) {
atc.DefaultCheckInterval = 0
atc.DefaultWebhookInterval = 0
atc.DefaultResourceTypeInterval = 0
}
func (s *PlannerSuite) TestFactory() {

View File

@ -81,7 +81,6 @@ func NewCheckFactory(
func (c *checkFactory) TryCreateCheck(ctx context.Context, checkable Checkable, resourceTypes ResourceTypes, from atc.Version, manuallyTriggered bool, skipIntervalRecursively bool, toDB bool) (Build, bool, error) {
logger := lagerctx.FromContext(ctx)
sourceDefaults := atc.Source{}
parentType, found := resourceTypes.Parent(checkable)
if found {
@ -105,6 +104,10 @@ func (c *checkFactory) TryCreateCheck(ctx context.Context, checkable Checkable,
interval = *checkable.CheckEvery()
}
if _, ok := checkable.(ResourceType); ok && checkable.CheckEvery() == nil {
interval.Interval = atc.DefaultResourceTypeInterval
}
skipInterval := manuallyTriggered
if !skipInterval && time.Now().Before(checkable.LastCheckEndTime().Add(interval.Interval)) {
// skip creating the check if its interval hasn't elapsed yet

View File

@ -24,11 +24,13 @@ var _ = Describe("CheckFactory", func() {
BeforeEach(func() {
atc.DefaultCheckInterval = defaultCheckInterval
atc.DefaultWebhookInterval = defaultWebhookCheckInterval
atc.DefaultResourceTypeInterval = defaultResourceTypeInterval
})
AfterEach(func() {
atc.DefaultCheckInterval = 0
atc.DefaultWebhookInterval = 0
atc.DefaultResourceTypeInterval = 0
})
Describe("TryCreateCheck", func() {
@ -319,7 +321,7 @@ var _ = Describe("CheckFactory", func() {
Expect(fakeResourceType.CheckPlanCallCount()).To(Equal(1))
_, types, version, interval, defaults, _, _ := fakeResourceType.CheckPlanArgsForCall(0)
Expect(version).To(Equal(atc.Version{"from": "version"}))
Expect(interval.Interval).To(Equal(defaultCheckInterval))
Expect(interval.Interval).To(Equal(defaultResourceTypeInterval))
Expect(types).To(Equal(rts))
Expect(defaults).To(Equal(atc.Source{}))
})
@ -348,7 +350,7 @@ var _ = Describe("CheckFactory", func() {
Expect(fakeResourceType.CheckPlanCallCount()).To(Equal(1))
_, types, version, interval, defaults, _, _ := fakeResourceType.CheckPlanArgsForCall(0)
Expect(version).To(Equal(atc.Version{"from": "version"}))
Expect(interval.Interval).To(Equal(defaultCheckInterval))
Expect(interval.Interval).To(Equal(defaultResourceTypeInterval))
Expect(types).To(Equal(rts))
Expect(defaults).To(Equal(atc.Source{}))
})

View File

@ -76,6 +76,7 @@ var (
defaultCheckInterval = time.Minute
defaultWebhookCheckInterval = time.Hour
defaultResourceTypeInterval = time.Hour
defaultCheckTimeout = 5 * time.Minute
defaultBuildCreatedBy string

View File

@ -5,6 +5,7 @@ import "time"
var (
DefaultCheckInterval time.Duration
DefaultWebhookInterval time.Duration
DefaultResourceTypeInterval time.Duration
)
type CheckRequestBody struct {