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

add noise to cron scheduling #20665

Merged
merged 4 commits into from
Dec 21, 2022

Conversation

mfsiega-airbyte
Copy link
Contributor

What

Adds 0-15 minutes of random noise to cron scheduling.

The time is always added, never subtracted. It's restricted to an allow-listed set of workspaces (empty in this PR).

@octavia-squidington-iv octavia-squidington-iv added area/platform issues related to the platform area/worker Related to worker labels Dec 19, 2022
@mfsiega-airbyte mfsiega-airbyte temporarily deployed to more-secrets December 19, 2022 19:35 — with GitHub Actions Inactive
@mfsiega-airbyte mfsiega-airbyte temporarily deployed to more-secrets December 19, 2022 19:36 — with GitHub Actions Inactive
return new ScheduleRetrieverOutput(timeToWait);
} catch (final ParseException e) {
throw (DateTimeException) new DateTimeException(e.getMessage()).initCause(e);
}
}
}

private void addSchedulingNoiseForAllowListedWorkspace(Duration timeToWait, StandardSync standardSync) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this activity used in AWS data plane? Seems it depends on ConfigRepository but data plane can't talk to db directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that this activity runs in the control plane.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(In any case the dependency already exists, so it's a bit unrelated to this PR.)

@supertopher
Copy link
Contributor

this is a truly baller idea @mfsiega-airbyte

nice find

I still think there is a more complete "correct" answer, but this is some pretty solid duct tape

@mfsiega-airbyte
Copy link
Contributor Author

@supertopher I can claim 0% of the idea, that was all @malikdiarra!

@mfsiega-airbyte mfsiega-airbyte temporarily deployed to more-secrets December 19, 2022 20:11 — with GitHub Actions Inactive
@mfsiega-airbyte mfsiega-airbyte temporarily deployed to more-secrets December 19, 2022 20:11 — with GitHub Actions Inactive
@mfsiega-airbyte mfsiega-airbyte temporarily deployed to more-secrets December 20, 2022 15:29 — with GitHub Actions Inactive
@mfsiega-airbyte mfsiega-airbyte temporarily deployed to more-secrets December 20, 2022 15:30 — with GitHub Actions Inactive
@mfsiega-airbyte mfsiega-airbyte temporarily deployed to more-secrets December 20, 2022 18:43 — with GitHub Actions Inactive
@mfsiega-airbyte mfsiega-airbyte temporarily deployed to more-secrets December 20, 2022 18:44 — with GitHub Actions Inactive
@@ -323,6 +325,36 @@ void testCronScheduleMinimumInterval() throws IOException, JsonValidationExcepti
.hasHours(24);
}

@Test
@DisplayName("Test that for specific workspace ids, we add some noise in the cron scheduling")
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

private final static long MS_PER_SECOND = 1000L;
private final static long MIN_CRON_INTERVAL_SECONDS = 60;
private static final Set<UUID> SCHEDULING_NOISE_WORKSPACE_IDS = Set.of(
// Testing
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a TODO to move this to env vars?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hoping we'll get rid of it altogether :)

// We really do want to add some scheduling noise for this connection.
final long minutesToWait = (long) (Math.random() * SCHEDULING_NOISE_CONSTANT);
LOGGER.debug("Adding {} minutes noise to wait", minutesToWait);
// Note: we add an extra second to make the unit tests pass in case `minutesToWait` was 0.
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without it the test fails 1/15 times (because Math.random() * SCHEDULING_NOISE_CONSTANT is <1, so it rounds to zero) which is pretty flaky for a unit test. It's a bit of a hack (hence the comment) - a better thing would be to inject a randomness provider or do some seeding of Math.random but this was a lot simpler.

@mfsiega-airbyte
Copy link
Contributor Author

/approve-and-merge reason="mitigates a paging oncall issue"

@octavia-approvington
Copy link
Contributor

This code is at peace with itself
imagine karate kid approving

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/platform issues related to the platform area/worker Related to worker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants