From 571a375f2efe2aaf82bb30e9093aec12edb2a94e Mon Sep 17 00:00:00 2001 From: Todd Beets Date: Fri, 11 Nov 2022 13:36:13 -0800 Subject: [PATCH 1/3] add unique_tag to JetStreamConfig for varz/jsz visibility --- server/jetstream.go | 8 ++++++-- server/server.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/server/jetstream.go b/server/jetstream.go index e6a46b45560..4ad3a3bc7a5 100644 --- a/server/jetstream.go +++ b/server/jetstream.go @@ -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. @@ -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) @@ -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) diff --git a/server/server.go b/server/server.go index 532dc3f9f21..6df3037f0ac 100644 --- a/server/server.go +++ b/server/server.go @@ -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) From aae1d623789e27a8eefc34becd48eea2a9f6cb3e Mon Sep 17 00:00:00 2001 From: Todd Beets Date: Fri, 11 Nov 2022 15:26:01 -0800 Subject: [PATCH 2/3] test for unique_tag present in response --- server/monitor_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/monitor_test.go b/server/monitor_test.go index ecf861f9c8e..828fdc0cd40 100644 --- a/server/monitor_test.go +++ b/server/monitor_test.go @@ -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) @@ -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) { From 40bbfbacc9597493fa8b3513bfe0b4c4740f74d2 Mon Sep 17 00:00:00 2001 From: Todd Beets Date: Sat, 12 Nov 2022 07:53:20 -0800 Subject: [PATCH 3/3] correct spaces to tabs in raw string literal --- server/monitor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/monitor_test.go b/server/monitor_test.go index 828fdc0cd40..b3cfac6d380 100644 --- a/server/monitor_test.go +++ b/server/monitor_test.go @@ -4124,7 +4124,7 @@ func TestMonitorJsz(t *testing.T) { routes: [nats-route://127.0.0.1:%d] } server_name: server_%d - server_tags: [ "az:%d" ] `, test.port, test.mport, tmpDir, test.cport, test.routed, test.port, test.port))) + server_tags: [ "az:%d" ] `, test.port, test.mport, tmpDir, test.cport, test.routed, test.port, test.port))) defer removeFile(t, cf) s, _ := RunServerWithConfig(cf)