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

GH-35 randomize validation time #73

Merged
merged 1 commit into from
Apr 15, 2024
Merged

GH-35 randomize validation time #73

merged 1 commit into from
Apr 15, 2024

Conversation

maksymvavilov
Copy link
Contributor

Randomize validation reconcilation delays

@maksymvavilov maksymvavilov linked an issue Apr 10, 2024 that may be closed by this pull request
5 tasks
@maksymvavilov maksymvavilov force-pushed the GH-35 branch 3 times, most recently from 051c334 to 91c61da Compare April 11, 2024 14:34
@maksymvavilov maksymvavilov marked this pull request as ready for review April 11, 2024 14:51
@maksymvavilov maksymvavilov changed the title [WIP] GH-35 GH-35 Apr 11, 2024
@maksymvavilov maksymvavilov changed the title GH-35 GH-35 randomize validation time Apr 12, 2024
@@ -69,6 +70,13 @@ func (r *DNSRecordReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
logger := log.FromContext(ctx)

reconcileStart = metav1.Now()

// randomize validation reconcile delay
seconds := float64(validationRequeueTime.Milliseconds())
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is this var name a bit misleading? should it be milliseconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed

seconds := float64(validationRequeueTime.Milliseconds())
validationRequeueTime = time.Millisecond * time.Duration(rand.Int63nRange(
int64(seconds*0.9),
int64(seconds*1.1)))
Copy link
Contributor

Choose a reason for hiding this comment

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

ok so the interval will be between 90 and 110 % of the validationRequeueTime? wondering if we should increase the possible range a bit. Like 50-150% . Anyway just a thought

Copy link
Contributor

Choose a reason for hiding this comment

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

possibly worth isolating into a function and adding a simple unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

increased variance to 50% and isolated into a separate function.

Not sure though how to reliably test the randomization function: we could have a test just ensuring that we get a valid value from this (but given how the code works we always will have a valid time.Duration value out of this) and we already testing for "usable" duration in the integration suite (if it to randomize seconds into minutes we will timeout out of the integration suite). The suggested way to test randomness is through a lot of iterations to build up a statistically significant amount of data - that doesn't sound like something worth doing.
In any case - I put together a tiny test that should be what you had in mind

Went through the package and there are a few functions that could use unit tests as well. If we do this - maybe better to move our integration suite into a separate package and only keep filename_test.go for the unit suite? I can create a issue for "better days" to reorganize tests in the DNS Operator if that sounds cool 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah not huge value here, I guess we could do a number of iterations and ensure the value is within the expected range?

Copy link
Contributor

@maleck13 maleck13 left a comment

Choose a reason for hiding this comment

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

looks ok to merge. just a couple small things to possibly improve

@maleck13
Copy link
Contributor

/lgtm

@maksymvavilov maksymvavilov force-pushed the GH-35 branch 2 times, most recently from 9b59ca6 to 0e5fd39 Compare April 15, 2024 10:02
duration time.Duration
}{
{
name: "returns valid duration in range",
Copy link
Contributor

Choose a reason for hiding this comment

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

yep this is fine perhaps forcing it to do a loop and a set number of iterations testing each is within the range?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦 yep, that is smart. Done

@maleck13 maleck13 added this pull request to the merge queue Apr 15, 2024
Merged via the queue into main with commit b5a7642 Apr 15, 2024
9 checks passed
@maksymvavilov maksymvavilov deleted the GH-35 branch May 23, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-queue DNS Record whenever a write to the Cloud Provider occurs
2 participants