forked from vulcand/vulcand
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I filed an ISSUE earlier to discuss this here: vulcand#218 The crux of this change is: 1. To make Router an interface behind which implementations can be changed out. 2. To allow the Registry to specify an implementation. 3. To fall back to the default implementation (route.Mux) when one is not provided by the registry. This change also depends on this pending PR in the mailgun/route library vulcand/route#10 WHY? As we try to add new features to mailgun/route, we continue to have to work off custom branches and re-vendor the files, and rebuild vulcand for each experiment. For example we have a forked route library which contains massive amounts of logging. Having re-vendored files is always confusing because we don't know what branch/fork it came from. We'd much rather have a way to host 10 forks and simply plug in an implementation at runtime based on command-line flags. This allows us to rapidly innovate, and I'm sure gives vulcand users the ability to use richer or simpler languages. For instance, one experiment I want to run is use of Javascript-based expressions which would allow the use of VERY rich matching rules at the cost of VERY high compute load per rule-match. It's just an idea, but trying it out can be made easier by making it pluggable. As it happens this change doesn't affect how Vulcan works today, and the defaults do not change. Some example routing rules are: r.Referrer.indexOf("foo.com") > 0 //When referrer is foo.com r.Header.Get("Cookie")["foo"] == "bar" //Check value of cookie without using a complex regex TESTING: There are sufficient UTs here, and in addition we have written sufficient UTs in a couple of routing libraries we wrote as an experiment to see how far we could go. Polyverse Corporation (the company I work for) has been using the forked copy with these changes for over three weeks at this point. We're running a pluggable library in production across a large cluster reliably. HOW TO: After this change, this is how we inject a custom router into our own installation: func GetRegistry(selfaddress string) (*plugin.Registry, error) { r := plugin.NewRegistry() specs := []*plugin.MiddlewareSpec{ connlimit.GetSpec(), ratelimit.GetSpec(), rewrite.GetSpec(), cbreaker.GetSpec(), trace.GetSpec(), ttlresetmiddleware.GetSpec(), unroutedrequesthandler.GetSpec(), polyverseerrormiddleware.GetSpec(), connectionmanagementmiddleware.GetSpec(), } r.AddNotFoundMiddleware(notFoundMiddleware) //Use combination-router to enable javascript evaluation as a fallback mechanism //when mailgun/route is insufficient. routers := combineroute.Routers{ combineroute.RouterEntry{ Name: "vulcanrouter", Router: route.NewMux(), }, combineroute.RouterEntry{ Name: "javascriptrouter", Router: jsroute.NewMux(), }, } commonrouter := combineroute.NewMux(routers) r.SetRouter(commonrouter) for _, spec := range specs { if err := r.AddSpec(spec); err != nil { return nil, err } } return r, nil } READY TO USE ROUTERS: Here are a couple of libraries that demonstrate the possibilities of allowing different language evaluators to be used for routing rules. https://github.com/polyverse-security/js-route https://github.com/polyverse-security/combine-route
- Loading branch information
Archis Gore
committed
Oct 16, 2015
1 parent
791285c
commit d598c38
Showing
20 changed files
with
149 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
Godeps/_workspace/src/github.com/mailgun/route/matcher_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.