Skip to content

Commit

Permalink
Merge pull request #15 from BuoyantIO/flynn/1.2.1
Browse files Browse the repository at this point in the history
1.2.2
  • Loading branch information
kflynn authored May 2, 2024
2 parents 79f416b + 1324f43 commit f2b4104
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion assets/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ <H1>Faces</H1>
let now = new Date().toISOString()
xhr.open("GET", `${this.fetchURL}?row=${this.row}&col=${this.col}&now=${now}`);
xhr.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0");
xhr.setRequestHeader("X-Faces-User", this.sw.userControl.user);
xhr.setRequestHeader("%%{user_header}", this.sw.userControl.user);

// We must send credentials...
xhr.withCredentials = true
Expand Down
5 changes: 3 additions & 2 deletions faces-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@

{{- define "partials.select-errorFraction" -}}
{{ $fraction := "" }}
{{- if .source.errorFraction -}}
{{- $fraction = .source.errorFraction -}}
{{ $srcFraction := .source.errorFraction }}
{{- if or ($srcFraction) (eq $srcFraction 0) -}}
{{- $fraction = $srcFraction -}}
{{- else if (and .default .default.errorFraction) -}}
{{- $fraction = .default.errorFraction -}}
{{- end -}}
Expand Down
48 changes: 24 additions & 24 deletions faces-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,39 @@ backend:
delayBuckets: "0,5,10,15,20,50,200,500,1500"

smiley:
image: "" # If set, overrides the imageName/imageTag pair
imageName: "" # If not set, uses backend.imageName
imageTag: "" # If not set, uses backend.imageTag
imagePullPolicy: "" # If not set, uses backend.imagePullPolicy
errorFraction: "" # If not set, uses backend.errorFraction
delayBuckets: "" # If not set, uses backend.delayBuckets
smiley: "" # Override if desired
# image: "" # If set, overrides the imageName/imageTag pair
# imageName: "" # If not set, uses backend.imageName
# imageTag: "" # If not set, uses backend.imageTag
# imagePullPolicy: "" # If not set, uses backend.imagePullPolicy
# errorFraction: "" # If not set, uses backend.errorFraction
# delayBuckets: "" # If not set, uses backend.delayBuckets

smiley2:
enabled: False # If set to True, enables the second smiley workload
image: "" # If set, overrides the imageName/imageTag pair
imageName: "" # If not set, uses backend.imageName
imageTag: "" # If not set, uses backend.imageTag
imagePullPolicy: "" # If not set, uses backend.imagePullPolicy
errorFraction: "" # If not set, uses backend.errorFraction
delayBuckets: "" # If not set, uses backend.delayBuckets
smiley: "HeartEyes" # Override if desired
# image: "" # If set, overrides the imageName/imageTag pair
# imageName: "" # If not set, uses backend.imageName
# imageTag: "" # If not set, uses backend.imageTag
# imagePullPolicy: "" # If not set, uses backend.imagePullPolicy
# errorFraction: "" # If not set, uses backend.errorFraction
# delayBuckets: "" # If not set, uses backend.delayBuckets

color:
image: "" # If set, overrides the imageName/imageTag pair
imageName: "" # If not set, uses backend.imageName
imageTag: "" # If not set, uses backend.imageTag
imagePullPolicy: "" # If not set, uses backend.imagePullPolicy
errorFraction: "" # If not set, uses backend.errorFraction
delayBuckets: "" # If not set, uses backend.delayBuckets
color: "" # Override if desired, defaults to colorblind-friendly light blue from the Tol palette
# image: "" # If set, overrides the imageName/imageTag pair
# imageName: "" # If not set, uses backend.imageName
# imageTag: "" # If not set, uses backend.imageTag
# imagePullPolicy: "" # If not set, uses backend.imagePullPolicy
# errorFraction: "" # If not set, uses backend.errorFraction
# delayBuckets: "" # If not set, uses backend.delayBuckets

color2:
enabled: False # If set to True, enables the second color workload
image: "" # If set, overrides the imageName/imageTag pair
imageName: "" # If not set, uses backend.imageName
imageTag: "" # If not set, uses backend.imageTag
imagePullPolicy: "" # If not set, uses backend.imagePullPolicy
errorFraction: "" # If not set, uses backend.errorFraction
delayBuckets: "" # If not set, uses backend.delayBuckets
color: "green" # Override if desired, defaults to colorblind-friendly green from the Tol palette
# image: "" # If set, overrides the imageName/imageTag pair
# imageName: "" # If not set, uses backend.imageName
# imageTag: "" # If not set, uses backend.imageTag
# imagePullPolicy: "" # If not set, uses backend.imagePullPolicy
# errorFraction: "" # If not set, uses backend.errorFraction
# delayBuckets: "" # If not set, uses backend.delayBuckets
5 changes: 4 additions & 1 deletion pkg/faces/baseserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type BaseServer struct {
server *http.ServeMux
preHook Hook
postHook Hook
userHeaderName string
}

func NewBaseServer(serverName string) *BaseServer {
Expand Down Expand Up @@ -153,6 +154,7 @@ func (srv *BaseServer) SetupFromEnvironment() {

srv.RegisterCustom("/rl", srv.rlGetHandler)

srv.userHeaderName = utils.StringFromEnv("USER_HEADER_NAME", "X-Faces-User")
srv.hostIP = utils.StringFromEnv("HOST_IP", utils.StringFromEnv("HOSTNAME", "unknown"))

delayBucketsStr := utils.StringFromEnv("DELAY_BUCKETS", "")
Expand Down Expand Up @@ -188,6 +190,7 @@ func (srv *BaseServer) SetupFromEnvironment() {
fmt.Printf("%s %s: latch_fraction %d\n", time.Now().Format(time.RFC3339), srv.Name, srv.latchFraction)
fmt.Printf("%s %s: debug_enabled %v\n", time.Now().Format(time.RFC3339), srv.Name, srv.debugEnabled)
fmt.Printf("%s %s: max_rate %f\n", time.Now().Format(time.RFC3339), srv.Name, srv.maxRate)
fmt.Printf("%s %s: userHeaderName %v\n", time.Now().Format(time.RFC3339), srv.Name, srv.userHeaderName)
}

func (srv *BaseServer) ListenAndServe(port string) {
Expand Down Expand Up @@ -430,7 +433,7 @@ func (srv *BaseServer) standardHeaders(w http.ResponseWriter, r *http.Request, s
}

w.Header().Set("Content-Type", contentType)
w.Header().Set("X-Faces-User", r.Header.Get("x-faces-user"))
w.Header().Set(srv.userHeaderName, r.Header.Get(srv.userHeaderName))
w.Header().Set("User-Agent", r.Header.Get("User-Agent"))
w.Header().Set("X-Faces-Pod", srv.hostIP)
w.WriteHeader(statusCode)
Expand Down
6 changes: 3 additions & 3 deletions pkg/faces/faceserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (srv *FaceServer) makeRequest(user string, userAgent string, service string
}

if !failed {
req.Header.Set("X-Faces-User", user)
req.Header.Set(srv.userHeaderName, user)
req.Header.Set("User-Agent", userAgent)

response, err = http.DefaultClient.Do(req)
Expand Down Expand Up @@ -190,7 +190,7 @@ func (srv *FaceServer) faceGetHandler(r *http.Request, rstat *BaseRequestStatus)
smiley, smileyOK = Smileys.Lookup(Defaults["smiley-ratelimit"])
color = Colors.Lookup(Defaults["color-ratelimit"])
} else {
user := r.Header.Get("X-Faces-User")
user := r.Header.Get(srv.userHeaderName)

if user == "" {
user = "unknown"
Expand Down Expand Up @@ -224,7 +224,7 @@ func (srv *FaceServer) faceGetHandler(r *http.Request, rstat *BaseRequestStatus)

if srv.debugEnabled {
fmt.Printf("%s %s: mapped smiley %d to %s (%s, %v)\n",
time.Now().Format(time.RFC3339), srv.Name, smileyResp.statusCode, mapped, smiley, smileyOK)
time.Now().Format(time.RFC3339), srv.Name, smileyResp.statusCode, mapped, smiley, smileyOK)
}
} else {
smiley = smileyResp.data
Expand Down
14 changes: 10 additions & 4 deletions pkg/faces/guiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ func (srv *GUIServer) guiGetHandler(w http.ResponseWriter, r *http.Request) {
start := time.Now()

fmt.Printf("%s %s: GET %s\n", time.Now().Format(time.RFC3339), srv.Name, r.URL.Path)
fmt.Printf(" userHeaderName: %s\n", srv.userHeaderName)
fmt.Printf(" headers: %s\n", r.Header)

user := r.Header.Get("x-faces-user")
user := r.Header.Get(srv.userHeaderName)
if user == "" {
user = "unknown"
}
Expand All @@ -81,6 +83,9 @@ func (srv *GUIServer) guiGetHandler(w http.ResponseWriter, r *http.Request) {
userAgent = "unknown"
}

fmt.Printf(" user: %s\n", user)
fmt.Printf(" userAgent: %s\n", userAgent)

podID := srv.hostIP
rcode := http.StatusNotFound
rtext := fmt.Sprintf("%s not found", r.URL.Path)
Expand All @@ -92,7 +97,7 @@ func (srv *GUIServer) guiGetHandler(w http.ResponseWriter, r *http.Request) {
latencyMs := end.Sub(start).Milliseconds()

w.Header().Set("Content-Type", "text/plain")
w.Header().Set("X-Faces-User", user)
w.Header().Set(srv.userHeaderName, user)
w.Header().Set("X-Faces-User-Agent", userAgent)
w.Header().Set("X-Faces-Latency", strconv.FormatInt(latencyMs, 10))
w.Header().Set("X-Faces-Pod", podID)
Expand All @@ -118,6 +123,7 @@ func (srv *GUIServer) guiGetHandler(w http.ResponseWriter, r *http.Request) {
rtext = strings.ReplaceAll(rtext, "%%{hide_key}", fmt.Sprintf("%v", srv.hideKey))
rtext = strings.ReplaceAll(rtext, "%%{show_pods}", fmt.Sprintf("%v", srv.showPods))
rtext = strings.ReplaceAll(rtext, "%%{user}", user)
rtext = strings.ReplaceAll(rtext, "%%{user_header}", fmt.Sprintf("%v", srv.userHeaderName))
rtext = strings.ReplaceAll(rtext, "%%{user_agent}", userAgent)
}
} else if strings.HasPrefix(r.URL.Path, "/face/") {
Expand All @@ -127,7 +133,7 @@ func (srv *GUIServer) guiGetHandler(w http.ResponseWriter, r *http.Request) {
reqStart := time.Now()

url := fmt.Sprintf("http://face/%s", r.URL.Path[6:])
user := r.Header.Get("x-faces-user")
user := r.Header.Get(srv.userHeaderName)
if user == "" {
user = "unknown"
}
Expand Down Expand Up @@ -202,7 +208,7 @@ func (srv *GUIServer) guiGetHandler(w http.ResponseWriter, r *http.Request) {
latencyMs := end.Sub(start).Milliseconds()

w.Header().Set("Content-Type", rtype)
w.Header().Set("X-Faces-User", user)
w.Header().Set(srv.userHeaderName, user)
w.Header().Set("X-Faces-User-Agent", userAgent)
w.Header().Set("X-Faces-Latency", strconv.FormatInt(latencyMs, 10))
w.Header().Set("X-Faces-Pod", podID)
Expand Down

0 comments on commit f2b4104

Please sign in to comment.