-
Notifications
You must be signed in to change notification settings - Fork 55
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 "service context" support for exec and health checks #246
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
987e5d2
Add support for service's to configure working directory
benhoyt 085a61a
Service context support for health checks of type exec
benhoyt 198246e
Move context merging logic to plan package for sharing
benhoyt 0abe106
Make MergeServiceContext copy ints; add tests
benhoyt 7a0a68f
Add exec support for service context and "pebble exec --context" arg
benhoyt 152ddc7
Merge branch 'master' into service-context
benhoyt 927e833
Address Jordan's code review points
benhoyt 224231f
Couple more wording tweaks.
benhoyt 91a8736
Merge branch 'master' into service-context
benhoyt 00eae86
Add copyIntPtr shortcut
benhoyt b608a0f
Rename "context" to "service-context" per spec update
benhoyt 505cbf3
Oops, rename health check instances too
benhoyt 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
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
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 |
---|---|---|
|
@@ -72,7 +72,7 @@ func (m *CheckManager) PlanChanged(p *plan.Plan) { | |
ctx, cancel := context.WithCancel(context.Background()) | ||
check := &checkData{ | ||
config: config, | ||
checker: newChecker(config), | ||
checker: newChecker(config, p), | ||
ctx: ctx, | ||
cancel: cancel, | ||
action: m.callFailureHandlers, | ||
|
@@ -93,7 +93,7 @@ func (m *CheckManager) callFailureHandlers(name string) { | |
} | ||
|
||
// newChecker creates a new checker of the configured type. | ||
func newChecker(config *plan.Check) checker { | ||
func newChecker(config *plan.Check, p *plan.Plan) checker { | ||
switch { | ||
case config.HTTP != nil: | ||
return &httpChecker{ | ||
|
@@ -110,15 +110,28 @@ func newChecker(config *plan.Check) checker { | |
} | ||
|
||
case config.Exec != nil: | ||
overrides := plan.ContextOptions{ | ||
Environment: config.Exec.Environment, | ||
UserID: config.Exec.UserID, | ||
User: config.Exec.User, | ||
GroupID: config.Exec.GroupID, | ||
Group: config.Exec.Group, | ||
WorkingDir: config.Exec.WorkingDir, | ||
} | ||
merged, err := plan.MergeServiceContext(p, config.Exec.Context, overrides) | ||
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. That's a very clean implementation. Thank you. |
||
if err != nil { | ||
// Context service name has already been checked when plan was loaded. | ||
panic("internal error: " + err.Error()) | ||
} | ||
return &execChecker{ | ||
name: config.Name, | ||
command: config.Exec.Command, | ||
environment: config.Exec.Environment, | ||
userID: config.Exec.UserID, | ||
user: config.Exec.User, | ||
groupID: config.Exec.GroupID, | ||
group: config.Exec.Group, | ||
workingDir: config.Exec.WorkingDir, | ||
environment: merged.Environment, | ||
userID: merged.UserID, | ||
user: merged.User, | ||
groupID: merged.GroupID, | ||
group: merged.Group, | ||
workingDir: merged.WorkingDir, | ||
} | ||
|
||
default: | ||
|
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
Oops, something went wrong.
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.
This is not about this PR, but looking at this logic makes me think there's a bug here that needs to be addressed separately. The cancel here is a request. Right above we're calling cancel() as if this would be a synchronous operation, but it's not. The goroutine may take its time to run. This may cause very awkward outcomes, such as an old check running after a new check. We need to use tomb or something similar to make the stopping of checkers become synchronous.
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.
Indeed! @flotter Actually fixed this exact bug a couple of weeks ago. It was causing intermittent issues in CI, but of course as you point out it could be a problem in production too.
@flotter Note that in future (perhaps for your servstate fix :-) we should probably use tombs for this rather than wait groups, to be consistent with other parts of Pebble. Pebble already uses tombs extensively elsewhere, so it won't be a new dependency. I should have mentioned that in the code review.