Include config in info for msgset

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2019-12-10 22:00:20 +01:00
parent 8a29444616
commit b3b2feebc5
5 changed files with 44 additions and 13 deletions

View File

@@ -390,15 +390,24 @@ func getMsgSetInfo(nc *nats.Conn, name string) {
if strings.HasPrefix(string(resp.Data), api.ErrPrefix) {
log.Fatalf("%q", resp.Data)
}
var mstats api.MsgSetStats
if err = json.Unmarshal(resp.Data, &mstats); err != nil {
var msi api.MsgSetInfo
if err = json.Unmarshal(resp.Data, &msi); err != nil {
log.Fatalf("Unexpected error: %v", err)
}
mstats := &msi.Stats
cfg := &msi.Config
log.Println()
log.Printf("Messages: %s", humanize.Comma(int64(mstats.Msgs)))
log.Printf("Bytes: %s", humanize.Bytes(mstats.Bytes))
log.Printf("FirstSeq: %s", humanize.Comma(int64(mstats.FirstSeq)))
log.Printf("LastSeq: %s", humanize.Comma(int64(mstats.LastSeq)))
log.Printf("Subjects: %+v", cfg.Subjects)
log.Printf("Retention: %s", cfg.Retention)
log.Printf("TTL: %v", cfg.MaxAge)
log.Printf("Messages: %s of %s",
humanize.Comma(int64(mstats.Msgs)),
unlimitedOrFriendly(int(cfg.MaxMsgs)))
log.Printf("Bytes: %s of %s",
humanize.Bytes(mstats.Bytes),
unlimitedOrFriendly(int(cfg.MaxBytes)))
log.Printf("FirstSeq: %s", humanize.Comma(int64(mstats.FirstSeq)))
log.Printf("LastSeq: %s", humanize.Comma(int64(mstats.LastSeq)))
log.Println()
}

View File

@@ -897,8 +897,11 @@ func (s *Server) jsMsgSetInfoRequest(sub *subscription, c *client, subject, repl
s.sendInternalAccountMsg(c.acc, reply, fmt.Sprintf("%s %v", ErrPrefix, err))
return
}
stats := mset.Stats()
b, err := json.MarshalIndent(stats, "", " ")
msi := MsgSetInfo{
Stats: mset.Stats(),
Config: mset.Config(),
}
b, err := json.MarshalIndent(msi, "", " ")
if err != nil {
return
}

View File

@@ -36,6 +36,11 @@ type MsgSetConfig struct {
NoAck bool `json:"no_ack,omitempty"`
}
type MsgSetInfo struct {
Config MsgSetConfig `json:"name"`
Stats MsgSetStats `json:"stats"`
}
// RetentionPolicy determines how messages in a set are retained.
type RetentionPolicy int

View File

@@ -95,6 +95,19 @@ const (
workQueuePolicyString = "work_queue"
)
func (rp RetentionPolicy) String() string {
switch rp {
case StreamPolicy:
return "Limits"
case InterestPolicy:
return "Interest"
case WorkQueuePolicy:
return "WorkQueue"
default:
return "Unknown Retention Policy"
}
}
func (rp RetentionPolicy) MarshalJSON() ([]byte, error) {
switch rp {
case StreamPolicy:

View File

@@ -16,6 +16,7 @@ package test
import (
"encoding/json"
"fmt"
"log"
"math/rand"
"os"
"path/filepath"
@@ -2836,12 +2837,12 @@ func TestJetStreamRequestAPI(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
var mstats server.MsgSetStats
if err = json.Unmarshal(resp.Data, &mstats); err != nil {
t.Fatalf("Unexpected error: %v", err)
var msi server.MsgSetInfo
if err = json.Unmarshal(resp.Data, &msi); err != nil {
log.Fatalf("Unexpected error: %v", err)
}
if mstats.Msgs != uint64(toSend) {
t.Fatalf("Expected to get %d msgs, got %d", toSend, mstats.Msgs)
if msi.Stats.Msgs != uint64(toSend) {
t.Fatalf("Expected to get %d msgs, got %d", toSend, msi.Stats.Msgs)
}
// Looking up on that is not there should yield an error.