Skip to content

Commit 061d462

Browse files
Raderluojun96
andauthored
fix: add per-stream MaxBytes/MaxAge config for LLMLog stream (#1246)
Co-authored-by: Jun Luo <luojun96@live.cn>
1 parent ec296c0 commit 061d462

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

builder/mq/nasts.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ func (n *Nats) getOrCreateStreamConsumer(params SubscribeParams) (jetstream.Cons
103103
Subjects: params.Topics,
104104
MaxConsumers: -1,
105105
MaxMsgs: -1,
106-
MaxBytes: -1,
106+
// NATS JetStream's unlimited sentinel for byte limit is -1.
107+
// Values <= 0 from SubscribeParams are mapped to -1.
108+
// See https://nats-io.github.io/nats.net/api/NATS.Client.JetStream.Models.StreamConfig.html
109+
MaxBytes: maxBytesOrDefault(params.MaxBytes),
110+
// NATS JetStream treats MaxAge 0 as unlimited (no age-based expiry).
111+
// See https://nats-io.github.io/nats.net/api/NATS.Client.JetStream.Models.StreamConfig.MaxAge.html
112+
MaxAge: params.MaxAge,
107113
})
108114
if err != nil {
109115
return nil, fmt.Errorf("[nats] failed to create or update stream %s error: %w", params.Group.StreamName, err)
@@ -211,3 +217,10 @@ func (n *Nats) DeleteMessagesByFilter(streamName string, filter func(data []byte
211217
slog.Int("deleted_count", deletedCount))
212218
return nil
213219
}
220+
221+
func maxBytesOrDefault(v int64) int64 {
222+
if v <= 0 {
223+
return -1
224+
}
225+
return v
226+
}

builder/mq/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package mq
22

3+
import "time"
4+
35
const (
46
NotifySubChangeSubject string = "accounting.notify.subscription"
57
NotifyStopDeploySubject string = "accounting.notify.stopdeploy"
@@ -129,4 +131,10 @@ type SubscribeParams struct {
129131
AutoACK bool // auto acknowledge message after callback success
130132
IsRedeliverForCBFailed bool // whether or not redeliver message for callback return error
131133
Callback MessageCallback
134+
// MaxBytes sets the stream's maximum size in bytes.
135+
// Non-positive values are handled by the message queue implementation.
136+
MaxBytes int64
137+
// MaxAge sets the stream's maximum message age.
138+
// Zero value is handled by the message queue implementation.
139+
MaxAge time.Duration
132140
}

common/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ type Config struct {
514514
WorkerNum int `env:"OPENCSG_LLMLOG_WORKER_NUM" default:"10"`
515515
BatchSize int `env:"OPENCSG_LLMLOG_BATCH_SIZE" default:"1000"`
516516
FlushIntervalSeconds int `env:"OPENCSG_LLMLOG_FLUSH_INTERVAL_SECONDS" default:"300"`
517+
StreamMaxBytes int64 `env:"OPENCSG_LLMLOG_STREAM_MAX_BYTES" default:"8589934592"` // 8 GiB
518+
StreamMaxAgeSeconds int `env:"OPENCSG_LLMLOG_STREAM_MAX_AGE_SECONDS" default:"1209600"` // 14 days
517519
Sync struct {
518520
Enable bool `env:"STARHUB_SERVER_LLMLOG_SYNC_ENABLE" default:"false"`
519521
Username string `env:"STARHUB_SERVER_LLMLOG_SYNC_USERNAME" default:""`

0 commit comments

Comments
 (0)