-
Notifications
You must be signed in to change notification settings - Fork 619
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
modifier: adding modifier tag concept #69
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package proxy | |
|
||
import ( | ||
"net/http" | ||
"strings" | ||
"time" | ||
|
||
"github.com/eBay/fabio/config" | ||
|
@@ -52,6 +53,16 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
h = newHTTPProxy(t.URL, p.tr) | ||
} | ||
|
||
// strip the prefix, if the target was tagged properly | ||
if t.StripPrefix { | ||
pieces := strings.SplitN(r.URL.Path, "/", 3) | ||
if len(pieces) == 3 { | ||
r.URL.Path = pieces[2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs refactoring, was just getting something working 😄 |
||
} else { | ||
r.URL.Path = "/" | ||
} | ||
} | ||
|
||
start := time.Now() | ||
h.ServeHTTP(w, r) | ||
p.requests.UpdateSince(start) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package route | |
import ( | ||
"fmt" | ||
"net/url" | ||
"regexp" | ||
"sort" | ||
"strings" | ||
|
||
|
@@ -11,6 +12,8 @@ import ( | |
gometrics "github.com/rcrowley/go-metrics" | ||
) | ||
|
||
var StripPrefixRegex *regexp.Regexp = regexp.MustCompile("modifier-/strip-prefix") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would love to hear thoughts on naming here. I'm not overly opinionated, I also considered |
||
|
||
// Route maps a path prefix to one or more target URLs. | ||
// routes can have a share value which describes the | ||
// amount of traffic this route should get. You can specify | ||
|
@@ -51,7 +54,24 @@ func (r *Route) addTarget(service string, targetURL *url.URL, fixedWeight float6 | |
name := metrics.TargetName(service, r.Host, r.Path, targetURL) | ||
timer := gometrics.GetOrRegisterTimer(name, metrics.ServiceRegistry) | ||
|
||
t := &Target{Service: service, Tags: tags, URL: targetURL, FixedWeight: fixedWeight, Timer: timer, timerName: name} | ||
stripPrefix := false | ||
// by passing a tag of `url-prefix-host/modifier#strip-prefix you can | ||
// drop whatever prefix the service is namespaced by | ||
for _, tag := range tags { | ||
if StripPrefixRegex.MatchString(tag) { | ||
stripPrefix = true | ||
} | ||
} | ||
|
||
t := &Target{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about a |
||
Service: service, | ||
Tags: tags, | ||
URL: targetURL, | ||
StripPrefix: stripPrefix, | ||
FixedWeight: fixedWeight, | ||
Timer: timer, | ||
timerName: name} | ||
|
||
r.Targets = append(r.Targets, t) | ||
r.weighTargets() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was digging through this, and it seems like the
Target
object could have aModify
method which accepts anhttp.Request
object and modifies the request to its liking. In the case that we had moremodifier
tags, this could be quite useful