Skip to content

Commit

Permalink
Merge pull request #252 from spiral/rr_1.6.2
Browse files Browse the repository at this point in the history
release 1.6.2
  • Loading branch information
wolfy-j authored Feb 23, 2020
2 parents 0bc6017 + 954fa52 commit b0a4a0d
Show file tree
Hide file tree
Showing 17 changed files with 1,176 additions and 85 deletions.
4 changes: 2 additions & 2 deletions .rr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static:
health:
# http host to serve health requests.
address: localhost:2113

# reload can reset rr servers when files change
reload:
# refresh internval (default 1s)
Expand All @@ -176,4 +176,4 @@ reload:
dirs: [""]

# include sub directories
recursive: true
recursive: true
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test:
go test -v -race -cover ./service/metrics
go test -v -race -cover ./service/health
go test -v -race -cover ./service/gzip
go test -v -race -cover ./service/reload
lint:
go fmt ./...
golint ./...
10 changes: 5 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cd $(dirname "${BASH_SOURCE[0]}")
OD="$(pwd)"

# Pushes application version into the build information.
RR_VERSION=1.6.1
RR_VERSION=1.6.2

# Hardcode some values to the core package
LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.Version=${RR_VERSION}"
Expand All @@ -12,7 +12,7 @@ LDFLAGS="$LDFLAGS -X github.com/spiral/roadrunner/cmd/rr/cmd.BuildTime=$(date +%
LDFLAGS="$LDFLAGS -s"

build(){
echo Packaging $1 Build
echo Packaging "$1" Build
bdir=roadrunner-${RR_VERSION}-$2-$3
rm -rf builds/"$bdir" && mkdir -p builds/"$bdir"
GOOS=$2 GOARCH=$3 ./build.sh
Expand All @@ -29,12 +29,12 @@ build(){
cd builds

if [ "$2" == "linux" ]; then
tar -zcf $bdir.tar.gz $bdir
tar -zcf "$bdir".tar.gz "$bdir"
else
zip -r -q $bdir.zip $bdir
zip -r -q "$bdir".zip "$bdir"
fi

rm -rf $bdir
rm -rf "$bdir"
cd ..
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/rr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/spiral/roadrunner/service/http"
"github.com/spiral/roadrunner/service/limit"
"github.com/spiral/roadrunner/service/metrics"
"github.com/spiral/roadrunner/service/reload"
"github.com/spiral/roadrunner/service/rpc"
"github.com/spiral/roadrunner/service/static"

Expand All @@ -51,6 +52,7 @@ func main() {
rr.Container.Register(limit.ID, &limit.Service{})
rr.Container.Register(health.ID, &health.Service{})
rr.Container.Register(gzip.ID, &gzip.Service{})
rr.Container.Register(reload.ID, &reload.Service{})

// you can register additional commands using cmd.CLI
rr.Execute()
Expand Down
6 changes: 6 additions & 0 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ type Controller interface {
// Detach pool watching.
Detach()
}

// Attacher defines the ability to attach rr controller.
type Attacher interface {
// Attach attaches controller to the service.
Attach(c Controller)
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ require (
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/olekukonko/tablewriter v0.0.4
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.4.1
Expand Down
6 changes: 6 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const (
EventPoolDestruct
)

// Controllable defines the ability to attach rr controller.
type Controllable interface {
// Server represents RR server
Server() *Server
}

// Server manages pool creation and swapping.
type Server struct {
// configures server, pool, cmd creation and factory.
Expand Down
71 changes: 0 additions & 71 deletions service/gzip/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,6 @@ func (cfg *testCfg) Unmarshal(out interface{}) error {
return json.Unmarshal([]byte(cfg.target), out)
}

//func get(url string) (string, *http.Response, error) {
// r, err := http.Get(url)
// if err != nil {
// return "", nil, err
// }
//
// b, err := ioutil.ReadAll(r.Body)
// if err != nil {
// return "", nil, err
// }
//
// err = r.Body.Close()
// if err != nil {
// return "", nil, err
// }
//
// return string(b), r, err
//}

func Test_Disabled(t *testing.T) {
logger, _ := test.NewNullLogger()
Expand All @@ -65,56 +47,3 @@ func Test_Disabled(t *testing.T) {
assert.NotNil(t, s)
assert.Equal(t, service.StatusInactive, st)
}

// func Test_Files(t *testing.T) {
// logger, _ := test.NewNullLogger()
// logger.SetLevel(logrus.DebugLevel)

// c := service.NewContainer(logger)
// c.Register(rrhttp.ID, &rrhttp.Service{})
// c.Register(ID, &Service{})

// assert.NoError(t, c.Init(&testCfg{
// gzip: `{"enable":true}`,
// static: `{"enable":true, "dir":"../../tests", "forbid":[]}`,
// httpCfg: `{
// "enable": true,
// "address": ":6029",
// "maxRequestSize": 1024,
// "uploads": {
// "dir": ` + tmpDir() + `,
// "forbid": []
// },
// "workers":{
// "command": "php ../../tests/http/client.php pid pipes",
// "relay": "pipes",
// "pool": {
// "numWorkers": 1,
// "allocateTimeout": 10000000,
// "destroyTimeout": 10000000
// }
// }
// }`}))

// go func() {
// err := c.Serve()
// if err != nil {
// t.Errorf("serve error: %v", err)
// }
// }()
// time.Sleep(time.Millisecond * 1000)
// defer c.Stop()

// b, _, _ := get("http://localhost:6029/sample.txt")
// assert.Equal(t, "sample", b)
// //header should not contain content-encoding:gzip because content-length < gziphandler.DefaultMinSize
// // b, _, _ := get("http://localhost:6029/gzip-large-file.txt")
// //header should contain content-encoding:gzip because content-length > gziphandler.DefaultMinSize
// }

//func tmpDir() string {
// p := os.TempDir()
// r, _ := json.Marshal(p)
//
// return string(r)
//}
8 changes: 1 addition & 7 deletions service/limit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import (
// ID defines controller service name.
const ID = "limit"

// controllable defines the ability to attach rr controller.
type controllable interface {
// Attach attaches controller to the service.
Attach(c roadrunner.Controller)
}

// Service to control the state of rr service inside other services.
type Service struct {
lsns []func(event int, ctx interface{})
Expand All @@ -24,7 +18,7 @@ func (s *Service) Init(cfg *Config, c service.Container) (bool, error) {
// mount Services to designated services
for id, watcher := range cfg.Controllers(s.throw) {
svc, _ := c.Get(id)
if ctrl, ok := svc.(controllable); ok {
if ctrl, ok := svc.(roadrunner.Attacher); ok {
ctrl.Attach(watcher)
}
}
Expand Down
66 changes: 66 additions & 0 deletions service/reload/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package reload

import (
"errors"
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/service"
"time"
)

// Config is a Reload configuration point.
type Config struct {
// Interval is a global refresh interval
Interval time.Duration

// Patterns is a global file patterns to watch. It will be applied to every directory in project
Patterns []string

// Services is set of services which would be reloaded in case of FS changes
Services map[string]ServiceConfig
}

type ServiceConfig struct {
// Enabled indicates that service must be watched, doest not required when any other option specified
Enabled bool

// Recursive is options to use nested files from root folder
Recursive bool

// Patterns is per-service specific files to watch
Patterns []string

// Dirs is per-service specific dirs which will be combined with Patterns
Dirs []string

// Ignore is set of files which would not be watched
Ignore []string

// service is a link to service to restart
service *roadrunner.Controllable
}

// Hydrate must populate Config values using given Config source. Must return error if Config is not valid.
func (c *Config) Hydrate(cfg service.Config) error {
if err := cfg.Unmarshal(c); err != nil {
return err
}

return nil
}

// InitDefaults sets missing values to their default values.
func (c *Config) InitDefaults() error {
c.Interval = time.Second
c.Patterns = []string{".php"}

return nil
}

// Valid validates the configuration.
func (c *Config) Valid() error {
if c.Interval < time.Second {
return errors.New("too short interval")
}

return nil
}
55 changes: 55 additions & 0 deletions service/reload/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package reload

import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func Test_Config_Valid(t *testing.T) {
services := make(map[string]ServiceConfig)
services["test"] = ServiceConfig{
Recursive: false,
Patterns: nil,
Dirs: nil,
Ignore: nil,
service: nil,
}

cfg := &Config{
Interval: time.Second,
Patterns: nil,
Services: services,
}
assert.NoError(t, cfg.Valid())
}

func Test_Fake_ServiceConfig(t *testing.T) {
services := make(map[string]ServiceConfig)
cfg := &Config{
Interval: time.Second,
Patterns: nil,
Services: services,
}
assert.Error(t, cfg.Valid())
}

func Test_Interval(t *testing.T) {
services := make(map[string]ServiceConfig)
cfg := &Config{
Interval: time.Millisecond,
Patterns: nil,
Services: services,
}
assert.Error(t, cfg.Valid())
}

func Test_NoServiceConfig(t *testing.T) {
services := make(map[string]ServiceConfig)
cfg := &Config{
Interval: time.Millisecond,
Patterns: nil,
Services: services,
}
assert.Error(t, cfg.Valid())
}
9 changes: 9 additions & 0 deletions service/reload/samefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build !windows

package reload

import "os"

func sameFile(fi1, fi2 os.FileInfo) bool {
return os.SameFile(fi1, fi2)
}
12 changes: 12 additions & 0 deletions service/reload/samefile_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build windows

package reload

import "os"

func sameFile(fi1, fi2 os.FileInfo) bool {
return fi1.ModTime() == fi2.ModTime() &&
fi1.Size() == fi2.Size() &&
fi1.Mode() == fi2.Mode() &&
fi1.IsDir() == fi2.IsDir()
}
Loading

0 comments on commit b0a4a0d

Please sign in to comment.