Skip to content

Commit

Permalink
make nats jetstream store dir configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek committed Mar 23, 2022
1 parent 6d0ac68 commit 10f190d
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 43 deletions.
5 changes: 1 addition & 4 deletions audit/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ func Server(cfg *config.Config) *cli.Command {
if err != nil {
return err
}
evts, err := events.Consume(
client, evtsCfg.ConsumerGroup,
types.RegisteredEvents()...,
)
evts, err := events.Consume(client, evtsCfg.ConsumerGroup, types.RegisteredEvents()...)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ require (
github.com/hashicorp/go-plugin v1.4.3 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/raft v1.3.6 // indirect
github.com/hashicorp/raft v1.3.3 // indirect
github.com/hashicorp/serf v0.9.6 // indirect
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
Expand Down Expand Up @@ -209,7 +209,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/nats-io/jwt/v2 v2.2.1-0.20220113022732-58e87895b296 // indirect
github.com/nats-io/nats-streaming-server v0.24.3 // indirect
github.com/nats-io/nats-streaming-server v0.24.1 // indirect
github.com/nats-io/nats.go v1.13.1-0.20220308171302-2f2f6968e98d // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
Expand Down
12 changes: 4 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD9
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19 h1:1jqPH58jCxvbaJ9WLIJ7W2/m622bWS6ChptzljSG6IQ=
github.com/cs3org/go-cs3apis v0.0.0-20220126114148-64c025ccdd19/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva/v2 v2.0.0-20220316045927-99115670eb33 h1:XK88Fs9FteY9a+iKXqPhUK38zNQbP1jj60zy+Tx7SPI=
github.com/cs3org/reva/v2 v2.0.0-20220316045927-99115670eb33/go.mod h1:XNtK1HEClNzmz5vyQa2DUw4KH3oqBjQoEsV1LhAGlV0=
github.com/cs3org/reva/v2 v2.0.0-20220321093112-25cedab9f739 h1:GD8ZoMqRKclM0dP5hjSMXals9vRWHPH2hOeBruCuQlg=
github.com/cs3org/reva/v2 v2.0.0-20220321093112-25cedab9f739/go.mod h1:XNtK1HEClNzmz5vyQa2DUw4KH3oqBjQoEsV1LhAGlV0=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down Expand Up @@ -817,9 +817,8 @@ github.com/hashicorp/memberlist v0.2.4/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn
github.com/hashicorp/memberlist v0.3.0 h1:8+567mCcFDnS5ADl7lrpxPMWiFCElyUEeW0gtj34fMA=
github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
github.com/hashicorp/raft v1.3.1/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM=
github.com/hashicorp/raft v1.3.3 h1:Xr6DSHC5cIM8kzxu+IgoT/+MeNeUNeWin3ie6nlSrMg=
github.com/hashicorp/raft v1.3.3/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM=
github.com/hashicorp/raft v1.3.6 h1:v5xW5KzByoerQlN/o31VJrFNiozgzGyDoMgDJgXpsto=
github.com/hashicorp/raft v1.3.6/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
github.com/hashicorp/serf v0.9.6 h1:uuEX1kLR6aoda1TBttmJQKDLZE1Ob7KN0NPdE7EtCDc=
Expand Down Expand Up @@ -1082,9 +1081,8 @@ github.com/nats-io/nats-server/v2 v2.7.2/go.mod h1:tckmrt0M6bVaDT3kmh9UrIq/CBOBB
github.com/nats-io/nats-server/v2 v2.7.4 h1:c+BZJ3rGzUKCBIM4IXO8uNT2u1vajGbD1kPA6wqCEaM=
github.com/nats-io/nats-server/v2 v2.7.4/go.mod h1:1vZ2Nijh8tcyNe8BDVyTviCd9NYzRbubQYiEHsvOQWc=
github.com/nats-io/nats-streaming-server v0.23.0/go.mod h1:1asNNRpUKbgwoPqRLEWbJE65uqmWjG1YN/Xlo3WgkTY=
github.com/nats-io/nats-streaming-server v0.24.1 h1:autzhooN72ELtqP3alC2OPzmrbiA6jIZaQmKdLQsckk=
github.com/nats-io/nats-streaming-server v0.24.1/go.mod h1:N2Q05hKD+aW2Ur1VYP85yUR2zUWHbqJG88CxAFLRrd4=
github.com/nats-io/nats-streaming-server v0.24.3 h1:uZez8jBkXscua++jaDsK7DhpSAkizdetar6yWbPMRco=
github.com/nats-io/nats-streaming-server v0.24.3/go.mod h1:rqWfyCbxlhKj//fAp8POdQzeADwqkVhZcoWlbhkuU5w=
github.com/nats-io/nats.go v1.10.0/go.mod h1:AjGArbfyR50+afOUotNX2Xs5SYHf+CoOa5HH1eEl2HE=
github.com/nats-io/nats.go v1.11.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
github.com/nats-io/nats.go v1.13.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
Expand Down Expand Up @@ -1558,7 +1556,6 @@ golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220314234724-5d542ad81a58 h1:L8CkJyVoa0/NslN3RUMLgasK5+KatNvyRGQ9QyCYAfc=
golang.org/x/crypto v0.0.0-20220314234724-5d542ad81a58/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -1826,7 +1823,6 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220307203707-22a9840ba4d7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201113234701-d7a72108b828/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand Down
11 changes: 8 additions & 3 deletions nats/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ func Server(cfg *config.Config) *cli.Command {
natsServer, err := nats.NewNATSServer(
ctx,
logging.NewLogWrapper(logger),
nats.Host(cfg.Nats.Host),
nats.Port(cfg.Nats.Port),
nats.ClusterID("ocis-cluster"),
[]nats.NatsOption{
nats.Host(cfg.Nats.Host),
nats.Port(cfg.Nats.Port),
nats.ClusterID("ocis-cluster"),
},
[]nats.JetStreamOption{
nats.JetStreamStoreDir(cfg.Nats.StoreDir),
},
)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions nats/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Config struct {

// Nats is the nats config
type Nats struct {
Host string `ocisConfig:"host" env:"NATS_NATS_HOST"`
Port int `ocisConfig:"port" env:"NATS_NATS_PORT"`
Host string `ocisConfig:"host" env:"NATS_NATS_HOST"`
Port int `ocisConfig:"port" env:"NATS_NATS_PORT"`
StoreDir string `ocisConfig:"store_dir" env:"NATS_NATS_STORE_DIR"`
}
12 changes: 9 additions & 3 deletions nats/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package defaults

import "github.com/owncloud/ocis/nats/pkg/config"
import (
"path"

"github.com/owncloud/ocis/nats/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
)

// NOTE: Most of this configuration is not needed to keep it as simple as possible
// TODO: Clean up unneeded configuration
Expand All @@ -20,8 +25,9 @@ func DefaultConfig() *config.Config {
Name: "nats",
},
Nats: config.Nats{
Host: "127.0.0.1",
Port: 9233,
Host: "127.0.0.1",
Port: 9233,
StoreDir: path.Join(defaults.BaseDataPath(), "nats"),
},
}
}
Expand Down
23 changes: 11 additions & 12 deletions nats/pkg/server/nats/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,28 @@ type NATSServer struct {
server *nserver.Server
}

func NewNATSServer(ctx context.Context, logger nserver.Logger, opts ...Option) (*NATSServer, error) {
options := &nserver.Options{}
func NewNATSServer(ctx context.Context, logger nserver.Logger, natsOpts []NatsOption, jetstreamOpts []JetStreamOption) (*NATSServer, error) {
natsOptions := &nserver.Options{}
jetStreamOptions := &nserver.JetStreamConfig{}

for _, o := range opts {
o(options)
for _, o := range natsOpts {
o(natsOptions)
}

server, err := nserver.NewServer(
options,
)
for _, o := range jetstreamOpts {
o(jetStreamOptions)
}

server, err := nserver.NewServer(natsOptions)
if err != nil {
return nil, err
}

server.SetLoggerV2(logger, true, true, false)

c := &nserver.JetStreamConfig{
StoreDir: "/tmp/ocis-jetstream", // TODO: configurable
}

return &NATSServer{
ctx: ctx,
jetStreamConfig: c,
jetStreamConfig: jetStreamOptions,
server: server,
}, nil
}
Expand Down
20 changes: 15 additions & 5 deletions nats/pkg/server/nats/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,36 @@ import (
nserver "github.com/nats-io/nats-server/v2/server"
)

// Option configures the nats server
type Option func(*nserver.Options)
// NatsOption configures the nats server
type NatsOption func(*nserver.Options)

// Host sets the host URL for the nats server
func Host(url string) Option {
func Host(url string) NatsOption {
return func(o *nserver.Options) {
o.Host = url
}
}

// Port sets the host URL for the nats server
func Port(port int) Option {
func Port(port int) NatsOption {
return func(o *nserver.Options) {
o.Port = port
}
}

// ClusterID sets the name for the nats cluster
func ClusterID(clusterID string) Option {
func ClusterID(clusterID string) NatsOption {
return func(o *nserver.Options) {
o.Cluster.Name = clusterID
}
}

// NatsOption configures the nats server
type JetStreamOption func(*nserver.JetStreamConfig)

// ClusterID sets the name for the nats cluster
func JetStreamStoreDir(StoreDir string) JetStreamOption {
return func(o *nserver.JetStreamConfig) {
o.StoreDir = StoreDir
}
}
5 changes: 1 addition & 4 deletions notifications/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ func Server(cfg *config.Config) *cli.Command {
if err != nil {
return err
}
evts, err := events.Consume(
client, evtsCfg.ConsumerGroup,
evs...,
)
evts, err := events.Consume(client, evtsCfg.ConsumerGroup, evs...)
if err != nil {
return err
}
Expand Down

0 comments on commit 10f190d

Please sign in to comment.