Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

rollout: Roll forward only if enough time passed #57

Merged
merged 4 commits into from
Aug 10, 2020
Merged

rollout: Roll forward only if enough time passed #57

merged 4 commits into from
Aug 10, 2020

Conversation

gvso
Copy link
Contributor

@gvso gvso commented Aug 6, 2020

This adds a new annotation containing the last time the traffic to the candidate was increased. Using the configuration for minimum time between roll forwards, it decides if it can continue rolling the candidate forward.

cmd/operator/main.go Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/config/config_test.go Outdated Show resolved Hide resolved
Comment on lines +215 to +227
// TODO (gvso): Refactor this and other methods to return only a traffic object.
// Then, rename this to trafficBasedOnDiagnosis.
// Also, move those traffic-config-related methods to traffic.go file.
Copy link
Contributor Author

@gvso gvso Aug 6, 2020

Choose a reason for hiding this comment

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

Instead of updating the service in PrepareRollForward and PrepareRollForward, which are deep in the call chain, we can just return the traffic config and make the update in, yeah, UpdateService.

We need to change the first two method's name and move them (an their helpers) to a new file since this one is getting very big.

Any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the TODO above is a good idea. Though I'm fine with it as it is right now.

pkg/config/config.go Outdated Show resolved Hide resolved
StableRevisionAnnotation = "rollout.cloud.run/stableRevision"
CandidateRevisionAnnotation = "rollout.cloud.run/candidateRevision"
LastFailedCandidateRevisionAnnotation = "rollout.cloud.run/lastFailedCandidateRevision"
LastRollForwardAnnotation = "rollout.cloud.run/lastRollForward"
Copy link
Contributor

Choose a reason for hiding this comment

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

lastRollout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

if err != nil {
return nil, errors.Wrap(err, "failed to update service after diagnosis")
}
if svc == nil {
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 comment inside this if about when this happens

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

if r.shouldRollback {
svc.Metadata.Annotations[LastFailedCandidateRevisionAnnotation] = candidate
delete(svc.Metadata.Annotations, LastRollForwardAnnotation)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd keep it (for the records)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

return svc
}

svc.Metadata.Annotations[StableRevisionAnnotation] = stable
svc.Metadata.Annotations[CandidateRevisionAnnotation] = candidate
svc.Metadata.Annotations[LastRollForwardAnnotation] = r.time.Now().Format(time.RFC3339)
Copy link
Contributor

Choose a reason for hiding this comment

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

init once now := r.time.Now().Format(time.RFC3339)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

// shouldRollForward determines if enough time has passed since last roll
// forward.
func (r *Rollout) shouldRollForward(lastRollForwardStr string, timeBetweenRollForwards int) (bool, error) {
lastRollForward, err := time.Parse(time.RFC3339, lastRollForwardStr)
Copy link
Contributor

@ahmetb ahmetb Aug 6, 2020

Choose a reason for hiding this comment

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

if annotation is empty, return a different error saying X annotation is missing

need to think about the case where it bricks here forever.

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 added a TODO for this

@@ -318,6 +364,23 @@ func (r *Rollout) diagnoseCandidate(candidate string, healthCriteria []config.Me
return d, errors.Wrap(err, "failed to diagnose candidate's health")
}

// shouldRollForward determines if enough time has passed since last roll
// forward.
func (r *Rollout) shouldRollForward(lastRollForwardStr string, timeBetweenRollForwards int) (bool, error) {
Copy link
Contributor

@ahmetb ahmetb Aug 6, 2020

Choose a reason for hiding this comment

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

shouldRollForwardisTimeElapsed

roll forward → rollout

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 renamed it to hasEnoughTimeElapsed. Is it fine?

Comment on lines 376 to 377
r.log.Debugf("last roll forward: %v", lastRollForward)
r.log.Debugf("current time: %v", currentTime)
Copy link
Contributor

Choose a reason for hiding this comment

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

these are fields

Copy link
Contributor

Choose a reason for hiding this comment

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

lets move the log to the call site

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 179 to 183
annotations: map[string]string{
rollout.LastRollForwardAnnotation: clockMock.Now().Format(time.RFC3339),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

create inline function

mkAnnotations := func(t time.Time, offset Duration) map[string]string { 
} 

inside the test function

Copy link
Contributor Author

@gvso gvso Aug 6, 2020

Choose a reason for hiding this comment

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

Since it can be also used in combination with other annotations, I created a utility function to generate the value instead.

@gvso gvso linked an issue Aug 7, 2020 that may be closed by this pull request
return svc
}

svc.Metadata.Annotations[StableRevisionAnnotation] = stable
svc.Metadata.Annotations[CandidateRevisionAnnotation] = candidate
svc.Metadata.Annotations[LastRolloutAnnotation] = now
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems like you always do this (in both cases). so why not just set it outside the if (e.g. right after now:=... ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Getulio Valentin Sánchez added 4 commits August 7, 2020 14:12
This adds a new annotation containing the last time the traffic to the candidate
was increased. Using the configuration for minimum time between roll forwards,
it decides if it can continue rolling the candidate forward.

Signed-off-by: Getulio Valentin Sánchez <gvso@google.com>
Signed-off-by: Getulio Valentin Sánchez <gvso@google.com>
Signed-off-by: Getulio Valentin Sánchez <gvso@google.com>
Signed-off-by: Getulio Valentin Sánchez <gvso@google.com>
Copy link
Contributor

@ahmetb ahmetb left a comment

Choose a reason for hiding this comment

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

LGTM. @grayside if you want to take a look as well.

@grayside
Copy link

grayside commented Aug 7, 2020

Don't have time today, and this looks good at a glance :)

@gvso gvso merged commit 63d1df6 into GoogleCloudPlatform:main Aug 10, 2020
@gvso gvso deleted the min-forward-time branch August 10, 2020 13:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a minimum time between each step
3 participants