Skip to content

Commit

Permalink
Merge branch 'develop' into urbs
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Apr 29, 2020
2 parents 4650791 + 87d4da0 commit 563e642
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
21 changes: 12 additions & 9 deletions pkg/middlewares/canary/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ func (c *Canary) processCanary(rw http.ResponseWriter, req *http.Request) {
}

type userInfo struct {
UID string `json:"uid"`
Sub string `json:"sub"`
ID string `json:"id"`
UID0 string `json:"uid"`
UID1 string `json:"_userId"`
UID2 string `json:"sub"`
UID3 string `json:"id"`
}

func extractUserID(req *http.Request, uidCookies []string) string {
Expand Down Expand Up @@ -212,12 +213,14 @@ func extractUserIDFromBase64(s string) string {
user := &userInfo{}
if err = json.Unmarshal(b, user); err == nil {
switch {
case user.UID != "":
return user.UID
case user.Sub != "":
return user.Sub
case user.ID != "":
return user.ID
case user.UID0 != "":
return user.UID0
case user.UID1 != "":
return user.UID1
case user.UID2 != "":
return user.UID2
case user.UID3 != "":
return user.UID3
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/middlewares/canary/canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestCanary(t *testing.T) {
cfg := dynamic.Canary{MaxCacheSize: 3, Server: "localhost", Product: "Urbs", AddRequestID: true}
c, err := New(context.Background(), next, cfg, "test")
c.ls.mustFetchLabels = func(ctx context.Context, uid, requestID string) ([]Label, int64) {
return []Label{Label{Label: uid}}, time.Now().Unix()
return []Label{{Label: uid}}, time.Now().Unix()
}
a.Nil(err)

Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/kubernetes/crd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.
case p.lastConfiguration.Get() == confHash:
logger.Debugf("Skipping Kubernetes event kind %T", event)
default:
logger.Infof("Process Kubernetes event %T, hash %d, conf %+v", event, confHash, conf)
logger.Infof("Process Kubernetes event %T, hash %d", event, confHash)
p.lastConfiguration.Set(confHash)
configurationChan <- dynamic.Message{
ProviderName: providerName,
Expand Down
21 changes: 13 additions & 8 deletions pkg/provider/kubernetes/crd/kubernetes_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,23 @@ func (c configBuilder) buildLabeledLB(ctx context.Context, namespace string, tSe
conf[fullNameMain] = k8sService
}

labeledServices := make([]string, len(tService.Labeled.Services))

for i, service := range tService.Labeled.Services {
fullName, k8sService, err := c.nameAndService(ctx, namespace, service.LoadBalancerSpec)
logger := log.FromContext(ctx)
labeledServices := make([]string, 0)
for _, service := range tService.Labeled.Services {
s := service.LoadBalancerSpec
fullName, k8sService, err := c.nameAndService(ctx, namespace, s)
if err != nil {
return err
logger.Errorf("buildLabeledLB (%s, %s, %s) failed: %s,", s.Name, s.Namespace, s.Kind, err.Error())
continue // ignore invalid service
}

if k8sService != nil {
conf[fullName] = k8sService
if k8sService == nil {
logger.Errorf("buildLabeledLB %s failed: %s,", fullName, "no k8s service")
continue // ignore invalid service
}
labeledServices[i] = fullName

conf[fullName] = k8sService
labeledServices = append(labeledServices, fullName)
}

conf[id] = &dynamic.Service{
Expand Down
7 changes: 5 additions & 2 deletions pkg/server/service/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ func buildProxy(passHostHeader *bool, responseForwarding *dynamic.ResponseForwar
}
}

log.Infof("'%d %s' caused by: %v", statusCode, statusText(statusCode), err)
if statusCode > 500 {
log.Warnf("Error proxying: %d, xRequestID: %s, host: %s, url: %s, caused by: %v",
statusCode, request.Header.Get("X-Request-ID"), request.Host, request.URL.String(), err)
}
w.WriteHeader(statusCode)
_, werr := w.Write([]byte(statusText(statusCode)))
if werr != nil {
log.Infof("Error while writing status code", werr)
log.Warnf("Error while writing status code: %s", werr.Error())
}
},
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/server/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ func (m *Manager) getLRRServiceHandler(ctx context.Context, serviceName string,
}

balancer := lrr.New(config.ServiceName, defaultHandler)
logger := log.FromContext(ctx)
for _, fullServiceName := range config.Services {
serviceHandler, err := m.BuildHTTP(ctx, fullServiceName, responseModifier)
if err != nil {
return nil, err
logger.Errorf("getLRRServiceHandler %s failed: %s,", fullServiceName, err.Error())
continue // should fallback to defaultHandler
}

balancer.AddService(fullServiceName, serviceHandler)
Expand Down

0 comments on commit 563e642

Please sign in to comment.