google-nomulus/release
Lai Jiang 2294c77306 Add a beam pipeline to expand recurring billing event (#1881)
This will replace the ExpandRecurringBillingEventsAction, which has a
couple of issues:

1) The action starts with too many Recurrings that are later filtered out
   because their expanded OneTimes are not actually in scope. This is due
   to the Recurrings not recording its latest expanded event time, and
   therefore many Recurrings that are not yet due for renewal get included
   in the initial query.

2) The action works in sequence, which exacerbated the issue in 1) and
   makes it very slow to run if the window of operation is wider than
   one day, which in turn makes it impossible to run any catch-up
   expansions with any significant gap to fill.

3) The action only expands the recurrence when the billing times because
   due, but most of its logic works on event time, which is 45 days
   before billing time, making the code hard to reason about and
   error-prone.  This has led to b/258822640 where a premature
   optimization intended to fix 1) caused some autorenwals to not be
   expanded correctly when subsequent manual renews within the autorenew
   grace period closed the original recurrece.

As a result, the new pipeline addresses the above issues in the
following way:

1) Update the recurrenceLastExpansion field on the Recurring when a new
   expansion occurs, and narrow down the Recurrings in scope for
   expansion by only looking for the ones that have not been expanded for
   more than a year.

2) Make it a Beam pipeline so expansions can happen in parallel. The
   Recurrings are grouped into batches in order to not overwhelm the
   database with writes for each expansion.

3) Create new expansions when the event time, as opposed to billing
   time, is within the operation window. This streamlines the logic and
   makes it clearer and easier to reason about. This also aligns with
   how other (cancelllable) operations for which there are accompanying
   grace periods are handled, when the corresponding data is always
   speculatively created at event time. Lastly, doing this negates the
   need to check if the expansion has finished running before generating
   the monthly invoices, because the billing events are now created not
   just-in-time, but 45 days in advance.

Note that this PR only adds the pipeline. It does not switch the default
behavior to using the pipeline, which is still done by
ExpandRecurringBillingEventsAction. We will first use this pipeline to
generate missing billing events and domain histories caused by
b/258822640. This also allows us to test it in production, as it
backfills data that will not affect ongoing invoice generation. If
anything goes wrong, we can always delete the generated billing events
and domain histories, based on the unique "reason" in them.

This pipeline can only run after we switch to use SQL sequence based ID
allocation, introduced in #1831.
2023-01-09 17:41:56 -05:00
..
builder Only use GPG2 in tests (#1676) 2022-06-22 11:03:41 -04:00
rollback Change check for root directory during rollback (#1602) 2022-04-25 12:39:16 -04:00
schema-deployer Use credential in secretmanager to deploy schema (#1055) 2021-04-06 09:43:15 -04:00
schema-verifier Verify schema using Cloud Build (#1627) 2022-05-16 16:10:09 -04:00
build_nomulus_for_env.sh Do not delete build cache when building release candidates (#1619) 2022-05-04 12:08:10 -04:00
cloudbuild-delete.yaml Correctly delete all stopped versions except for the most recent 3 (#1511) 2022-02-03 16:04:58 -05:00
cloudbuild-deploy.yaml Remove dos.xml from the configs (#1587) 2022-04-11 15:22:42 -04:00
cloudbuild-dev-resource.yaml Re-enable tests in RC build (#1130) 2021-05-05 13:53:21 -04:00
cloudbuild-kythe.yaml Make Kythe run work with Gradle 7 (#1727) 2022-08-02 13:19:47 -04:00
cloudbuild-nomulus.yaml Add a beam pipeline to expand recurring billing event (#1881) 2023-01-09 17:41:56 -05:00
cloudbuild-proxy.yaml Re-enable tests in RC build (#1130) 2021-05-05 13:53:21 -04:00
cloudbuild-release.yaml Verify schema using Cloud Build (#1627) 2022-05-16 16:10:09 -04:00
cloudbuild-schema-deploy.yaml Use SecretManager for nomulus-tool-cloudbuild cred (#1188) 2021-06-02 09:32:57 -04:00
cloudbuild-schema-verify.yaml Remove bracket in Cloud Build script (#1658) 2022-06-08 13:58:56 -04:00
cloudbuild-sync.yaml Re-enable tests in RC build (#1130) 2021-05-05 13:53:21 -04:00
cloudbuild-tag.yaml Re-enable tests in RC build (#1130) 2021-05-05 13:53:21 -04:00
stage_beam_pipeline.sh Do not delete build cache when building release candidates (#1619) 2022-05-04 12:08:10 -04:00