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

Module rewrite #275

Merged
merged 35 commits into from
Mar 1, 2017
Merged

Module rewrite #275

merged 35 commits into from
Mar 1, 2017

Conversation

bufdev
Copy link
Contributor

@bufdev bufdev commented Feb 16, 2017

No description provided.

@mention-bot
Copy link

@peter-edge, thanks for your PR! By analyzing the history of the files in this pull request, we identified @sectioneight, @shawnburke and @madhuravi to be potential reviewers.

Host
Items() map[string]interface{}
// TODO(pedge)
ConfigValue() config.Value
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought Host already has Config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya I'm going to remove this for now

return nil
}
func WithInboundMiddleware(i ...middleware.UnaryInbound) service.ModuleOption {
return service.WithModuleItem(_interceptorKey, func(existing interface{}) interface{} {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this wrapping on write to module item.
maybe a similar wrapping for read as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean exactly? Wrap Items() access?

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

func WithModuleItem(key string, f func(interface{})interface{}) ModuleOption {
return func(o *moduleOption) error {
value, ok := o.items[key]
if ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

if value, ok := o.items[key]; ok {
  o.items[key] = f(value)
  return nil
}
o.items[key] = f(nil)
retur nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ya whoops, sorry

Copy link
Contributor

@dmcaulay dmcaulay left a comment

Choose a reason for hiding this comment

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

so much better 👏

service/host.go Outdated
@@ -323,29 +304,34 @@ func (s *host) Stop(reason string, exitCode int) error {
return err
}

func (s *host) startModules() map[Module]error {
results := map[Module]error{}
func (s *host) startModules() []error {
Copy link
Contributor

Choose a reason for hiding this comment

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

so this only happens once, right? how much time are we saving be starting these in parallel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No idea, but this PR is just addressing the external interface, I think we can iterate on implementation some other time.

Copy link
Contributor

Choose a reason for hiding this comment

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

sg

return &serviceCore{
authClient: client,
configProvider: config.NewStaticProvider(nil),
configProvider: configProvider,
standardConfig: serviceConfig{
Name: "dummy",
Copy link
Contributor

Choose a reason for hiding this comment

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

can we read the name from our config provider? i need this for some integration tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can, but probably out of scope for this PR

return m.name
}

func (m *moduleWrapper) Start() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove locking if we single thread start/stop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya we can, but I really think the locking is "proper".

Copy link
Contributor

Choose a reason for hiding this comment

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

okay. fine with it.

}

func (mi *moduleInfo) Metrics() tally.Scope {
return mi.Host.Metrics().SubScope("modules").SubScope(mi.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

is it more efficient to memoize this scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think I have a TODO somewhere in this file to do that

@@ -65,7 +60,8 @@ var (
// that are stored together to create a shared dispatcher.
// The YARPC team advised it to be a 'singleton' to control
// the lifecycle of all of the in/out bound traffic.
_controller dispatcherController
_controller dispatcherController
_controllerRunning bool
Copy link

Choose a reason for hiding this comment

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

This global var is definitely not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

type CreateThriftServiceFunc func(svc service.Host) ([]transport.Procedure, error)

// ThriftModule creates a Thrift Module from a service func
func ThriftModule(hookup CreateThriftServiceFunc, options ...modules.Option) service.ModuleCreateFunc {
Copy link

Choose a reason for hiding this comment

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

Why are you removing options?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are now on the service builder only

for msg := range b.bufQueue {
errorCh <- Run(context.Background(), msg)
// TODO(pedge): this was effectively not being handled and was a bug
Copy link

Choose a reason for hiding this comment

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

It is not a bug, but a feature :) Seriously, this is a way to communicate with a sender about errors in function executions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you look into how this channel was read, this error would have never been read with the current service code

Copy link
Contributor

Choose a reason for hiding this comment

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

We do want to propagate these errors up so nothing to change here. Need to not drop them on the floor in module Start where this gets called.

@bufdev bufdev mentioned this pull request Feb 20, 2017
@bufdev bufdev changed the title WIP Module rewrite [WIP] [NOT READY FOR REVIEW] Module rewrite Feb 20, 2017
@bufdev bufdev changed the title [WIP] [NOT READY FOR REVIEW] Module rewrite [WIP] Module rewrite Feb 20, 2017
@bufdev
Copy link
Contributor Author

bufdev commented Feb 20, 2017

I've updated for the latest changes. Before continuing, if everyone could give a quick lookover of what has happened so far, that would be great - the next step is going to be a lot of test refactoring and documentation updates, and before doing that, it would be nice to have a general "OK" from what I have so far.

@sectioneight @dmcaulay @alsamylkin @madhuravi @yutongp @glibsm

@@ -22,22 +22,26 @@ package service

import "github.com/pkg/errors"

// WithModules is a helper to create a service without any options
func WithModules(modules ...ModuleCreateFunc) *Builder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? I would prefer keeping WithModules.
1.
service.WithModule(
rpc,
uhttp,
task
)

service.WithModule(uhttp)
.WithModule(rpc)
.WithModule(task)

1 (the existing way) seems simpler and nicer than 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can't do this anymore, WithModule takes more than one parameter for every module.

@bufdev
Copy link
Contributor Author

bufdev commented Feb 20, 2017 via email

Copy link
Contributor

@dmcaulay dmcaulay left a comment

Choose a reason for hiding this comment

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

this is looking good to me. a lot of great work here.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d2a3a7b on module-rewrite into ** on master**.

@@ -48,7 +48,8 @@
// )
Copy link
Contributor

Choose a reason for hiding this comment

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

This file shouldn't be included?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

? It changed from make gendoc.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 92.139% when pulling c5af058 on module-rewrite into 8622d3c on master.

@bufdev
Copy link
Contributor Author

bufdev commented Feb 23, 2017

Code coverage is back up

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 92.141% when pulling ca33b51 on module-rewrite into 8622d3c on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 90.836% when pulling 5aad484 on module-rewrite into 732bd07 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 90.836% when pulling 5aad484 on module-rewrite into 732bd07 on master.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 12b58a2 on module-rewrite into ** on master**.

@coveralls
Copy link

coveralls commented Mar 1, 2017

Coverage Status

Changes Unknown when pulling f0304ee on module-rewrite into ** on master**.

@bufdev bufdev mentioned this pull request Mar 1, 2017
@bufdev bufdev merged commit a35fbb7 into master Mar 1, 2017
@bufdev bufdev deleted the module-rewrite branch March 1, 2017 21:28
@ascandella
Copy link
Contributor

👏 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

8 participants