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

Refactor: Config to Application State #138

Merged
merged 19 commits into from
May 2, 2016

Conversation

justenwalker
Copy link
Contributor

@justenwalker justenwalker commented Apr 23, 2016

For #128

This is an initial stab at factoring out the application state from configuration. One cool thing about this is that many (all?) of the global variables go away.

I also added support for telemetry reload (hopefully, I have not tested this extensively)

I thought I'd get this out in the open so that everyone can poke some holes in it.

cc: @tgross

Work in progress

One thing I'm not too happy about is the proliferation of methods that I implemented on the Config struct. I think the next step would probably be to push that logic into the packages themselves. I've had some success implementing configs as some high-level structure containing mostly maps and using github.com/mitchellh/mapstructure - since it supports weak typing which would be good for things like #122

@tgross
Copy link
Contributor

tgross commented Apr 25, 2016

I'm still digging into details as there's a lot here, but just want to say this is some damn nice work @justenwalker

@tgross
Copy link
Contributor

tgross commented Apr 25, 2016

One thing I'm not too happy about is the proliferation of methods that I implemented on the Config struct. I think the next step would probably be to push that logic into the packages themselves.

What I've noticed is that there are broadly two categories of methods there. There are some that are thin wrappers on somepackage.NewSomeStruct that check for nil and that's about it. Those NewSomeStruct all take json.RawMessage, so maybe there's a nice way to define a function type for those and then push them into the packages as you've suggested.

The second category are those that are building exec.Cmd and stuff like that. I suspect we don't want to try to move those out of the core package because it's going to cause us heartburn around imports. But moving them into functions that can be tested in isolation (in core/commands.go lets say) could be useful.

@@ -58,90 +40,19 @@ type Config struct {
BackendsConfig json.RawMessage `json:"backends,omitempty"`
TasksConfig json.RawMessage `json:"tasks,omitempty"`
TelemetryConfig json.RawMessage `json:"telemetry,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessarily in scope for this PR, but omitempty is really only used when we serialize a struct, right? Maybe we don't really need this annotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we can remove it - we really don't re-serialize the config anyway, so the extra tag options are mostly useless.

@justenwalker
Copy link
Contributor Author

justenwalker commented Apr 29, 2016

@tgross There is a lot here. I broke it out into individual commits that should be hopefully self-explanitory, but I'll summarize:

"os/exec"

"github.com/joyent/containerpilot/utils"
"github.com/prometheus/common/log"
Copy link
Contributor

Choose a reason for hiding this comment

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

prometheus/common/log? What happened to logrus 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.

Ah, my auto-importer often gets the common names wrong :(

@tgross
Copy link
Contributor

tgross commented Apr 29, 2016

One last little comment about the log import in config/commands.go but otherwise this LGTM.

@tgross
Copy link
Contributor

tgross commented May 2, 2016

LGTM.

@tgross tgross merged commit 7c8c42f into TritonDataCenter:master May 2, 2016
@justenwalker justenwalker deleted the gh128_refactor-app-state branch May 11, 2016 17:32
tgross added a commit to tgross/containerpilot that referenced this pull request May 27, 2016
The native golang HTTP server cannot be gracefully reloaded. The telemetry
server originally punted on reloading because this meant the only thing we
couldn't change was the telemetry port. Although we made a go at it, we can't
make the reload work so this commit backs out the change (but still uses the
refactored code from PR TritonDataCenter#138) until we can find a better HTTP server lib to
use.
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.

2 participants