Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14
FROM golang:1.15

ENV SQUASHFUSE_VERSION=0.1.103 \
GOPROXY=https://proxy.golang.org
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Dependencies

- Golang version 1.14.
- Golang version 1.15.
- docker 17.03+ and docker-compose (`pip install docker-compose`).

## Testing
Expand Down
4 changes: 2 additions & 2 deletions app/broker/celery.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

scriptpb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/script/v1"

"github.com/Syncano/pkg-go/celery"
"github.com/Syncano/pkg-go/util"
"github.com/Syncano/pkg-go/v2/celery"
"github.com/Syncano/pkg-go/v2/util"
)

var (
Expand Down
23 changes: 15 additions & 8 deletions app/broker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

"github.com/imdario/mergo"
"github.com/sirupsen/logrus"
"go.opencensus.io/plugin/ocgrpc"
"go.opencensus.io/stats"
Expand All @@ -17,8 +18,8 @@ import (
"google.golang.org/grpc/metadata"

"github.com/Syncano/codebox/app/common"
"github.com/Syncano/pkg-go/celery"
"github.com/Syncano/pkg-go/util"
"github.com/Syncano/pkg-go/v2/celery"
"github.com/Syncano/pkg-go/v2/util"
brokerpb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/broker/v1"
repopb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/filerepo/v1"
lbpb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/lb/v1"
Expand All @@ -36,7 +37,7 @@ type Server struct {
uploads map[string]chan struct{}
downloader util.Downloader

options ServerOptions
options *ServerOptions
}

type loadBalancer struct {
Expand All @@ -60,7 +61,7 @@ type ServerOptions struct {
}

// DefaultOptions holds default options values for Broker server.
var DefaultOptions = &ServerOptions{
var DefaultOptions = ServerOptions{
DownloadConcurrency: 16,
LBRetry: 3,
MaxPayloadSize: 15 << 20,
Expand Down Expand Up @@ -90,7 +91,13 @@ const (
)

// NewServer initializes new Broker server.
func NewServer(redisClient RedisClient, cel *celery.Celery, options *ServerOptions) (*Server, error) {
func NewServer(redisClient RedisClient, cel *celery.Celery, opts *ServerOptions) (*Server, error) {
options := DefaultOptions

if opts != nil {
_ = mergo.Merge(&options, opts, mergo.WithOverride)
}

// Register prometheus exports.
initOnce.Do(func() {
util.Must(view.Register(overheadDurationView))
Expand Down Expand Up @@ -121,14 +128,14 @@ func NewServer(redisClient RedisClient, cel *celery.Celery, options *ServerOptio
cel: cel,
lbServers: lbServers,
uploads: make(map[string]chan struct{}),
downloader: util.NewDownloader(&util.DownloaderOptions{Concurrency: options.DownloadConcurrency}),
options: *options,
downloader: util.NewDownloader(util.WithConcurrency(options.DownloadConcurrency)),
options: &options,
}, nil
}

// Options returns a copy of Broker options struct.
func (s *Server) Options() ServerOptions {
return s.options
return *s.options
}

// Shutdown stops gracefully Broker server.
Expand Down
14 changes: 7 additions & 7 deletions app/broker/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import (
"github.com/Syncano/codebox/app/common"
repomocks "github.com/Syncano/codebox/app/filerepo/mocks"
lbmocks "github.com/Syncano/codebox/app/lb/mocks"
"github.com/Syncano/pkg-go/celery"
celerymocks "github.com/Syncano/pkg-go/celery/mocks"
"github.com/Syncano/pkg-go/util"
utilmocks "github.com/Syncano/pkg-go/util/mocks"
"github.com/Syncano/pkg-go/v2/celery"
celerymocks "github.com/Syncano/pkg-go/v2/celery/mocks"
"github.com/Syncano/pkg-go/v2/util"
utilmocks "github.com/Syncano/pkg-go/v2/util/mocks"
brokerpb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/broker/v1"
repopb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/filerepo/v1"
lbpb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/lb/v1"
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestServerMethods(t *testing.T) {
celery.New(amqpCh),
&ServerOptions{
LBAddr: []string{"127.0.0.1"},
LBRetry: 0,
LBRetry: -1,
DownloadConcurrency: 1,
})
So(e, ShouldBeNil)
Expand All @@ -78,8 +78,8 @@ func TestServerMethods(t *testing.T) {
s.lbServers[0].repoCli = repoCli

Convey("Options returns a copy of options struct", func() {
So(s.Options(), ShouldNotEqual, s.options)
So(s.Options(), ShouldResemble, s.options)
So(s.Options(), ShouldNotEqual, *s.options)
So(s.Options(), ShouldResemble, *s.options)
})
Convey("Run returns error on invalid request", func() {
stream.On("Context").Return(context.Background())
Expand Down
2 changes: 1 addition & 1 deletion app/broker/uwsgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/vmihailenco/msgpack/v4"

"github.com/Syncano/codebox/app/common"
"github.com/Syncano/pkg-go/util"
"github.com/Syncano/pkg-go/v2/util"
brokerpb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/broker/v1"
lbpb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/lb/v1"
scriptpb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/script/v1"
Expand Down
18 changes: 9 additions & 9 deletions app/docker/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
type StdManager struct {
client Client
storageLimitSupported bool
options Options
options *Options
info types.Info
runtime string
}
Expand All @@ -36,7 +36,7 @@ type Options struct {
}

// DefaultOptions holds default options values for docker manager.
var DefaultOptions = &Options{
var DefaultOptions = Options{
BlkioDevice: "/dev/sda",
Network: "isolated_nw",
NetworkSubnet: "172.25.0.0/16",
Expand Down Expand Up @@ -72,11 +72,11 @@ const (
)

// NewManager initializes a new manager for docker.
func NewManager(options *Options, cli Client) (*StdManager, error) {
if options != nil {
mergo.Merge(options, DefaultOptions) // nolint - error not possible
} else {
options = DefaultOptions
func NewManager(opts *Options, cli Client) (*StdManager, error) {
options := DefaultOptions

if opts != nil {
_ = mergo.Merge(&options, opts, mergo.WithOverride)
}

// Get and save Info from docker.
Expand All @@ -90,7 +90,7 @@ func NewManager(options *Options, cli Client) (*StdManager, error) {

m := StdManager{
client: cli,
options: *options,
options: &options,
info: info,
runtime: gvisorRuntime,
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func NewManager(options *Options, cli Client) (*StdManager, error) {

// Options returns a copy of manager options struct.
func (m *StdManager) Options() Options {
return m.options
return *m.options
}

// Info returns a copy of docker info struct.
Expand Down
6 changes: 3 additions & 3 deletions app/docker/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ func (mc mockReadCloser) Close() error { return mc.closeErr }
func TestManagerMethods(t *testing.T) {
Convey("Given manager with mocked docker client", t, func() {
cli := new(MockClient)
m := StdManager{client: cli}
m := StdManager{client: cli, options: &Options{}}

Convey("Options returns a copy of options struct", func() {
So(m.Options(), ShouldNotEqual, m.options)
So(m.Options(), ShouldResemble, m.options)
So(m.Options(), ShouldNotEqual, *m.options)
So(m.Options(), ShouldResemble, *m.options)
})

Convey("Info returns a copy of info struct", func() {
Expand Down
35 changes: 18 additions & 17 deletions app/filerepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/afero"

"github.com/Syncano/pkg-go/cache"
"github.com/Syncano/pkg-go/sys"
"github.com/Syncano/pkg-go/util"
"github.com/Syncano/pkg-go/v2/cache"
"github.com/Syncano/pkg-go/v2/sys"
"github.com/Syncano/pkg-go/v2/util"
)

// FsRepo provides methods to store files and manipulate volumes.
type FsRepo struct {
storeID string
fileCache *cache.LRUCache
options Options
options *Options
sys sys.SystemChecker
fs Fs
command Commander
Expand All @@ -48,7 +48,7 @@ type Options struct {
}

// DefaultOptions holds default options values for file repo.
var DefaultOptions = &Options{
var DefaultOptions = Options{
BasePath: "/home/codebox/storage",
MaxDiskUsage: 90,
TTL: 3 * time.Hour,
Expand Down Expand Up @@ -77,18 +77,18 @@ const (
)

// New initializes a new file repo.
func New(options *Options, checker sys.SystemChecker, fs Fs, command Commander) *FsRepo {
if options != nil {
mergo.Merge(options, DefaultOptions) // nolint - error not possible
} else {
options = DefaultOptions
func New(opts *Options, checker sys.SystemChecker, fs Fs, command Commander) *FsRepo {
options := DefaultOptions

if opts != nil {
_ = mergo.Merge(&options, opts, mergo.WithOverride)
}

util.Must(fs.MkdirAll(options.BasePath, os.ModePerm))

r := FsRepo{
storeID: util.GenerateKey(),
options: *options,
options: &options,
sys: checker,
fs: fs,
command: command,
Expand All @@ -97,11 +97,12 @@ func New(options *Options, checker sys.SystemChecker, fs Fs, command Commander)
storeLocks: make(map[string]chan struct{}),
}

r.fileCache = cache.NewLRUCache(&cache.Options{
TTL: options.TTL,
CleanupInterval: options.CleanupInterval,
Capacity: options.Capacity,
}, &cache.LRUOptions{})
r.fileCache = cache.NewLRUCache(
true,
cache.WithTTL(options.TTL),
cache.WithCleanupInterval(options.CleanupInterval),
cache.WithCapacity(options.Capacity),
)

r.fileCache.OnValueEvicted(r.onValueEvictedHandler)

Expand All @@ -110,7 +111,7 @@ func New(options *Options, checker sys.SystemChecker, fs Fs, command Commander)

// Options returns a copy of options struct.
func (r *FsRepo) Options() Options {
return r.options
return *r.options
}

// GetFS returns FS used by repo.
Expand Down
14 changes: 7 additions & 7 deletions app/filerepo/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/mock"

"github.com/Syncano/pkg-go/sys/mocks"
"github.com/Syncano/pkg-go/v2/sys/mocks"
)

func verifyFile(filepath, content string) {
Expand All @@ -33,11 +33,11 @@ func TestRepo(t *testing.T) {
repo := New(&opts, sc, new(LinkFs), new(Command))

Convey("related options are properly set up", func() {
cacheOpts := repo.fileCache.Options()
cacheCfg := repo.fileCache.Config()

So(cacheOpts.CleanupInterval, ShouldEqual, opts.CleanupInterval)
So(cacheOpts.Capacity, ShouldEqual, opts.Capacity)
So(cacheOpts.TTL, ShouldEqual, opts.TTL)
So(cacheCfg.CleanupInterval, ShouldEqual, opts.CleanupInterval)
So(cacheCfg.Capacity, ShouldEqual, opts.Capacity)
So(cacheCfg.TTL, ShouldEqual, opts.TTL)

So(repo.storeID, ShouldNotBeBlank)
storagePath := repo.StoragePath()
Expand Down Expand Up @@ -311,8 +311,8 @@ func TestRepo(t *testing.T) {
})

Convey("Options returns a copy of options struct", func() {
So(repo.Options(), ShouldNotEqual, repo.options)
So(repo.Options(), ShouldResemble, repo.options)
So(repo.Options(), ShouldNotEqual, *repo.options)
So(repo.Options(), ShouldResemble, *repo.options)
})

Convey("RelativePath returns path relative to BasePath", func() {
Expand Down
2 changes: 1 addition & 1 deletion app/filerepo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/Syncano/pkg-go/util"
"github.com/Syncano/pkg-go/v2/util"
pb "github.com/Syncano/syncanoapis/gen/go/syncano/codebox/filerepo/v1"
)

Expand Down
2 changes: 1 addition & 1 deletion app/lb/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.opencensus.io/metric/metricproducer"

"github.com/Syncano/codebox/internal/metrics"
"github.com/Syncano/pkg-go/util"
"github.com/Syncano/pkg-go/v2/util"
)

var (
Expand Down
Loading