Skip to content

Commit

Permalink
Merge pull request #3617 from nats-io/add-unique-tag
Browse files Browse the repository at this point in the history
add unique_tag to JetStreamConfig for varz/jsz visibility
  • Loading branch information
derekcollison committed Nov 12, 2022
2 parents a2f8dbf + 40bbfba commit a5398e1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 6 additions & 2 deletions server/jetstream.go
Expand Up @@ -43,6 +43,7 @@ type JetStreamConfig struct {
StoreDir string `json:"store_dir,omitempty"`
Domain string `json:"domain,omitempty"`
CompressOK bool `json:"compress_ok,omitempty"`
UniqueTag string `json:"unique_tag,omitempty"`
}

// Statistics about JetStream for this server.
Expand Down Expand Up @@ -174,10 +175,10 @@ func (s *Server) EnableJetStream(config *JetStreamConfig) error {

s.Noticef("Starting JetStream")
if config == nil || config.MaxMemory <= 0 || config.MaxStore <= 0 {
var storeDir, domain string
var storeDir, domain, uniqueTag string
var maxStore, maxMem int64
if config != nil {
storeDir, domain = config.StoreDir, config.Domain
storeDir, domain, uniqueTag = config.StoreDir, config.Domain, config.UniqueTag
maxStore, maxMem = config.MaxStore, config.MaxMemory
}
config = s.dynJetStreamConfig(storeDir, maxStore, maxMem)
Expand All @@ -187,6 +188,9 @@ func (s *Server) EnableJetStream(config *JetStreamConfig) error {
if domain != _EMPTY_ {
config.Domain = domain
}
if uniqueTag != _EMPTY_ {
config.UniqueTag = uniqueTag
}
s.Debugf("JetStream creating dynamic configuration - %s memory, %s disk", friendlyBytes(config.MaxMemory), friendlyBytes(config.MaxStore))
} else if config.StoreDir != _EMPTY_ {
config.StoreDir = filepath.Join(config.StoreDir, JetStreamStoreDir)
Expand Down
12 changes: 11 additions & 1 deletion server/monitor_test.go
Expand Up @@ -4116,13 +4116,15 @@ func TestMonitorJsz(t *testing.T) {
max_mem_store: 10Mb
max_file_store: 10Mb
store_dir: '%s'
unique_tag: az
}
cluster {
name: cluster_name
listen: 127.0.0.1:%d
routes: [nats-route://127.0.0.1:%d]
}
server_name: server_%d `, test.port, test.mport, tmpDir, test.cport, test.routed, test.port)))
server_name: server_%d
server_tags: [ "az:%d" ] `, test.port, test.mport, tmpDir, test.cport, test.routed, test.port, test.port)))
defer removeFile(t, cf)

s, _ := RunServerWithConfig(cf)
Expand Down Expand Up @@ -4393,6 +4395,14 @@ func TestMonitorJsz(t *testing.T) {
}
}
})
t.Run("unique-tag-exists", func(t *testing.T) {
for _, url := range []string{monUrl1, monUrl2} {
info := readJsInfo(url)
if len(info.Config.UniqueTag) == 0 {
t.Fatalf("expected unique_tag to be returned by %s but got %v", url, info)
}
}
})
}

func TestMonitorReloadTLSConfig(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Expand Up @@ -1769,6 +1769,7 @@ func (s *Server) Start() {
MaxStore: opts.JetStreamMaxStore,
Domain: opts.JetStreamDomain,
CompressOK: true,
UniqueTag: opts.JetStreamUniqueTag,
}
if err := s.EnableJetStream(cfg); err != nil {
s.Fatalf("Can't start JetStream: %v", err)
Expand Down

0 comments on commit a5398e1

Please sign in to comment.