fix(postprocessing,storage-users): NATS再送による重複処理を解消する
ワーカーが埋まっている間に順番待ちしている後続イベントがAckWait超過で再送され、多重処理されていた問題に対処する。 - ocis-pkg/natsconsumer: durableコンシューマーのAckWait/MaxDeliverをサーバー側の更新APIで反映するヘルパーを追加。購読オプションで渡すと再起動時にconfig不一致で起動できなくなるため。 - ocis-pkg/eventdedup: 同一イベントIDの再送を破棄するフィルターを追加。 - postprocessing/storage-users: AckWait(既定30分)/MaxDelivery(既定3)/並行数/重複排除ウィンドウの設定と環境変数を追加し、起動時にコンシューマー設定を反映。
This commit is contained in:
1 parent
b690f4eb8f
commit
456dc232cb
11 files changed
+649
-39
No files matched your search
@@ -0,0 +1,86 @@
|
||||
// Package eventdedup drops redelivered copies of events.
|
||||
//
|
||||
// JetStream redelivers a message when its ack does not arrive within AckWait.
|
||||
// With reva's event consumers the ack is sent only after a worker takes the
|
||||
// event off the channel, so messages that wait behind a long running task can
|
||||
// be redelivered and processed twice. Every published event carries a unique
|
||||
// event ID (see reva events.Publish), so a redelivered copy has the same ID as
|
||||
// the original and can be recognised.
|
||||
//
|
||||
// The key is the event ID, not the upload ID: a single upload legitimately
|
||||
// produces several distinct events (BytesReceived, StepFinished, ...).
|
||||
package eventdedup
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/owncloud/reva/v2/pkg/events"
|
||||
)
|
||||
|
||||
// Seen remembers event IDs for a limited time.
|
||||
type Seen struct {
|
||||
mu sync.Mutex
|
||||
ttl time.Duration
|
||||
now func() time.Time
|
||||
ids map[string]time.Time
|
||||
lastGC time.Time
|
||||
}
|
||||
|
||||
// NewSeen returns a Seen that forgets IDs after ttl.
|
||||
func NewSeen(ttl time.Duration) *Seen {
|
||||
return &Seen{ttl: ttl, now: time.Now, ids: map[string]time.Time{}}
|
||||
}
|
||||
|
||||
// FirstTime records id and reports whether it was not seen within the ttl.
|
||||
// Empty IDs are always reported as first time, since they cannot be matched.
|
||||
func (s *Seen) FirstTime(id string) bool {
|
||||
if id == "" {
|
||||
return true
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
now := s.now()
|
||||
if now.Sub(s.lastGC) > s.ttl {
|
||||
for k, t := range s.ids {
|
||||
if now.Sub(t) > s.ttl {
|
||||
delete(s.ids, k)
|
||||
}
|
||||
}
|
||||
s.lastGC = now
|
||||
}
|
||||
|
||||
if t, ok := s.ids[id]; ok && now.Sub(t) <= s.ttl {
|
||||
return false
|
||||
}
|
||||
s.ids[id] = now
|
||||
return true
|
||||
}
|
||||
|
||||
// Len returns the number of remembered IDs.
|
||||
func (s *Seen) Len() int {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return len(s.ids)
|
||||
}
|
||||
|
||||
// Filter forwards events from in whose ID was not seen before. onDrop, if not
|
||||
// nil, is called for every dropped duplicate. The returned channel is closed
|
||||
// when in is closed.
|
||||
func Filter(in <-chan events.Event, seen *Seen, onDrop func(events.Event)) <-chan events.Event {
|
||||
out := make(chan events.Event)
|
||||
go func() {
|
||||
defer close(out)
|
||||
for e := range in {
|
||||
if !seen.FirstTime(e.ID) {
|
||||
if onDrop != nil {
|
||||
onDrop(e)
|
||||
}
|
||||
continue
|
||||
}
|
||||
out <- e
|
||||
}
|
||||
}()
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package eventdedup_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-micro/plugins/v4/events/natsjs"
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/eventdedup"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/natsconsumer"
|
||||
"github.com/owncloud/reva/v2/pkg/events"
|
||||
"github.com/owncloud/reva/v2/pkg/events/stream"
|
||||
)
|
||||
|
||||
func TestSeen(t *testing.T) {
|
||||
s := eventdedup.NewSeen(time.Hour)
|
||||
if !s.FirstTime("a") || s.FirstTime("a") || !s.FirstTime("b") {
|
||||
t.Fatal("unexpected dedup result")
|
||||
}
|
||||
if !s.FirstTime("") || !s.FirstTime("") {
|
||||
t.Fatal("empty IDs must never be dropped")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeenExpires(t *testing.T) {
|
||||
s := eventdedup.NewSeen(50 * time.Millisecond)
|
||||
s.FirstTime("a")
|
||||
time.Sleep(120 * time.Millisecond)
|
||||
if !s.FirstTime("a") {
|
||||
t.Fatal("id should be forgotten after ttl")
|
||||
}
|
||||
if s.Len() != 1 {
|
||||
t.Fatalf("expired ids must be removed, len=%d", s.Len())
|
||||
}
|
||||
}
|
||||
|
||||
// runLongTaskScenario reproduces the production problem against a real
|
||||
// JetStream server. AckWait is short compared to the processing time of one
|
||||
// upload ("big"), and there is a single worker. While "big" is processed, the
|
||||
// reva forwarding goroutine is blocked handing off the first follower, so the
|
||||
// remaining followers stay unacked in the natsjs callback and JetStream
|
||||
// redelivers them. Those redelivered copies carry the same event ID as the
|
||||
// originals. The function returns how often each upload was processed.
|
||||
func runLongTaskScenario(t *testing.T, dedup bool) map[string]int {
|
||||
t.Helper()
|
||||
srv, err := server.NewServer(&server.Options{Host: "127.0.0.1", Port: -1, JetStream: true, StoreDir: t.TempDir(), NoSigs: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go srv.Start()
|
||||
if !srv.ReadyForConnections(10 * time.Second) {
|
||||
t.Fatal("nats server not ready")
|
||||
}
|
||||
defer srv.Shutdown()
|
||||
|
||||
bus, err := stream.Nats(natsjs.Address(srv.ClientURL()), natsjs.ClusterID("test"), natsjs.SynchronousPublish(true))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ch, err := events.Consume(bus, "postprocessing", events.BytesReceived{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// shorten AckWait on the server so the test finishes in seconds
|
||||
nc, js, err := natsconsumer.Connect(natsconsumer.Connection{Endpoint: srv.ClientURL(), Name: "test"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nc.Close()
|
||||
if _, err := natsconsumer.Apply(js, events.MainQueueName, "postprocessing", natsconsumer.Settings{AckWait: time.Second}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if dedup {
|
||||
ch = eventdedup.Filter(ch, eventdedup.NewSeen(time.Hour), nil)
|
||||
}
|
||||
|
||||
var mu sync.Mutex
|
||||
counts := map[string]int{}
|
||||
go func() { // a single worker, like a fully occupied worker pool
|
||||
for e := range ch {
|
||||
id := e.Event.(events.BytesReceived).UploadID
|
||||
mu.Lock()
|
||||
counts[id]++
|
||||
mu.Unlock()
|
||||
if id == "big" {
|
||||
time.Sleep(5 * time.Second) // much longer than AckWait
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// "big" occupies the worker; the followers queue up behind it. The first
|
||||
// follower is acked at hand-off, the later ones stay unacked and are
|
||||
// redelivered while the worker is busy.
|
||||
ids := []string{"big", "f0", "f1", "f2", "f3"}
|
||||
for _, id := range ids {
|
||||
if err := events.Publish(context.Background(), bus, events.BytesReceived{UploadID: id}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
res := map[string]int{}
|
||||
for k, v := range counts {
|
||||
res[k] = v
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func total(counts map[string]int) int {
|
||||
n := 0
|
||||
for _, v := range counts {
|
||||
n += v
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func TestRedeliveredEventsProcessedTwiceWithoutDedup(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("integration test")
|
||||
}
|
||||
counts := runLongTaskScenario(t, false)
|
||||
// 5 distinct uploads; any duplicate from redelivery pushes the total above 5.
|
||||
if total(counts) <= len(counts) {
|
||||
t.Fatalf("expected redelivered events to be processed more than once, counts=%v", counts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedeliveredEventsProcessedOnceWithDedup(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("integration test")
|
||||
}
|
||||
counts := runLongTaskScenario(t, true)
|
||||
var dupes []string
|
||||
for id, c := range counts {
|
||||
if c != 1 {
|
||||
dupes = append(dupes, fmt.Sprintf("%s=%d", id, c))
|
||||
}
|
||||
}
|
||||
if len(dupes) > 0 {
|
||||
t.Fatalf("each upload must be processed exactly once, duplicates: %v (counts=%v)", dupes, counts)
|
||||
}
|
||||
if len(counts) != 5 {
|
||||
t.Fatalf("all 5 uploads should be processed once, counts=%v", counts)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
// Package natsconsumer adjusts the settings of durable JetStream consumers that
|
||||
// were created by other components (for example reva's event consumers).
|
||||
//
|
||||
// The go-micro natsjs plugin used by reva creates its consumers with the server
|
||||
// defaults (AckWait 30s, unlimited MaxDeliver) and does not expose these options.
|
||||
// Passing them as subscribe options would break restarts, because nats.go rejects
|
||||
// a subscription whose options differ from the existing durable consumer.
|
||||
// Updating the consumer on the server avoids that: the client never sends
|
||||
// AckWait or MaxDeliver, so the server-side values survive restarts.
|
||||
package natsconsumer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
)
|
||||
|
||||
// Settings are the consumer settings to enforce. Zero values leave the current
|
||||
// server value untouched.
|
||||
type Settings struct {
|
||||
// AckWait is how long the server waits for an ack before redelivering.
|
||||
AckWait time.Duration
|
||||
// MaxDeliver is the maximum number of delivery attempts. -1 means unlimited.
|
||||
MaxDeliver int
|
||||
}
|
||||
|
||||
// IsZero reports whether no setting is requested.
|
||||
func (s Settings) IsZero() bool {
|
||||
return s.AckWait == 0 && s.MaxDeliver == 0
|
||||
}
|
||||
|
||||
// Validate checks the settings for values the server would reject.
|
||||
func (s Settings) Validate() error {
|
||||
if s.AckWait < 0 {
|
||||
return fmt.Errorf("ack wait must not be negative, got %s", s.AckWait)
|
||||
}
|
||||
if s.MaxDeliver < -1 {
|
||||
return fmt.Errorf("max deliver must be -1 (unlimited), 0 (unchanged) or positive, got %d", s.MaxDeliver)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Connection holds what is needed to reach the NATS server.
|
||||
type Connection struct {
|
||||
Endpoint string
|
||||
Name string
|
||||
EnableTLS bool
|
||||
TLSInsecure bool
|
||||
TLSRootCACertificate string
|
||||
AuthUsername string
|
||||
AuthPassword string
|
||||
}
|
||||
|
||||
// Connect opens a NATS connection and a JetStream context.
|
||||
func Connect(c Connection) (*nats.Conn, nats.JetStreamContext, error) {
|
||||
opts := []nats.Option{nats.Name(c.Name)}
|
||||
if c.AuthUsername != "" || c.AuthPassword != "" {
|
||||
opts = append(opts, nats.UserInfo(c.AuthUsername, c.AuthPassword))
|
||||
}
|
||||
if c.EnableTLS {
|
||||
tlsConf := &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
InsecureSkipVerify: c.TLSInsecure, //nolint:gosec
|
||||
}
|
||||
if c.TLSRootCACertificate != "" {
|
||||
pem, err := os.ReadFile(c.TLSRootCACertificate)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
pool := x509.NewCertPool()
|
||||
if !pool.AppendCertsFromPEM(pem) {
|
||||
return nil, nil, errors.New("failed to append cert from PEM")
|
||||
}
|
||||
tlsConf.RootCAs = pool
|
||||
tlsConf.InsecureSkipVerify = false
|
||||
}
|
||||
opts = append(opts, nats.Secure(tlsConf))
|
||||
}
|
||||
|
||||
nc, err := nats.Connect(c.Endpoint, opts...)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
js, err := nc.JetStream()
|
||||
if err != nil {
|
||||
nc.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
return nc, js, nil
|
||||
}
|
||||
|
||||
// Apply updates the consumer when its settings differ from s. It reports
|
||||
// whether an update was sent.
|
||||
func Apply(js nats.JetStreamManager, stream, consumer string, s Settings) (bool, error) {
|
||||
if err := s.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
info, err := js.ConsumerInfo(stream, consumer)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
cfg := info.Config
|
||||
changed := false
|
||||
if s.AckWait > 0 && cfg.AckWait != s.AckWait {
|
||||
if len(cfg.BackOff) > 0 {
|
||||
return false, fmt.Errorf("consumer %s/%s uses a backoff list, which overrides ack wait", stream, consumer)
|
||||
}
|
||||
cfg.AckWait = s.AckWait
|
||||
changed = true
|
||||
}
|
||||
if s.MaxDeliver != 0 && cfg.MaxDeliver != s.MaxDeliver {
|
||||
cfg.MaxDeliver = s.MaxDeliver
|
||||
changed = true
|
||||
}
|
||||
if !changed {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if _, err := js.UpdateConsumer(stream, &cfg); err != nil {
|
||||
return false, fmt.Errorf("updating consumer %s/%s: %w", stream, consumer, err)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Ensure connects to NATS and applies s to the consumer. It retries every
|
||||
// retryInterval while the stream or consumer does not exist yet, until ctx is done.
|
||||
func Ensure(ctx context.Context, logger log.Logger, conn Connection, stream, consumer string, s Settings, retryInterval time.Duration) error {
|
||||
if s.IsZero() {
|
||||
return nil
|
||||
}
|
||||
if err := s.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nc, js, err := Connect(conn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer nc.Close()
|
||||
|
||||
for {
|
||||
updated, err := Apply(js, stream, consumer, s)
|
||||
switch {
|
||||
case err == nil:
|
||||
ev := logger.Debug()
|
||||
msg := "NATS consumer settings already up to date"
|
||||
if updated {
|
||||
ev = logger.Info()
|
||||
msg = "updated NATS consumer settings"
|
||||
}
|
||||
ev.Str("stream", stream).Str("consumer", consumer).
|
||||
Str("ackWait", s.AckWait.String()).Int("maxDeliver", s.MaxDeliver).Msg(msg)
|
||||
return nil
|
||||
case errors.Is(err, nats.ErrConsumerNotFound), errors.Is(err, nats.ErrStreamNotFound):
|
||||
// the owning component has not subscribed yet
|
||||
default:
|
||||
return err
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return fmt.Errorf("consumer %s/%s not found: %w", stream, consumer, ctx.Err())
|
||||
case <-time.After(retryInterval):
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package natsconsumer_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
"github.com/nats-io/nats.go"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/natsconsumer"
|
||||
)
|
||||
|
||||
func runServer(t *testing.T) string {
|
||||
t.Helper()
|
||||
s, err := server.NewServer(&server.Options{Host: "127.0.0.1", Port: -1, JetStream: true, StoreDir: t.TempDir(), NoSigs: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go s.Start()
|
||||
if !s.ReadyForConnections(10 * time.Second) {
|
||||
t.Fatal("nats server not ready")
|
||||
}
|
||||
t.Cleanup(s.Shutdown)
|
||||
return s.ClientURL()
|
||||
}
|
||||
|
||||
// subscribeLikeNatsjs subscribes with exactly the options the go-micro natsjs
|
||||
// plugin uses (no AckWait, no MaxDeliver).
|
||||
func subscribeLikeNatsjs(t *testing.T, url string) *nats.Conn {
|
||||
t.Helper()
|
||||
nc, err := nats.Connect(url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
js, err := nc.JetStream()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.StreamInfo("main-queue"); err != nil {
|
||||
if _, err := js.AddStream(&nats.StreamConfig{Name: "main-queue"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
_, err = js.QueueSubscribe("main-queue", "dcfs", func(*nats.Msg) {},
|
||||
nats.AckExplicit(), nats.DeliverNew(), nats.Durable("dcfs"))
|
||||
if err != nil {
|
||||
t.Fatalf("subscribe: %v", err)
|
||||
}
|
||||
return nc
|
||||
}
|
||||
|
||||
func TestApplyUpdatesConsumerAndSurvivesRestart(t *testing.T) {
|
||||
url := runServer(t)
|
||||
nc := subscribeLikeNatsjs(t, url)
|
||||
|
||||
cnc, js, err := natsconsumer.Connect(natsconsumer.Connection{Endpoint: url, Name: "test"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer cnc.Close()
|
||||
|
||||
want := natsconsumer.Settings{AckWait: 30 * time.Minute, MaxDeliver: 3}
|
||||
updated, err := natsconsumer.Apply(js, "main-queue", "dcfs", want)
|
||||
if err != nil || !updated {
|
||||
t.Fatalf("Apply: updated=%v err=%v", updated, err)
|
||||
}
|
||||
if updated, err := natsconsumer.Apply(js, "main-queue", "dcfs", want); err != nil || updated {
|
||||
t.Fatalf("second Apply should be a no-op: updated=%v err=%v", updated, err)
|
||||
}
|
||||
|
||||
// Simulate a service restart: the durable stays, the client resubscribes
|
||||
// with the natsjs options. This must not fail with a config mismatch.
|
||||
nc.Close()
|
||||
nc2 := subscribeLikeNatsjs(t, url)
|
||||
defer nc2.Close()
|
||||
|
||||
info, err := js.ConsumerInfo("main-queue", "dcfs")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if info.Config.AckWait != want.AckWait || info.Config.MaxDeliver != want.MaxDeliver {
|
||||
t.Fatalf("got AckWait=%s MaxDeliver=%d", info.Config.AckWait, info.Config.MaxDeliver)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureWaitsForConsumer(t *testing.T) {
|
||||
url := runServer(t)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
done <- natsconsumer.Ensure(ctx, log.NopLogger(), natsconsumer.Connection{Endpoint: url, Name: "test"},
|
||||
"main-queue", "dcfs", natsconsumer.Settings{AckWait: 10 * time.Minute, MaxDeliver: 2}, 100*time.Millisecond)
|
||||
}()
|
||||
|
||||
time.Sleep(500 * time.Millisecond) // the consumer appears after Ensure starts
|
||||
nc := subscribeLikeNatsjs(t, url)
|
||||
defer nc.Close()
|
||||
|
||||
if err := <-done; err != nil {
|
||||
t.Fatalf("Ensure: %v", err)
|
||||
}
|
||||
js, _ := nc.JetStream()
|
||||
info, err := js.ConsumerInfo("main-queue", "dcfs")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if info.Config.AckWait != 10*time.Minute || info.Config.MaxDeliver != 2 {
|
||||
t.Fatalf("got AckWait=%s MaxDeliver=%d", info.Config.AckWait, info.Config.MaxDeliver)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
if err := (natsconsumer.Settings{MaxDeliver: -2}).Validate(); err == nil {
|
||||
t.Fatal("expected error for MaxDeliver -2")
|
||||
}
|
||||
if err := (natsconsumer.Settings{AckWait: -time.Second}).Validate(); err == nil {
|
||||
t.Fatal("expected error for negative AckWait")
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,16 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/owncloud/reva/v2/pkg/events"
|
||||
"github.com/owncloud/reva/v2/pkg/events/stream"
|
||||
"github.com/owncloud/reva/v2/pkg/store"
|
||||
"github.com/urfave/cli/v2"
|
||||
microstore "go-micro.dev/v4/store"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/generators"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/natsconsumer"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/runner"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
|
||||
@@ -73,6 +76,27 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
// The consumer exists now (NewPostprocessingService subscribed), so its
|
||||
// server-side settings can be adjusted without breaking later restarts.
|
||||
go func() {
|
||||
ev := cfg.Postprocessing.Events
|
||||
err := natsconsumer.Ensure(ctx, logger, natsconsumer.Connection{
|
||||
Endpoint: ev.Endpoint,
|
||||
Name: cfg.Service.Name + "-consumer-config",
|
||||
EnableTLS: ev.EnableTLS,
|
||||
TLSInsecure: ev.TLSInsecure,
|
||||
TLSRootCACertificate: ev.TLSRootCACertificate,
|
||||
AuthUsername: ev.AuthUsername,
|
||||
AuthPassword: ev.AuthPassword,
|
||||
}, events.MainQueueName, "postprocessing", natsconsumer.Settings{
|
||||
AckWait: cfg.Postprocessing.AckWait,
|
||||
MaxDeliver: cfg.Postprocessing.MaxDelivery,
|
||||
}, 5*time.Second)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("could not apply NATS consumer settings")
|
||||
}
|
||||
}()
|
||||
|
||||
gr.Add(runner.New(cfg.Service.Name+".svc", func() error {
|
||||
return svc.Run()
|
||||
}, func() {
|
||||
|
||||
@@ -26,7 +26,11 @@ type Config struct {
|
||||
// Postprocessing defines the config options for the postprocessing service.
|
||||
type Postprocessing struct {
|
||||
Events Events `yaml:"events"`
|
||||
Workers int `yaml:"workers" env:"POSTPROCESSING_WORKERS" desc:"The number of concurrent go routines that fetch events from the event queue." introductionVersion:"6.7"`
|
||||
Workers int `yaml:"workers" env:"POSTPROCESSING_WORKERS;POSTPROCESSING_CONCURRENCY" desc:"The number of concurrent go routines that fetch events from the event queue. POSTPROCESSING_CONCURRENCY is an alias and takes precedence when both are set." introductionVersion:"6.7"`
|
||||
|
||||
AckWait time.Duration `yaml:"ack_wait" env:"POSTPROCESSING_ACK_WAIT" desc:"How long the NATS JetStream server waits for an acknowledgement before it redelivers an event to the postprocessing consumer. The value is written to the durable consumer on the server at startup. Set to 0 to keep the current server value. See the Environment Variable Types description for more details." introductionVersion:"8.3.0"`
|
||||
MaxDelivery int `yaml:"max_delivery" env:"POSTPROCESSING_MAX_DELIVERY" desc:"Maximum number of delivery attempts of an event to the postprocessing consumer. Events exceeding it are no longer redelivered. -1 means unlimited, 0 keeps the current server value." introductionVersion:"8.3.0"`
|
||||
DedupWindow time.Duration `yaml:"dedup_window" env:"POSTPROCESSING_DEDUP_WINDOW" desc:"How long event IDs are remembered to drop redelivered duplicates. Should be at least ack_wait multiplied by max_delivery. Set to 0 to disable deduplication. See the Environment Variable Types description for more details." introductionVersion:"8.3.0"`
|
||||
|
||||
Steps []string `yaml:"steps" env:"POSTPROCESSING_STEPS" desc:"A list of postprocessing steps processed in order of their appearance. Currently supported values by the system are: 'virusscan', 'policies' and 'delay'. Custom steps are allowed. See the documentation for instructions. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
Delayprocessing time.Duration `yaml:"delayprocessing" env:"POSTPROCESSING_DELAY" desc:"After uploading a file but before making it available for download, a delay step can be added. Intended for developing purposes only. If a duration is set but the keyword 'delay' is not explicitely added to 'POSTPROCESSING_STEPS', the delay step will be processed as last step. In such a case, a log entry will be written on service startup to remind the admin about that situation. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
@@ -57,11 +61,11 @@ type Debug struct {
|
||||
|
||||
// Store configures the store to use
|
||||
type Store struct {
|
||||
Store string `yaml:"store" env:"OCIS_PERSISTENT_STORE;POSTPROCESSING_STORE" desc:"The type of the store. Supported values are: 'memory', 'redis-sentinel', 'nats-js-kv', 'noop'. See the text description for details." introductionVersion:"pre5.0"`
|
||||
Nodes []string `yaml:"nodes" env:"OCIS_PERSISTENT_STORE_NODES;POSTPROCESSING_STORE_NODES" desc:"A list of nodes to access the configured store. This has no effect when 'memory' store is configured. Note that the behaviour how nodes are used is dependent on the library of the configured store. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
Database string `yaml:"database" env:"POSTPROCESSING_STORE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"`
|
||||
Table string `yaml:"table" env:"POSTPROCESSING_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"pre5.0"`
|
||||
TTL time.Duration `yaml:"ttl" env:"OCIS_PERSISTENT_STORE_TTL;POSTPROCESSING_STORE_TTL" desc:"Time to live for events in the store. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
Store string `yaml:"store" env:"OCIS_PERSISTENT_STORE;POSTPROCESSING_STORE" desc:"The type of the store. Supported values are: 'memory', 'redis-sentinel', 'nats-js-kv', 'noop'. See the text description for details." introductionVersion:"pre5.0"`
|
||||
Nodes []string `yaml:"nodes" env:"OCIS_PERSISTENT_STORE_NODES;POSTPROCESSING_STORE_NODES" desc:"A list of nodes to access the configured store. This has no effect when 'memory' store is configured. Note that the behaviour how nodes are used is dependent on the library of the configured store. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
Database string `yaml:"database" env:"POSTPROCESSING_STORE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"`
|
||||
Table string `yaml:"table" env:"POSTPROCESSING_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"pre5.0"`
|
||||
TTL time.Duration `yaml:"ttl" env:"OCIS_PERSISTENT_STORE_TTL;POSTPROCESSING_STORE_TTL" desc:"Time to live for events in the store. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
AuthUsername string `yaml:"username" env:"OCIS_PERSISTENT_STORE_AUTH_USERNAME;POSTPROCESSING_STORE_AUTH_USERNAME" desc:"The username to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
|
||||
AuthPassword string `yaml:"password" env:"OCIS_PERSISTENT_STORE_AUTH_PASSWORD;POSTPROCESSING_STORE_AUTH_PASSWORD" desc:"The password to authenticate with the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
|
||||
EnableTLS bool `yaml:"enable_tls" env:"OCIS_PERSISTENT_STORE_ENABLE_TLS;POSTPROCESSING_STORE_ENABLE_TLS" desc:"Activate TLS for the connection to the store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
|
||||
@@ -32,6 +32,9 @@ func DefaultConfig() *config.Config {
|
||||
Cluster: "ocis-cluster",
|
||||
},
|
||||
Workers: 3,
|
||||
AckWait: 30 * time.Minute,
|
||||
MaxDelivery: 3,
|
||||
DedupWindow: 2 * time.Hour,
|
||||
RetryBackoffDuration: 5 * time.Second,
|
||||
MaxRetries: 14,
|
||||
},
|
||||
@@ -71,6 +74,9 @@ func EnsureDefaults(cfg *config.Config) {
|
||||
}
|
||||
}
|
||||
|
||||
// Sanitize does nothing atm
|
||||
// Sanitize sanitizes the config
|
||||
func Sanitize(cfg *config.Config) {
|
||||
if cfg.Postprocessing.Workers < 1 {
|
||||
cfg.Postprocessing.Workers = 1
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/eventdedup"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/postprocessing"
|
||||
@@ -56,6 +57,12 @@ func NewPostprocessingService(ctx context.Context, stream events.Stream, logger
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.DedupWindow > 0 {
|
||||
evs = eventdedup.Filter(evs, eventdedup.NewSeen(c.DedupWindow), func(e events.Event) {
|
||||
logger.Info().Str("eventID", e.ID).Str("type", e.Type).Msg("dropping redelivered duplicate event")
|
||||
})
|
||||
}
|
||||
|
||||
return &PostprocessingService{
|
||||
ctx: ctx,
|
||||
log: logger,
|
||||
|
||||
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/natsconsumer"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/runner"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
|
||||
@@ -17,6 +19,7 @@ import (
|
||||
"github.com/owncloud/ocis/v2/services/storage-users/pkg/revaconfig"
|
||||
"github.com/owncloud/ocis/v2/services/storage-users/pkg/server/debug"
|
||||
"github.com/owncloud/reva/v2/cmd/revad/runtime"
|
||||
revaevents "github.com/owncloud/reva/v2/pkg/events"
|
||||
"github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@@ -95,6 +98,30 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
// The decomposedfs consumer is created by reva once the storage
|
||||
// provider starts; Ensure retries until it exists.
|
||||
go func() {
|
||||
group := cfg.Events.ConsumerGroup
|
||||
if group == "" {
|
||||
group = "dcfs"
|
||||
}
|
||||
err := natsconsumer.Ensure(ctx, logger, natsconsumer.Connection{
|
||||
Endpoint: cfg.Events.Addr,
|
||||
Name: cfg.Service.Name + "-consumer-config",
|
||||
EnableTLS: cfg.Events.EnableTLS,
|
||||
TLSInsecure: cfg.Events.TLSInsecure,
|
||||
TLSRootCACertificate: cfg.Events.TLSRootCaCertPath,
|
||||
AuthUsername: cfg.Events.AuthUsername,
|
||||
AuthPassword: cfg.Events.AuthPassword,
|
||||
}, revaevents.MainQueueName, group, natsconsumer.Settings{
|
||||
AckWait: cfg.Events.AckWait,
|
||||
MaxDeliver: cfg.Events.MaxDelivery,
|
||||
}, 5*time.Second)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Str("consumer", group).Msg("could not apply NATS consumer settings")
|
||||
}
|
||||
}()
|
||||
|
||||
eventSVC, err := event.NewService(ctx, selector, stream, traceProvider, logger, *cfg)
|
||||
if err != nil {
|
||||
logger.Fatal().Err(err).Msg("can't create event handler")
|
||||
|
||||
@@ -211,43 +211,45 @@ type PosixDriver struct {
|
||||
|
||||
// Events combines the configuration options for the event bus.
|
||||
type Events struct {
|
||||
Addr string `yaml:"endpoint" env:"OCIS_EVENTS_ENDPOINT;STORAGE_USERS_EVENTS_ENDPOINT" desc:"The address of the event system. The event system is the message queuing service. It is used as message broker for the microservice architecture." introductionVersion:"pre5.0"`
|
||||
ClusterID string `yaml:"cluster" env:"OCIS_EVENTS_CLUSTER;STORAGE_USERS_EVENTS_CLUSTER" desc:"The clusterID of the event system. The event system is the message queuing service. It is used as message broker for the microservice architecture. Mandatory when using NATS as event system." introductionVersion:"pre5.0"`
|
||||
TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_INSECURE;STORAGE_USERS_EVENTS_TLS_INSECURE" desc:"Whether to verify the server TLS certificates." introductionVersion:"pre5.0"`
|
||||
TLSRootCaCertPath string `yaml:"tls_root_ca_cert_path" env:"OCIS_EVENTS_TLS_ROOT_CA_CERTIFICATE;STORAGE_USERS_EVENTS_TLS_ROOT_CA_CERTIFICATE" desc:"The root CA certificate used to validate the server's TLS certificate. If provided STORAGE_USERS_EVENTS_TLS_INSECURE will be seen as false." introductionVersion:"pre5.0"`
|
||||
EnableTLS bool `yaml:"enable_tls" env:"OCIS_EVENTS_ENABLE_TLS;STORAGE_USERS_EVENTS_ENABLE_TLS" desc:"Enable TLS for the connection to the events broker. The events broker is the ocis service which receives and delivers events between the services." introductionVersion:"pre5.0"`
|
||||
NumConsumers int `yaml:"num_consumers" env:"STORAGE_USERS_EVENTS_NUM_CONSUMERS" desc:"The amount of concurrent event consumers to start. Event consumers are used for post-processing files. Multiple consumers increase parallelisation, but will also increase CPU and memory demands. The setting has no effect when the OCIS_ASYNC_UPLOADS is set to false. The default and minimum value is 1." introductionVersion:"pre5.0"`
|
||||
ConsumerGroup string `yaml:"consumer_group" env:"STORAGE_USERS_EVENTS_CONSUMER_GROUP" desc:"The name of the consumer group to be used at the event to help consumers identify the unique group." introductionVersion:"8.1.0"`
|
||||
AuthUsername string `yaml:"username" env:"OCIS_EVENTS_AUTH_USERNAME;STORAGE_USERS_EVENTS_AUTH_USERNAME" desc:"The username to authenticate with the events broker. The events broker is the ocis service which receives and delivers events between the services." introductionVersion:"5.0"`
|
||||
AuthPassword string `yaml:"password" env:"OCIS_EVENTS_AUTH_PASSWORD;STORAGE_USERS_EVENTS_AUTH_PASSWORD" desc:"The password to authenticate with the events broker. The events broker is the ocis service which receives and delivers events between the services." introductionVersion:"5.0"`
|
||||
Addr string `yaml:"endpoint" env:"OCIS_EVENTS_ENDPOINT;STORAGE_USERS_EVENTS_ENDPOINT" desc:"The address of the event system. The event system is the message queuing service. It is used as message broker for the microservice architecture." introductionVersion:"pre5.0"`
|
||||
ClusterID string `yaml:"cluster" env:"OCIS_EVENTS_CLUSTER;STORAGE_USERS_EVENTS_CLUSTER" desc:"The clusterID of the event system. The event system is the message queuing service. It is used as message broker for the microservice architecture. Mandatory when using NATS as event system." introductionVersion:"pre5.0"`
|
||||
TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_INSECURE;STORAGE_USERS_EVENTS_TLS_INSECURE" desc:"Whether to verify the server TLS certificates." introductionVersion:"pre5.0"`
|
||||
TLSRootCaCertPath string `yaml:"tls_root_ca_cert_path" env:"OCIS_EVENTS_TLS_ROOT_CA_CERTIFICATE;STORAGE_USERS_EVENTS_TLS_ROOT_CA_CERTIFICATE" desc:"The root CA certificate used to validate the server's TLS certificate. If provided STORAGE_USERS_EVENTS_TLS_INSECURE will be seen as false." introductionVersion:"pre5.0"`
|
||||
EnableTLS bool `yaml:"enable_tls" env:"OCIS_EVENTS_ENABLE_TLS;STORAGE_USERS_EVENTS_ENABLE_TLS" desc:"Enable TLS for the connection to the events broker. The events broker is the ocis service which receives and delivers events between the services." introductionVersion:"pre5.0"`
|
||||
NumConsumers int `yaml:"num_consumers" env:"STORAGE_USERS_EVENTS_NUM_CONSUMERS" desc:"The amount of concurrent event consumers to start. Event consumers are used for post-processing files. Multiple consumers increase parallelisation, but will also increase CPU and memory demands. The setting has no effect when the OCIS_ASYNC_UPLOADS is set to false. The default and minimum value is 1." introductionVersion:"pre5.0"`
|
||||
ConsumerGroup string `yaml:"consumer_group" env:"STORAGE_USERS_EVENTS_CONSUMER_GROUP" desc:"The name of the consumer group to be used at the event to help consumers identify the unique group." introductionVersion:"8.1.0"`
|
||||
AckWait time.Duration `yaml:"ack_wait" env:"STORAGE_USERS_EVENTS_ACK_WAIT" desc:"How long the NATS JetStream server waits for an acknowledgement before it redelivers an event to the storage postprocessing consumer (the one finalizing uploads into the blobstore). Written to the durable consumer on the server at startup. Set to 0 to keep the current server value. See the Environment Variable Types description for more details." introductionVersion:"8.3.0"`
|
||||
MaxDelivery int `yaml:"max_delivery" env:"STORAGE_USERS_EVENTS_MAX_DELIVERY" desc:"Maximum number of delivery attempts of an event to the storage postprocessing consumer. -1 means unlimited, 0 keeps the current server value." introductionVersion:"8.3.0"`
|
||||
AuthUsername string `yaml:"username" env:"OCIS_EVENTS_AUTH_USERNAME;STORAGE_USERS_EVENTS_AUTH_USERNAME" desc:"The username to authenticate with the events broker. The events broker is the ocis service which receives and delivers events between the services." introductionVersion:"5.0"`
|
||||
AuthPassword string `yaml:"password" env:"OCIS_EVENTS_AUTH_PASSWORD;STORAGE_USERS_EVENTS_AUTH_PASSWORD" desc:"The password to authenticate with the events broker. The events broker is the ocis service which receives and delivers events between the services." introductionVersion:"5.0"`
|
||||
}
|
||||
|
||||
// FilemetadataCache holds cache config
|
||||
type FilemetadataCache struct {
|
||||
Store string `yaml:"store" env:"OCIS_CACHE_STORE;STORAGE_USERS_FILEMETADATA_CACHE_STORE" desc:"The type of the cache store. Supported values are: 'memory', 'redis-sentinel', 'nats-js-kv', 'noop'. See the text description for details." introductionVersion:"pre5.0"`
|
||||
Nodes []string `yaml:"nodes" env:"OCIS_CACHE_STORE_NODES;STORAGE_USERS_FILEMETADATA_CACHE_STORE_NODES" desc:"A list of nodes to access the configured store. This has no effect when 'memory' store is configured. Note that the behaviour how nodes are used is dependent on the library of the configured store. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
Database string `yaml:"database" env:"OCIS_CACHE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"`
|
||||
TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;STORAGE_USERS_FILEMETADATA_CACHE_TTL" desc:"Default time to live for user info in the user info cache. Only applied when access tokens has no expiration. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;STORAGE_USERS_FILEMETADATA_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"`
|
||||
AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;STORAGE_USERS_FILEMETADATA_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
|
||||
AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;STORAGE_USERS_FILEMETADATA_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
|
||||
EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;STORAGE_USERS_FILEMETADATA_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;STORAGE_USERS_FILEMETADATA_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;STORAGE_USERS_FILEMETADATA_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
Store string `yaml:"store" env:"OCIS_CACHE_STORE;STORAGE_USERS_FILEMETADATA_CACHE_STORE" desc:"The type of the cache store. Supported values are: 'memory', 'redis-sentinel', 'nats-js-kv', 'noop'. See the text description for details." introductionVersion:"pre5.0"`
|
||||
Nodes []string `yaml:"nodes" env:"OCIS_CACHE_STORE_NODES;STORAGE_USERS_FILEMETADATA_CACHE_STORE_NODES" desc:"A list of nodes to access the configured store. This has no effect when 'memory' store is configured. Note that the behaviour how nodes are used is dependent on the library of the configured store. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
Database string `yaml:"database" env:"OCIS_CACHE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"`
|
||||
TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;STORAGE_USERS_FILEMETADATA_CACHE_TTL" desc:"Default time to live for user info in the user info cache. Only applied when access tokens has no expiration. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;STORAGE_USERS_FILEMETADATA_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"`
|
||||
AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;STORAGE_USERS_FILEMETADATA_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
|
||||
AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;STORAGE_USERS_FILEMETADATA_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
|
||||
EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;STORAGE_USERS_FILEMETADATA_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;STORAGE_USERS_FILEMETADATA_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;STORAGE_USERS_FILEMETADATA_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
}
|
||||
|
||||
// IDCache holds cache config
|
||||
type IDCache struct {
|
||||
Store string `yaml:"store" env:"OCIS_CACHE_STORE;STORAGE_USERS_ID_CACHE_STORE" desc:"The type of the cache store. Supported values are: 'memory', 'redis-sentinel', 'nats-js-kv', 'noop'. See the text description for details." introductionVersion:"pre5.0"`
|
||||
Nodes []string `yaml:"nodes" env:"OCIS_CACHE_STORE_NODES;STORAGE_USERS_ID_CACHE_STORE_NODES" desc:"A list of nodes to access the configured store. This has no effect when 'memory' store is configured. Note that the behaviour how nodes are used is dependent on the library of the configured store. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
Database string `yaml:"database" env:"OCIS_CACHE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"`
|
||||
TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;STORAGE_USERS_ID_CACHE_TTL" desc:"Default time to live for user info in the user info cache. Only applied when access tokens have no expiration. Defaults to 300s which is derived from the underlaying package though not explicitly set as default. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;STORAGE_USERS_ID_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"`
|
||||
AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;STORAGE_USERS_ID_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
|
||||
AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;STORAGE_USERS_ID_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
|
||||
EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;STORAGE_USERS_ID_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;STORAGE_USERS_ID_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;STORAGE_USERS_ID_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
Store string `yaml:"store" env:"OCIS_CACHE_STORE;STORAGE_USERS_ID_CACHE_STORE" desc:"The type of the cache store. Supported values are: 'memory', 'redis-sentinel', 'nats-js-kv', 'noop'. See the text description for details." introductionVersion:"pre5.0"`
|
||||
Nodes []string `yaml:"nodes" env:"OCIS_CACHE_STORE_NODES;STORAGE_USERS_ID_CACHE_STORE_NODES" desc:"A list of nodes to access the configured store. This has no effect when 'memory' store is configured. Note that the behaviour how nodes are used is dependent on the library of the configured store. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
Database string `yaml:"database" env:"OCIS_CACHE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"`
|
||||
TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;STORAGE_USERS_ID_CACHE_TTL" desc:"Default time to live for user info in the user info cache. Only applied when access tokens have no expiration. Defaults to 300s which is derived from the underlaying package though not explicitly set as default. See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
|
||||
DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;STORAGE_USERS_ID_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"`
|
||||
AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;STORAGE_USERS_ID_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
|
||||
AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;STORAGE_USERS_ID_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
|
||||
EnableTLS bool `yaml:"enable_tls" env:"OCIS_CACHE_ENABLE_TLS;STORAGE_USERS_ID_CACHE_ENABLE_TLS" desc:"Activate TLS for the connection to the cache store. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_CACHE_TLS_INSECURE;STORAGE_USERS_ID_CACHE_TLS_INSECURE" desc:"Disable TLS certificate verification for the cache store connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"OCIS_CACHE_TLS_ROOT_CA_CERTIFICATE;STORAGE_USERS_ID_CACHE_TLS_ROOT_CA_CERTIFICATE" desc:"Path to the PEM-encoded root CA certificate for the cache store TLS connection. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"8.3.0"`
|
||||
}
|
||||
|
||||
// S3Driver is the storage driver configuration when using 's3' storage driver
|
||||
|
||||
@@ -151,9 +151,12 @@ func DefaultConfig() *config.Config {
|
||||
},
|
||||
},
|
||||
Events: config.Events{
|
||||
Addr: "127.0.0.1:9233",
|
||||
ClusterID: "ocis-cluster",
|
||||
EnableTLS: false,
|
||||
Addr: "127.0.0.1:9233",
|
||||
ClusterID: "ocis-cluster",
|
||||
EnableTLS: false,
|
||||
NumConsumers: 4,
|
||||
AckWait: 30 * time.Minute,
|
||||
MaxDelivery: 3,
|
||||
},
|
||||
FilemetadataCache: config.FilemetadataCache{
|
||||
Store: "memory",
|
||||
|
||||
Reference in new issue
Block a user