Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #122 from vania-pooh/master
Browse files Browse the repository at this point in the history
Added ability to show overall number of requests in /ping (fixes #121)
  • Loading branch information
aandryashin authored Oct 5, 2017
2 parents 199ebc8 + 5646427 commit c20535d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/multiple-instances.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ $ curl -s http://example.com:4444/ping
.Result
[source,javascript]
----
{"uptime":"2m46.854829503s","lastReloadTime":"2017-05-12 12:33:06.322038542 +0300 MSK"}
{"uptime":"2m46.854829503s","lastReloadTime":"2017-05-12 12:33:06.322038542 +0300 MSK","numRequests":42}
----

It returns `200 OK` when Ggr operates normally. Additionally server uptime and last quota reload time are returned in JSON format.
It returns `200 OK` when Ggr operates normally. Additionally server uptime, last quota reload time and overall number of session requests from service startup are returned in JSON format.

=== Why Ggr is Stateless
Selenium uses an HTTP-based protocol. That means every action in Selenium, e.g. launching browser or taking screenshot is a separate HTTP request. When multiple instances of Ggr are handling requests behind load balancer every request can be routed to any of these instances. Here's how it works.
Expand Down
26 changes: 18 additions & 8 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var (
quota = make(map[string]Browsers)
routes Routes = make(Routes)
num uint64
numLock sync.Mutex
numLock sync.RWMutex
confLock sync.RWMutex
)

Expand Down Expand Up @@ -150,6 +150,12 @@ func serial() uint64 {
return id
}

func getSerial() uint64 {
numLock.RLock()
defer numLock.RUnlock()
return num
}

func info(r *http.Request) (user, remote string) {
if guestAccessAllowed {
user = guestUserName
Expand Down Expand Up @@ -335,7 +341,8 @@ func ping(w http.ResponseWriter, _ *http.Request) {
json.NewEncoder(w).Encode(struct {
Uptime string `json:"uptime"`
LastReloadTime string `json:"lastReloadTime"`
}{time.Since(startTime).String(), lastReloadTime.String()})
NumRequests uint64 `json:"numRequests"`
}{time.Since(startTime).String(), lastReloadTime.String(), getSerial()})
}

func err(w http.ResponseWriter, _ *http.Request) {
Expand Down Expand Up @@ -493,12 +500,15 @@ func vnc(wsconn *websocket.Conn) {
path = vncInfo.Path
}
switch scheme {
case vncScheme: proxyVNC(wsconn, sessionId, host, port)
case wsScheme: proxyWebSockets(wsconn, sessionId, host, port, path)
default: {
log.Printf("[UNSUPPORTED_HOST_VNC_SCHEME] [%s]\n", scheme)
return
}
case vncScheme:
proxyVNC(wsconn, sessionId, host, port)
case wsScheme:
proxyWebSockets(wsconn, sessionId, host, port, path)
default:
{
log.Printf("[UNSUPPORTED_HOST_VNC_SCHEME] [%s]\n", scheme)
return
}
}
} else {
log.Printf("[UNKNOWN_VNC_HOST] [%s]\n", sum)
Expand Down
4 changes: 3 additions & 1 deletion proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestPing(t *testing.T) {
AssertThat(t, rsp, Code{http.StatusOK})
AssertThat(t, rsp.Body, Is{Not{nil}})

var data map[string]string
var data map[string]interface{}
bt, readErr := ioutil.ReadAll(rsp.Body)
AssertThat(t, readErr, Is{nil})
jsonErr := json.Unmarshal(bt, &data)
Expand All @@ -96,6 +96,8 @@ func TestPing(t *testing.T) {
AssertThat(t, hasUptime, Is{true})
_, hasLastReloadTime := data["lastReloadTime"]
AssertThat(t, hasLastReloadTime, Is{true})
_, hasNumRequests := data["numRequests"]
AssertThat(t, hasNumRequests, Is{true})
}

func TestErr(t *testing.T) {
Expand Down

0 comments on commit c20535d

Please sign in to comment.