-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 Stop() to Instancer interface #566
Comments
I think it's because there is no generic definition of "stopping" the instancer, it' implementation specific and sometimes meaningless, e.g. for a static/fixed instancer. In practice this should not be a problem because when you instantiate an instancer as one of the implementations, you actually get back a concrete type, so if it has Stop() you can call it. |
I just checked and all instancer implementations do have Stop that does various things including stopping background goroutine which all of them do. As for concrete type, yes you get it. But if you want to make an abstraction in your code and hide details behind gokit's sd.Instancer, you have to type cast to Stop it which is very annoying. |
Well, this guy doesn't: FixedInstancer
You can still hide the abstraction. There is no generic factory that gives you an Instancer, so your code always has to call explicit constructor, e.g. var instancer sd.Instancer
var stopper func()
if discoveryType == "etcd" {
if etcd, err := etcd.NewInstancer(...); err == nil {
instancer = etc
stopper = func() { etcd.Stop() } // make your generic stopper
}
} else if discoveryType == "eureka" {
// ...
} |
Not hard to add an empty func.
Yes, I never said its impossible. If you hide construction in some func and want an ability to stop it, you have to return a stopper func yourself as another argument. Or construct an object that holds both instancer and stopper and provide your own interfaces. In any case its more work compared to just calling instancer.Stop() on the same object and be done with it. All I am saying is right now its inconvenient and could be made easier/better. |
Not hard to add empty func but definitely code smell. If you don't like the proposed explicit example you could also use a consumer side interface. type Stopper interface {
Stop()
}
...
var instancer sd.Instancer
...
// check if we can call Stop
if instancer, ok := instancer.(Stopper); ok {
instancer.Stop()
} |
Every implementation (modulo mock/test impls) already provided this method, and so it makes sense to lift it to the interface definition. Closes #566.
* cmd/kitgen: parse * First stymie * Sketch developing * Broken sketch. * Further progress - still doesn't build * Need to collect ast.Exprs, not strings * Running downhill. * sd: add Stop method to Instancer interface Every implementation (modulo mock/test impls) already provided this method, and so it makes sense to lift it to the interface definition. Closes #566. * Fruitful avenue. Committing for travel. * Needs uniquify for varnames * Track gauge values and support default tags for dogstatsd Dogstatsd doesn't support sending deltas for gauges, so we must maintain the raw gauge value ourselves. * Service generation tests work * add failing test for cloudwatch metrics, that are not reset * Refactor cloudwatch: Reset().Walk() on every Send(), like influx impl does. Note there is a breaking API change, as the cloudwatch object now has optional parameters. * Tolerate that there may not be any lables, if the teststat.FillCounter() did not add any samples. * Use Cloudwatch options in the struct itself, which is cleaner * sd: fix TestDefaultEndpointer flake, hopefully * util/conn: more detail for flaky test * removed deprecated functions changed `NewContext -> NewOutgoingContext` and `FromContext -> FromIncomingContext` as described in [metadta](https://github.com/grpc/grpc-go/blob/master/metadata/metadata.go) * Functions extracted from inline codefile * Cleaner/easier way for user to specify Cloudwatch metric percentiles. * fix test to read quantile metrics with p prefix * test cloudwatch.WithPercentiles() * Handles anonymous fields for all parts of interface * Handles underscore param names, produces compile-able code * do not prefix metrics with 'p', just like it was previously. * Fix for dogstatsd metrics with default tags and no labelValues Signed-off-by: James Hamlin <james@goforward.com> * Converted flat to a layout - proceeding to implement default * Convenience function for formatting to a tree * Fix spelling of deregisters https://en.wiktionary.org/wiki/deregister * Add basic auth middleware * Default layout * Need to handle mutating trees more effectively to do default layout. * Basic Auth: optimize memory allocation. * Fix typo * cache required creds' slices * Clean up comment * Replacing idents successfully * improve error handling and style * Constructs import paths usefully * Some debugging - transit * Set time unit on metrics.Timer * Changes as per code review * fix missing comma in example histogram code * update_deps.bash: handle detached HEAD better * .travis.yml: go1.9 + tip exclusively * circle.yml: go1.9 exclusively * Selectify works - need to rearrange some idents now * Updating golden masters so that they build * Nearly 100% functionality * Updated masters - all seems to work * Now testing that everything builds * Removing AST experiments * Chopping up long sourcecontext.gog * Tiny little notes * auth/jwt: add claim factory to example * auth/jwt: minor gofmt fixes * fix typo in addcli * Cleaning up some type assertion digging * Remove dependency on juju * Downstream usages of ratelimit package * Recreating profilesvc issue * Adding .ignore for rg * flat layout works with defined types * Default layout mostly works - one remaining selectify issue * Debugging replaces - determined we need to do cloning * Halfway through an edit - taking it home * Works with new profilesvc testcases * Try to fix Thrift failure (again) (#630) * Empty commit to trigger CI * examples/addsvc: rebuild with latest thrift * cmd/kitgen: parse * First stymie * Sketch developing * Broken sketch. * Further progress - still doesn't build * Need to collect ast.Exprs, not strings * Running downhill. * Fruitful avenue. Committing for travel. * Needs uniquify for varnames * Service generation tests work * Functions extracted from inline codefile * Handles anonymous fields for all parts of interface * Handles underscore param names, produces compile-able code * Converted flat to a layout - proceeding to implement default * Convenience function for formatting to a tree * Default layout * Need to handle mutating trees more effectively to do default layout. * Replacing idents successfully * Constructs import paths usefully * Some debugging - transit * Selectify works - need to rearrange some idents now * Updating golden masters so that they build * Nearly 100% functionality * Updated masters - all seems to work * Now testing that everything builds * Removing AST experiments * Chopping up long sourcecontext.gog * Tiny little notes * Cleaning up some type assertion digging * Recreating profilesvc issue * Adding .ignore for rg * flat layout works with defined types * Default layout mostly works - one remaining selectify issue * Debugging replaces - determined we need to do cloning * Halfway through an edit - taking it home * Works with new profilesvc testcases
Stop() func is not part of Instancer interface which makes it impossible to stop instancers in a generic way.
The text was updated successfully, but these errors were encountered: