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

Enable setting environment variables via Hooks #27

Merged
merged 1 commit into from
Dec 4, 2017

Conversation

AlfredBroda
Copy link
Contributor

This allows for setting application environment via Hooks (for remote configuration retrieval purposes).

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 75.92% when pulling 2640253 on feature_set_env into 1648fdf on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 75.92% when pulling a3a0329 on feature_set_env into 1648fdf on master.

Copy link
Contributor

@medzin medzin left a comment

Choose a reason for hiding this comment

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

It will not work - hook recives copy of TaskInfo. You have to modify Hook interface so it will allow to return values.

@AlfredBroda AlfredBroda changed the title Enable setting environment variables via mesos.taskInfo Enable setting environment variables via Hooks Nov 30, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 75.79% when pulling aae731b on feature_set_env into 6705a3a on master.

Copy link
Contributor

@janisz janisz left a comment

Choose a reason for hiding this comment

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

Change commit message. You add only test now.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 75.79% when pulling 42947c0 on feature_set_env into 6705a3a on master.

@medzin
Copy link
Contributor

medzin commented Dec 1, 2017

@AlfredBroda why I see "Fix Travis configuration for releses #22" in this PR?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 74.945% when pulling 816e858 on feature_set_env into 653f93c on master.

@AlfredBroda
Copy link
Contributor Author

Fixed all the conflicts... for now.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.6%) to 76.139% when pulling bd84cbe on feature_set_env into 653f93c on master.

janisz
janisz previously requested changes Dec 1, 2017
command.go Outdated
@@ -121,7 +122,7 @@ func (c *cancellableCommand) Stop(gracePeriod time.Duration) {
}

// NewCommand returns a new command based on passed CommandInfo.
func NewCommand(commandInfo mesos.CommandInfo, env []string, options ...func(*exec.Cmd) error) (Command, error) {
func NewCommand(commandInfo mesos.CommandInfo, env hook.Env, options ...func(*exec.Cmd) error) (Command, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Env should not be defined in hook package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where do you suggest to put it? executor.go? command.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted back to []string

default:
log.Debugf("Received unsupported event type %s - ignoring", event.Type)
return nil // ignore unsupported events
return hook.Env{}, nil // ignore unsupported events
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO nil will be better than hook.Env{}

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a problem really - you have to perform error check before you will use that value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And deal with mocking in tests. Will try that approach (again).

Copy link
Contributor

@medzin medzin Dec 1, 2017

Choose a reason for hiding this comment

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

I mean, it does not make sense to return pointer here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Returning nil then.

executor.go Outdated
Type: hook.BeforeTaskStartEvent,
TaskInfo: mesosutils.TaskInfo{TaskInfo: taskInfo},
}
additionalEnv, err := e.hookManager.HandleEvent(beforeStartEvent, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

You have to merge env and additionalEnv slices or services will not have access to certificate or MESOS_ variables.

Copy link
Contributor

@medzin medzin Dec 1, 2017

Choose a reason for hiding this comment

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

Also add test case for this - the current ones did not catch this problem (os.Environ() is not copied into command env)

Copy link
Contributor

@medzin medzin left a comment

Choose a reason for hiding this comment

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

Correct the submitted comments.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.0%) to 75.56% when pulling 7b2fad2 on feature_set_env into 653f93c on master.

@medzin
Copy link
Contributor

medzin commented Dec 1, 2017

@AlfredBroda explain in commit message why we are enabling this.

hook/hook.go Outdated
@@ -25,12 +25,15 @@ type Event struct {
TaskInfo mesosutils.TaskInfo
}

// Env is a container type for environment variables.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add info about format. Most people will expect map here - not slice.


returnedValue := taskInfo.FindEnvValue(key)

require.Equal(t, returnedValue, expectedValue)
Copy link
Contributor

Choose a reason for hiding this comment

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

Signature of Equal is:

func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{})

(switch returnedValue and expectedValue)

@coveralls
Copy link

Coverage Status

Coverage increased (+1.5%) to 75.771% when pulling 910c347 on feature_set_env into a0fa859 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.5%) to 75.771% when pulling 910c347 on feature_set_env into a0fa859 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.4%) to 75.627% when pulling de3e296 on feature_set_env into a0fa859 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.5%) to 75.46% when pulling 2474a3b on feature_set_env into 36a4c04 on master.

@AlfredBroda AlfredBroda dismissed janisz’s stale review December 4, 2017 12:50

Fixes done, no time to wait for your ok. :P

@AlfredBroda AlfredBroda merged commit 7cd3c84 into master Dec 4, 2017
Copy link
Contributor

@janisz janisz left a comment

Choose a reason for hiding this comment

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

We could make use of named return values. E.g., when it's alywas nil we can call it ignore.

I'd like to make code cleanup in separated commits.

@@ -405,8 +414,8 @@ func (e *Executor) shutDown(taskInfo mesos.TaskInfo, cmd Command) {
Type: hook.BeforeTerminateEvent,
TaskInfo: mesosutils.TaskInfo{TaskInfo: taskInfo},
}
_ = e.hookManager.HandleEvent(beforeTerminateEvent, true) // ignore errors here, so every hook will have a chance to be called
cmd.Stop(gracePeriod) // blocking call
_, _ = e.hookManager.HandleEvent(beforeTerminateEvent, true) // ignore errors here, so every hook will have a chance to be called
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 we should log errors

@@ -46,15 +46,15 @@ type Config struct {

// HandleEvent calls appropriate hook functions that correspond to supported
// event types. Unsupported events are ignored.
func (h *Hook) HandleEvent(event hook.Event) error {
func (h *Hook) HandleEvent(event hook.Event) (hook.Env, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please document when HandleEvent returns hook.Env

@@ -25,12 +25,15 @@ type Event struct {
TaskInfo mesosutils.TaskInfo
}

// Env is a container for os.Environ style list of combined environment variable strings.
type Env []string
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 this should not be in this package

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest another then 😄

// Hook is an interface for various executor extensions, that can add some actions
// during task lifecycle events.
type Hook interface {
// HandleEvent is called when any of defined executor task events occurs.
// Received events may be handled in any way, but hook should ignore unknown or
// unsupported ones. Call to this function will block executor process until
// it returns. Order of received event types is undefined.
HandleEvent(Event) error
HandleEvent(Event) (Env, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the godoc

@AlfredBroda AlfredBroda deleted the feature_set_env branch January 31, 2018 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants