Skip to content

Commit

Permalink
Merge pull request #25 from BuoyantIO/flynn/dev/split-requests
Browse files Browse the repository at this point in the history
Make requests include /center/ or /edge/ depending on which cell is in play.
  • Loading branch information
kflynn committed Sep 11, 2024
2 parents b41afc0 + e641292 commit b170446
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion assets/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,10 @@ <H1>Faces</H1>

for (row = 0; row < 4; row++) {
for (col = 0; col < 4; col++) {
let cell = new Cell(logger, sw, podSet, `../face/cell/`, $("cells"), row, col)
let isCenter = ((row === 1 || row === 2) && (col === 1 || col === 2))
let cellURL = isCenter ? `../face/center/` : `../face/edge/`

let cell = new Cell(logger, sw, podSet, cellURL, $("cells"), row, col)
cells.push(cell)
}
$("cells").innerHTML += "<br/>"
Expand Down
13 changes: 9 additions & 4 deletions pkg/faces/faceserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"time"

"github.com/BuoyantIO/faces-demo/v2/pkg/utils"
Expand Down Expand Up @@ -63,10 +64,10 @@ func (srv *FaceServer) SetupFromEnvironment() {
fmt.Printf("%s %s: colorService %v\n", time.Now().Format(time.RFC3339), srv.Name, srv.colorService)
}

func (srv *FaceServer) makeRequest(user string, userAgent string, service string, keyword string) *FaceResponse {
func (srv *FaceServer) makeRequest(user string, userAgent string, service string, keyword string, subrequest string) *FaceResponse {
start := time.Now()

url := fmt.Sprintf("http://%s/", service)
url := fmt.Sprintf("http://%s/%s/", service, subrequest)

if srv.debugEnabled {
fmt.Printf("%s %s: %s starting\n", time.Now().Format(time.RFC3339), srv.Name, url)
Expand Down Expand Up @@ -178,6 +179,10 @@ func (srv *FaceServer) faceGetHandler(r *http.Request, rstat *BaseRequestStatus)
StatusCode: http.StatusOK,
}

// Our request URL should start with /center/ or /edge/, and we want to
// propagate that to our smiley and color services.
subrequest := strings.Split(r.URL.Path, "/")[1]

errors := []string{}
var smiley string
var color string
Expand Down Expand Up @@ -207,11 +212,11 @@ func (srv *FaceServer) faceGetHandler(r *http.Request, rstat *BaseRequestStatus)
colorCh := make(chan *FaceResponse)

go func() {
smileyCh <- srv.makeRequest(user, userAgent, srv.smileyService, "smiley")
smileyCh <- srv.makeRequest(user, userAgent, srv.smileyService, "smiley", subrequest)
}()

go func() {
colorCh <- srv.makeRequest(user, userAgent, srv.colorService, "color")
colorCh <- srv.makeRequest(user, userAgent, srv.colorService, "color", subrequest)
}()

// Wait for the responses from both services
Expand Down

0 comments on commit b170446

Please sign in to comment.