Skip to content

Commit

Permalink
Merge latest changes from develop (#2)
Browse files Browse the repository at this point in the history
* Init commit

* Project refactoring

* Code refactoring, unit tests coverage

* Fix docker file. Packages update. Tests refactoring

* Added custom header for logging purposes

* Added graceful shodown

* Added devtools handler

* Added new routes. Code refactoring

* Added status handler

* README update

* Fixed README table

* README update

* Added defaultVersion support for browsers. Graceful shutdown prop update

* Fix typos in README

* Added config watcher, active session limits, status handler, logs handler. Fixed vnc handler error

* Added missed Total prop to status handler

* Forced to use default browser version in case empty browser version recieved

* Added healthz handler

* README update
  • Loading branch information
alcounit authored Nov 10, 2020
1 parent 781ad41 commit 8eca4c8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Flags:
--port string port for selenosis (default ":4444")
--proxy-port string proxy continer port (default "4445")
--browsers-config string browsers config (default "config/browsers.yaml")
--browser-limit int active sessions max limit (default 10)
--namespace string kubernetes namespace (default "default")
--service-name string kubernetes service name for browsers (default "selenosis")
--browser-wait-timeout duration time in seconds that a browser will be ready (default 30s)
Expand All @@ -35,6 +36,8 @@ Flags:
| WS/HTTP | /devtools/{sessionId} |
| HTTP | /download/{sessionId} |
| HTTP | /clipboard/{sessionId} |
| HTTP | /status |
| HTTP | /healthz |
<br/>

## Configuration
Expand Down Expand Up @@ -434,4 +437,7 @@ spec:
Selenosis doesn't store any session info. All connections to the browsers are automatically assigned via headless service.

### Hot config reload
Once you decide to update in browsers config
Selenosis supports hot config reload, to do so update you configMap
```bash
kubectl edit configmap -n selenosis selenosis-config -o yaml
```
3 changes: 3 additions & 0 deletions cmd/selenosis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func command() *cobra.Command {
router.PathPrefix("/download/{sessionId}").HandlerFunc(app.HandleReverseProxy)
router.PathPrefix("/clipboard/{sessionId}").HandlerFunc(app.HandleReverseProxy)
router.PathPrefix("/status").HandlerFunc(app.HandleStatus)
router.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}).Methods(http.MethodGet)

srv := &http.Server{
Addr: address,
Expand Down
5 changes: 4 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ func (cfg *BrowsersConfig) Find(name, version string) (*platform.BrowserSpec, er
if !ok {
return nil, fmt.Errorf("unknown browser version %s", version)
}
v.BrowserName = name
v.BrowserVersion = c.DefaultVersion
return v, nil
}
return nil, fmt.Errorf("unknown browser version %s", version)
}

v.BrowserName = name
v.BrowserVersion = version
return v, nil
}

Expand Down
18 changes: 9 additions & 9 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,15 @@ func (app *App) HandleStatus(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")

type Status struct {
Browsers map[string][]string `json:"config"`
Sessions []*platform.Service `json:"sessions"`
Total int `json:"total"`
Browsers map[string][]string `json:"config,omitempty"`
Sessions []*platform.Service `json:"sessions,omitempty"`
}

type Response struct {
Status int `json:"status"`
Error error `json:"err"`
Selenosis Status `json:"selenosis"`
Error string `json:"err,omitempty"`
Selenosis Status `json:"selenosis,omitempty"`
}

sessions, err := app.client.List()
Expand All @@ -362,27 +363,26 @@ func (app *App) HandleStatus(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(
Response{
Status: http.StatusInternalServerError,
Error: err,
Error: fmt.Sprintf("%v", err),
Selenosis: Status{
Total: app.sessionLimit,
Browsers: app.browsers.GetBrowserVersions(),
},
},
)
return
}

err = json.NewEncoder(w).Encode(
json.NewEncoder(w).Encode(
Response{
Status: http.StatusOK,
Selenosis: Status{
Total: app.sessionLimit,
Browsers: app.browsers.GetBrowserVersions(),
Sessions: sessions,
},
},
)
if err != nil {
w.Write([]byte(fmt.Sprintf("marshal err: %v", err)))
}
return
}

Expand Down
4 changes: 2 additions & 2 deletions platform/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func (cl *Client) Create(layout *ServiceSpec) (*Service, error) {

labels := map[string]string{
defaults.serviceType: "browser",
defaults.browserName: layout.RequestedCapabilities.BrowserName,
defaults.browserVersion: layout.RequestedCapabilities.BrowserVersion,
defaults.browserName: layout.Template.BrowserName,
defaults.browserVersion: layout.Template.BrowserVersion,
defaults.testName: layout.RequestedCapabilities.TestName,
defaults.session: layout.SessionID,
}
Expand Down
10 changes: 6 additions & 4 deletions platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ type Spec struct {

//BrowserSpec describes settings for Service
type BrowserSpec struct {
Image string `yaml:"image" json:"image"`
Path string `yaml:"path" json:"path"`
Meta Meta `yaml:"meta" json:"meta"`
Spec Spec `yaml:"spec" json:"spec"`
BrowserName string `yaml:"-" json:"-"`
BrowserVersion string `yaml:"-" json:"-"`
Image string `yaml:"image" json:"image"`
Path string `yaml:"path" json:"path"`
Meta Meta `yaml:"meta" json:"meta"`
Spec Spec `yaml:"spec" json:"spec"`
}

//ServiceSpec describes data requred for creating service
Expand Down

0 comments on commit 8eca4c8

Please sign in to comment.