Repository: nats-io/nats-server
Pull request #5652 (2024-07-15 08:11:31)

Report the js limits in jsz output
Reports some often requested information about JS config in jsz

Signed-off-by: R.I.Pienaar <rip@devco.net>


ripienaar: Ok I will update that json key in a few hours 

Patch:
diff --git a/.goreleaser.yml b/.goreleaser.yml
index 91905885..51a0d21d 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -16,7 +16,7 @@ builds:
   flags:
   - -trimpath
   ldflags:
-    - -w -X 'github.com/nats-io/nats-server/v2/server.gitCommit={{.ShortCommit}}' -X 'github.com/nats-io/nats-server/v2/server.serverVersion={{.Tag}}'
+    - -w -X github.com/nats-io/nats-server/v2/server.gitCommit={{.ShortCommit}}
   env:
     - GO111MODULE=on
     - CGO_ENABLED=0
diff --git a/server/const.go b/server/const.go
index 8b88341f..82e968f5 100644
--- a/server/const.go
+++ b/server/const.go
@@ -15,7 +15,6 @@ package server
 
 import (
 	"regexp"
-	"runtime/debug"
 	"time"
 )
 
@@ -35,27 +34,14 @@ const (
 )
 
 var (
-	// gitCommit and serverVersion injected at build.
-	gitCommit, serverVersion string
+	// gitCommit injected at build
+	gitCommit string
 	// trustedKeys is a whitespace separated array of trusted operator's public nkeys.
 	trustedKeys string
 	// SemVer regexp to validate the VERSION.
 	semVerRe = regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
 )
 
-func init() {
-	// Use build info if present, it would be if building using 'go build .'
-	// or when using a release.
-	if info, ok := debug.ReadBuildInfo(); ok {
-		for _, setting := range info.Settings {
-			switch setting.Key {
-			case "vcs.revision":
-				gitCommit = setting.Value[:7]
-			}
-		}
-	}
-}
-
 const (
 	// VERSION is the current version for the server.
 	VERSION = "2.11.0-dev"
diff --git a/server/filestore.go b/server/filestore.go
index b034ac77..6e10ede8 100644
--- a/server/filestore.go
+++ b/server/filestore.go
@@ -2975,10 +2975,6 @@ func (fs *fileStore) NumPending(sseq uint64, filter string, lastPerSubject bool)
 		return 0, validThrough
 	}
 
-	// If sseq is less then our first set to first.
-	if sseq < fs.state.FirstSeq {
-		sseq = fs.state.FirstSeq
-	}
 	// Track starting for both block for the sseq and staring block that matches any subject.
 	var seqStart int
 	// See if we need to figure out starting block per sseq.
diff --git a/server/monitor.go b/server/monitor.go
index fb601d97..2fa89f9f 100644
--- a/server/monitor.go
+++ b/server/monitor.go
@@ -1387,8 +1387,6 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
 	var srcUrl string
 	if gitCommit == _EMPTY_ {
 		srcUrl = "https://github.com/nats-io/nats-server"
-	} else if serverVersion != _EMPTY_ {
-		srcUrl = fmt.Sprintf("https://github.com/nats-io/nats-server/tree/%s", serverVersion)
 	} else {
 		srcUrl = fmt.Sprintf("https://github.com/nats-io/nats-server/tree/%s", gitCommit)
 	}
@@ -2795,6 +2793,7 @@ type JSInfo struct {
 	Now      time.Time       `json:"now"`
 	Disabled bool            `json:"disabled,omitempty"`
 	Config   JetStreamConfig `json:"config,omitempty"`
+	Limits   JSLimitOpts     `json:"limits"`
 	JetStreamStats
 	Streams   int              `json:"streams"`
 	Consumers int              `json:"consumers"`
@@ -2959,6 +2958,8 @@ func (s *Server) Jsz(opts *JSzOptions) (*JSInfo, error) {
 		return jsi, nil
 	}
 
+	jsi.Limits = s.getOpts().JetStreamLimits
+
 	js.mu.RLock()
 	isLeader := js.cluster == nil || js.cluster.isLeader()
 	js.mu.RUnlock()
diff --git a/server/opts.go b/server/opts.go
index e717f26e..08d9baad 100644
--- a/server/opts.go
+++ b/server/opts.go
@@ -233,10 +233,10 @@ type RemoteLeafOpts struct {
 }
 
 type JSLimitOpts struct {
-	MaxRequestBatch int
-	MaxAckPending   int
-	MaxHAAssets     int
-	Duplicates      time.Duration
+	MaxRequestBatch int           `json:"max_request_batch,omitempty"`
+	MaxAckPending   int           `json:"max_ack_pending,omitempty"`
+	MaxHAAssets     int           `json:"max_ha_assets,omitempty"`
+	Duplicates      time.Duration `json:"max_duplicate_window,omitempty"`
 }
 
 type JSTpmOpts struct {


Test patch:
diff --git a/scripts/runTestsOnTravis.sh b/scripts/runTestsOnTravis.sh
index 45847886..6d2b8f37 100755
--- a/scripts/runTestsOnTravis.sh
+++ b/scripts/runTestsOnTravis.sh
@@ -10,7 +10,7 @@ if [ "$1" = "compile" ]; then
     go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1;
     golangci-lint run;
     if [ "$TRAVIS_TAG" != "" ]; then
-        go test -race -v -run=TestVersionMatchesTag ./server -ldflags="-X=github.com/nats-io/nats-server/v2/server.serverVersion=$TRAVIS_TAG" -count=1 -vet=off
+        go test -race -v -run=TestVersionMatchesTag ./server -count=1 -vet=off
     fi
 
 elif [ "$1" = "build_only" ]; then
diff --git a/server/jetstream_test.go b/server/jetstream_test.go
index a4559cc8..d153255a 100644
--- a/server/jetstream_test.go
+++ b/server/jetstream_test.go
@@ -23763,47 +23763,3 @@ func TestJetStreamBadSubjectMappingStream(t *testing.T) {
 
 	require_Error(t, err, NewJSStreamUpdateError(errors.New("unable to get subject transform for source: invalid mapping destination: too many arguments passed to the function in {{wildcard(1)}}{{split(3,1)}}")))
 }
-
-func TestJetStreamConsumerInfoNumPending(t *testing.T) {
-	s := RunBasicJetStreamServer(t)
-	defer s.Shutdown()
-
-	// Client for API requests.
-	nc, js := jsClientConnect(t, s)
-	defer nc.Close()
-
-	_, err := js.AddStream(&nats.StreamConfig{
-		Name:     "LIMITS",
-		Subjects: []string{"js.in.limits"},
-		MaxMsgs:  100,
-	})
-	require_NoError(t, err)
-
-	_, err = js.AddConsumer("LIMITS", &nats.ConsumerConfig{
-		Name:      "PULL",
-		AckPolicy: nats.AckExplicitPolicy,
-	})
-	require_NoError(t, err)
-
-	for i := 0; i < 1000; i++ {
-		js.Publish("js.in.limits", []byte("x"))
-	}
-
-	ci, err := js.ConsumerInfo("LIMITS", "PULL")
-	require_NoError(t, err)
-	require_Equal(t, ci.NumPending, 100)
-
-	// Now restart the server.
-	sd := s.JetStreamConfig().StoreDir
-	s.Shutdown()
-	// Restart.
-	s = RunJetStreamServerOnPort(-1, sd)
-	defer s.Shutdown()
-
-	nc, js = jsClientConnect(t, s)
-	defer nc.Close()
-
-	ci, err = js.ConsumerInfo("LIMITS", "PULL")
-	require_NoError(t, err)
-	require_Equal(t, ci.NumPending, 100)
-}
diff --git a/server/monitor_test.go b/server/monitor_test.go
index 949fdb8e..60faf361 100644
--- a/server/monitor_test.go
+++ b/server/monitor_test.go
@@ -4298,6 +4298,9 @@ func TestMonitorJsz(t *testing.T) {
 			max_file_store: 10Mb
 			store_dir: '%s'
 			unique_tag: az
+			limits: {
+				max_ha_assets: 1000
+			}
 		}
 		cluster {
 			name: cluster_name
@@ -4377,6 +4380,9 @@ func TestMonitorJsz(t *testing.T) {
 			if info.Messages != 2 {
 				t.Fatalf("expected two message but got %d", info.Messages)
 			}
+			if info.Limits.MaxHAAssets != 1000 {
+				t.Fatalf("expected max_ha_assets limit to be 1000 got %v", info.Limits)
+			}
 		}
 	})
 	t.Run("accounts", func(t *testing.T) {
diff --git a/server/server_test.go b/server/server_test.go
index 08789a20..483fb7be 100644
--- a/server/server_test.go
+++ b/server/server_test.go
@@ -143,17 +143,6 @@ func TestVersionMatchesTag(t *testing.T) {
 	if VERSION != tag[1:] {
 		t.Fatalf("Version (%s) does not match tag (%s)", VERSION, tag[1:])
 	}
-	// Check that the version dynamically set via ldflags matches the version
-	// from the server previous to releasing.
-	if serverVersion == _EMPTY_ {
-		t.Fatal("Version missing in ldflags")
-	}
-	// Unlike VERSION constant, serverVersion is prefixed with a 'v'
-	// since it should be the same as the git tag.
-	expected := "v" + VERSION
-	if serverVersion != _EMPTY_ && expected != serverVersion {
-		t.Fatalf("Version (%s) does not match ldflags version (%s)", expected, serverVersion)
-	}
 }
 
 func TestStartProfiler(t *testing.T) {