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

Refactor parse.Run to use an event funnel #1272

Merged

Conversation

karlkfi
Copy link
Contributor

@karlkfi karlkfi commented Jun 13, 2024

Replace the timers in parse.Run with an set of event Producers that
send events into a Funnel which synchronizes them for an EventHandler
which executes the RunFunc as needed for specific event types.

The PublishingGroupBuilder takes the timer periods and generates
Publishers, one for each type of event. Then the event Funnel starts
all the Publishers and runs a select loop that calls the Publisher's
Publish method when that event is received. The Publish method then
calls the Subscriber.Handle method.

Motivation:

  • Fixes a bug that was causing unnecessary back-to-back sync
    attempts.
  • Validates retry backoff behavior.
  • Validates sync attempt scheduling behavior.
  • Hides hard to test delay timers with an easier to test/read event-based scheduling system.
  • Unblocks future refactoring into a control-loop scheduling system.

Dependencies:

Possible future cleanup:

  • Drive namespace events with a channel from the namespace controller
  • Drive retry events with a channel so they only ever happen when a retry is needed, instead of checking inside the event whether a retry is needed.
  • Don't start retry events until a run attempt has errored
  • Combine the SyncEventType and SyncWithReimportEventType, and just use a lastImportTime check to decide whether to re-import or not.

pkg/parse/run_test.go Outdated Show resolved Hide resolved
pkg/parse/run.go Outdated Show resolved Hide resolved
@karlkfi karlkfi force-pushed the karl-backoff-test branch 2 times, most recently from 92bbc57 to f6887f9 Compare June 13, 2024 20:32
@karlkfi karlkfi force-pushed the karl-backoff-test branch 4 times, most recently from c00a18c to cad7935 Compare June 28, 2024 02:26
@karlkfi
Copy link
Contributor Author

karlkfi commented Jun 28, 2024

/retest

@karlkfi
Copy link
Contributor Author

karlkfi commented Jul 1, 2024

/retest

1 similar comment
@karlkfi
Copy link
Contributor Author

karlkfi commented Jul 2, 2024

/retest

@karlkfi karlkfi force-pushed the karl-backoff-test branch 3 times, most recently from dfe215c to 6461a8f Compare August 6, 2024 20:19
@google-oss-prow google-oss-prow bot added size/XXL and removed size/XL labels Aug 6, 2024
@karlkfi karlkfi changed the title [WIP] Refactor parse.Run to use an event generator [WIP] Refactor parse.Run to use an event scheduler Aug 6, 2024
@karlkfi karlkfi changed the title [WIP] Refactor parse.Run to use an event scheduler [WIP] Refactor parse.Run to use event schedulers Aug 6, 2024
@karlkfi karlkfi force-pushed the karl-backoff-test branch 2 times, most recently from 222ec76 to f5f428e Compare August 6, 2024 20:52
pkg/parse/events/events.go Outdated Show resolved Hide resolved
pkg/parse/run.go Outdated Show resolved Hide resolved
SyncPeriod: opts.PollingPeriod,
FullSyncPeriod: opts.ResyncPeriod,
StatusUpdatePeriod: opts.StatusUpdatePeriod,
// TODO: Shouldn't this use opts.RetryPeriod as the initial duration?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems like an existing bug. The Backoff wasn't being built with the RetryPeriod option.

@karlkfi karlkfi force-pushed the karl-backoff-test branch 3 times, most recently from bd2d7bd to 1f9da0a Compare August 16, 2024 23:09
@karlkfi karlkfi changed the title [WIP] Refactor parse.Run to use event schedulers Refactor parse.Run to use an event funnel Aug 16, 2024
@karlkfi karlkfi removed the request for review from tiffanny29631 August 16, 2024 23:11
@karlkfi
Copy link
Contributor Author

karlkfi commented Aug 16, 2024

/cc @Camila-B

Copy link

@karlkfi: GitHub didn't allow me to request PR reviews from the following users: Camila-B.

Note that only GoogleContainerTools members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @Camila-B

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

pkg/parse/run.go Outdated Show resolved Hide resolved
pkg/parse/run.go Outdated Show resolved Hide resolved
pkg/parse/run.go Outdated Show resolved Hide resolved
pkg/parse/events/events.go Outdated Show resolved Hide resolved
pkg/parse/run.go Outdated Show resolved Hide resolved
pkg/reconciler/reconciler.go Outdated Show resolved Hide resolved
pkg/parse/events/sources.go Outdated Show resolved Hide resolved
pkg/parse/run.go Outdated Show resolved Hide resolved
@karlkfi karlkfi force-pushed the karl-backoff-test branch 2 times, most recently from 8bbb464 to f7b9406 Compare September 19, 2024 21:16
pkg/parse/events/funnel_test.go Outdated Show resolved Hide resolved
pkg/parse/events/publisher.go Outdated Show resolved Hide resolved
pkg/parse/events/publisher.go Outdated Show resolved Hide resolved
@karlkfi karlkfi force-pushed the karl-backoff-test branch 2 times, most recently from 852cc5a to 2716f78 Compare September 20, 2024 21:03
pkg/parse/events/doc.go Outdated Show resolved Hide resolved
pkg/parse/events/builder.go Show resolved Hide resolved
pkg/parse/events/doc.go Outdated Show resolved Hide resolved
@karlkfi karlkfi force-pushed the karl-backoff-test branch 2 times, most recently from 997373e to 55cb26e Compare September 23, 2024 18:13
Copy link
Contributor

@nan-yu nan-yu left a comment

Choose a reason for hiding this comment

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

One nit comment. Otherwise LGTM

pkg/parse/events/funnel_test.go Outdated Show resolved Hide resolved
pkg/parse/events/builder.go Show resolved Hide resolved
Replace the timers in parse.Run with an set of event Producers that
send events into a Funnel which synchronizes them for an EventHandler
which executes the RunFunc as needed for specific event types.

The PublishingGroupBuilder takes the timer periods and generates
Publishers, one for each type of event. Then the event Funnel starts
all the Publishers and runs a select loop that calls the Publisher's
Publish method when that event is received. The Publish method then
calls the Subscriber.Handle method.

Motivation:
- Allows for testing retry backoff in the event funnel, separate
  from the parser logic, using a FakeClock.
- This should make parse.Run look a little more like a controller's
  Reconcile loop from controller-runtime, which paves the way for
  further refactoring.
- This is not an ideal solution yet, just a next step towards
  something that's easier to test and easier to change.
Copy link
Contributor

@nan-yu nan-yu left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nan-yu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit 9780d88 into GoogleContainerTools:main Sep 23, 2024
6 checks passed
@karlkfi karlkfi deleted the karl-backoff-test branch September 23, 2024 21:15
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.

3 participants