Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(2.11) ADR-44: JetStream API Level in varz,jsz,statsz,$JS.API.INFO #5855

Merged
merged 15 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions server/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3675,3 +3675,25 @@ func TestServerEventsProfileZNotBlockingRecvQ(t *testing.T) {
})
}
}

func TestServerEventsStatsZJetStreamApiLevel(t *testing.T) {
s, opts := runTrustedServer(t)
defer s.Shutdown()

acc, akp := createAccount(s)
s.setSystemAccount(acc)
s.EnableJetStream(&JetStreamConfig{StoreDir: t.TempDir()})

url := fmt.Sprintf("nats://%s:%d", opts.Host, opts.Port)
ncs, err := nats.Connect(url, createUserCreds(t, s, akp))
require_NoError(t, err)

msg, err := ncs.Request("$SYS.REQ.SERVER.PING.STATSZ", nil, time.Second)
require_NoError(t, err)

var stats ServerStatsMsg
err = json.Unmarshal(msg.Data, &stats)
require_NoError(t, err)

require_Equal(t, stats.Stats.JetStream.Stats.API.Level, JSApiLevel)
}
3 changes: 3 additions & 0 deletions server/jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type JetStreamAccountStats struct {
}

type JetStreamAPIStats struct {
Level int `json:"level"`
Total uint64 `json:"total"`
Errors uint64 `json:"errors"`
Inflight uint64 `json:"inflight,omitempty"`
Expand Down Expand Up @@ -1685,6 +1686,7 @@ func (a *Account) JetStreamUsage() JetStreamAccountStats {
stats.Memory, stats.Store = jsa.storageTotals()
stats.Domain = js.config.Domain
stats.API = JetStreamAPIStats{
Level: JSApiLevel,
Total: jsa.apiTotal,
Errors: jsa.apiErrors,
}
Expand Down Expand Up @@ -2374,6 +2376,7 @@ func (js *jetStream) usageStats() *JetStreamStats {
stats.ReservedStore = uint64(js.storeReserved)
s := js.srv
js.mu.RUnlock()
stats.API.Level = JSApiLevel
stats.API.Total = uint64(atomic.LoadInt64(&js.apiTotal))
stats.API.Errors = uint64(atomic.LoadInt64(&js.apiErrors))
stats.API.Inflight = uint64(atomic.LoadInt64(&js.apiInflight))
Expand Down
3 changes: 3 additions & 0 deletions server/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7488,6 +7488,9 @@ func TestJetStreamRequestAPI(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}

// JS API level should be set.
require_Equal(t, info.API.Level, JSApiLevel)

// Now create a stream.
msetCfg := StreamConfig{
Name: "MSET22",
Expand Down
21 changes: 21 additions & 0 deletions server/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4677,6 +4677,12 @@ func TestMonitorJsz(t *testing.T) {
}
}
})
t.Run("js-api-level", func(t *testing.T) {
for _, url := range []string{monUrl1, monUrl2} {
info := readJsInfo(url)
require_Equal(t, info.API.Level, JSApiLevel)
}
})
}

func TestMonitorReloadTLSConfig(t *testing.T) {
Expand Down Expand Up @@ -5418,3 +5424,18 @@ func TestVarzSyncInterval(t *testing.T) {
require_True(t, jscfg.SyncInterval == opts.SyncInterval)
require_True(t, jscfg.SyncAlways)
}

func TestVarzJSApiLevel(t *testing.T) {
resetPreviousHTTPConnections()
opts := DefaultMonitorOptions()
opts.JetStream = true

s := RunServer(opts)
defer s.Shutdown()

url := fmt.Sprintf("http://127.0.0.1:%d/varz", s.MonitorAddr().Port)

varz := pollVarz(t, s, 0, url, nil)
apiLevel := varz.JetStream.Stats.API.Level
require_Equal(t, apiLevel, JSApiLevel)
}
35 changes: 35 additions & 0 deletions test/configs/jetstream/restore_empty_R1F_stream/backup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"config": {
"name": "STREAM",
"subjects": [
"stream"
],
"retention": "limits",
"max_consumers": -1,
"max_msgs_per_subject": -1,
"max_msgs": -1,
"max_bytes": -1,
"max_age": 0,
"max_msg_size": -1,
"storage": "file",
"discard": "old",
"num_replicas": 1,
"duplicate_window": 120000000000,
"sealed": false,
"deny_delete": false,
"deny_purge": false,
"allow_rollup_hdrs": false,
"allow_direct": true,
"mirror_direct": false,
"consumer_limits": {}
},
"state": {
"messages": 0,
"bytes": 0,
"first_seq": 0,
"first_ts": "0001-01-01T00:00:00Z",
"last_seq": 0,
"last_ts": "0001-01-01T00:00:00Z",
"consumer_count": 0
}
}
Binary file not shown.
35 changes: 35 additions & 0 deletions test/configs/jetstream/restore_empty_R3F_stream/backup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"config": {
"name": "STREAM",
"subjects": [
"stream"
],
"retention": "limits",
"max_consumers": -1,
"max_msgs_per_subject": -1,
"max_msgs": -1,
"max_bytes": -1,
"max_age": 0,
"max_msg_size": -1,
"storage": "file",
"discard": "old",
"num_replicas": 3,
"duplicate_window": 120000000000,
"sealed": false,
"deny_delete": false,
"deny_purge": false,
"allow_rollup_hdrs": false,
"allow_direct": true,
"mirror_direct": false,
"consumer_limits": {}
},
"state": {
"messages": 0,
"bytes": 0,
"first_seq": 0,
"first_ts": "0001-01-01T00:00:00Z",
"last_seq": 0,
"last_ts": "0001-01-01T00:00:00Z",
"consumer_count": 0
}
}
Binary file not shown.