From 10f190d7f4c81c53fd861143188d24f5ac49ef11 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 23 Mar 2022 10:15:27 +0100 Subject: [PATCH] make nats jetstream store dir configurable --- audit/pkg/command/server.go | 5 +---- go.mod | 4 ++-- go.sum | 12 ++++-------- nats/pkg/command/server.go | 11 ++++++++--- nats/pkg/config/config.go | 5 +++-- nats/pkg/config/defaults/defaultconfig.go | 12 +++++++++--- nats/pkg/server/nats/nats.go | 23 +++++++++++------------ nats/pkg/server/nats/options.go | 20 +++++++++++++++----- notifications/pkg/command/server.go | 5 +---- 9 files changed, 54 insertions(+), 43 deletions(-) diff --git a/audit/pkg/command/server.go b/audit/pkg/command/server.go index b440932255c..74518348da4 100644 --- a/audit/pkg/command/server.go +++ b/audit/pkg/command/server.go @@ -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 } diff --git a/go.mod b/go.mod index 83fbe7e23e5..411cf1b282a 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 47e5dc8fd7c..bfd19c11cfc 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= @@ -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= @@ -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= diff --git a/nats/pkg/command/server.go b/nats/pkg/command/server.go index 84b24692d72..c29069f1ec9 100644 --- a/nats/pkg/command/server.go +++ b/nats/pkg/command/server.go @@ -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 diff --git a/nats/pkg/config/config.go b/nats/pkg/config/config.go index bc8d670fc34..4793831df33 100644 --- a/nats/pkg/config/config.go +++ b/nats/pkg/config/config.go @@ -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"` } diff --git a/nats/pkg/config/defaults/defaultconfig.go b/nats/pkg/config/defaults/defaultconfig.go index 03f5167b3e0..ac7215dff76 100644 --- a/nats/pkg/config/defaults/defaultconfig.go +++ b/nats/pkg/config/defaults/defaultconfig.go @@ -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 @@ -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"), }, } } diff --git a/nats/pkg/server/nats/nats.go b/nats/pkg/server/nats/nats.go index ffb5363c8fe..e7717d6449d 100644 --- a/nats/pkg/server/nats/nats.go +++ b/nats/pkg/server/nats/nats.go @@ -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 } diff --git a/nats/pkg/server/nats/options.go b/nats/pkg/server/nats/options.go index 2b2d23e30b9..cceb83ec406 100644 --- a/nats/pkg/server/nats/options.go +++ b/nats/pkg/server/nats/options.go @@ -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 + } +} diff --git a/notifications/pkg/command/server.go b/notifications/pkg/command/server.go index 6c3f9f32b0c..df4c49b694c 100644 --- a/notifications/pkg/command/server.go +++ b/notifications/pkg/command/server.go @@ -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 }