This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
rollout: Include health report in service object #51
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
013b647
rollout: Include health report in service object
0d42934
Report in human-readable format
a1f4653
Add todo about JSONReport
4e641f1
Rename last status to status
b7d207b
Fix typo
6da8e9e
Remove JSON report
52a0478
Create setAnnotation function
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,7 +122,12 @@ func (r *Rollout) UpdateService(svc *run.Service) (*run.Service, error) { | |
if isNewCandidate(svc, candidate) { | ||
r.log.Debug("new candidate, assign some traffic") | ||
svc = r.PrepareRollForward(svc, stable, candidate) | ||
svc = r.updateAnnotations(svc, stable, candidate, "new candidate, no health report available yet") | ||
svc = r.updateAnnotations(svc, stable, candidate) | ||
|
||
// TODO(gvso): create a setHealthReportAnnotation that appends the | ||
// current time to the report before setting the annotation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this probably could be part of the health report string generation IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My initial thought was also this one, but the problem is that we don't generate a report when we have a new candidate. We have a string literal in that case |
||
setAnnotation(svc, LastHealthReportAnnotation, "new candidate, no health report available yet") | ||
|
||
err := r.replaceService(svc) | ||
return svc, errors.Wrap(err, "failed to replace service") | ||
} | ||
|
@@ -148,8 +153,10 @@ func (r *Rollout) UpdateService(svc *run.Service) (*run.Service, error) { | |
return nil, errors.Errorf("invalid candidate's health diagnosis %v", diagnosis.OverallResult) | ||
} | ||
|
||
svc = r.updateAnnotations(svc, stable, candidate) | ||
report := health.StringReport(r.strategy.HealthCriteria, diagnosis) | ||
svc = r.updateAnnotations(svc, stable, candidate, report) | ||
setAnnotation(svc, LastHealthReportAnnotation, report) | ||
|
||
err = r.replaceService(svc) | ||
return svc, errors.Wrap(err, "failed to replace service") | ||
} | ||
|
@@ -286,28 +293,31 @@ func (r *Rollout) nextCandidateTraffic(current int64) int64 { | |
} | ||
|
||
// updateAnnotations updates the annotations to keep some state about the rollout. | ||
func (r *Rollout) updateAnnotations(svc *run.Service, stable, candidate, healthReport string) *run.Service { | ||
if svc.Metadata.Annotations == nil { | ||
svc.Metadata.Annotations = make(map[string]string) | ||
} | ||
svc.Metadata.Annotations[LastHealthReportAnnotation] = healthReport | ||
|
||
func (r *Rollout) updateAnnotations(svc *run.Service, stable, candidate string) *run.Service { | ||
// The candidate has become the stable revision. | ||
if r.promoteToStable { | ||
svc.Metadata.Annotations[StableRevisionAnnotation] = candidate | ||
setAnnotation(svc, StableRevisionAnnotation, candidate) | ||
delete(svc.Metadata.Annotations, CandidateRevisionAnnotation) | ||
return svc | ||
} | ||
|
||
svc.Metadata.Annotations[StableRevisionAnnotation] = stable | ||
svc.Metadata.Annotations[CandidateRevisionAnnotation] = candidate | ||
setAnnotation(svc, StableRevisionAnnotation, stable) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, yeah you can just use it here :D |
||
setAnnotation(svc, CandidateRevisionAnnotation, candidate) | ||
if r.shouldRollback { | ||
svc.Metadata.Annotations[LastFailedCandidateRevisionAnnotation] = candidate | ||
setAnnotation(svc, LastFailedCandidateRevisionAnnotation, candidate) | ||
} | ||
|
||
return svc | ||
} | ||
|
||
// setAnnotation sets the value of an annotation. | ||
func setAnnotation(svc *run.Service, key, value string) { | ||
if svc.Metadata.Annotations == nil { | ||
svc.Metadata.Annotations = make(map[string]string) | ||
} | ||
svc.Metadata.Annotations[key] = value | ||
} | ||
|
||
// diagnoseCandidate returns the candidate's diagnosis based on metrics. | ||
func (r *Rollout) diagnoseCandidate(candidate string, healthCriteria []config.Metric) (d health.Diagnosis, err error) { | ||
healthCheckOffset := time.Duration(r.strategy.HealthOffsetMinute) * time.Minute | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we also added the time we wrote this down?
does the user have any way of telling when was this status report for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but I'd probably have a function
setHealthReportAnnotation(report string)
inrollout
since there are cases in which this function is not called (e.g. new candidate). In that function, we can append the time at the end of any report.I will defer this after #57 since we would need the mocked time introduced there. Doing it here would be double work and would make this PR much longer.