Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/roeschter/natscli
Browse files Browse the repository at this point in the history
  • Loading branch information
roeschter committed Nov 20, 2024
2 parents 057e3f7 + 18f677a commit 9286bdd
Show file tree
Hide file tree
Showing 42 changed files with 3,454 additions and 302 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ jobs:
shell: bash --noprofile --norc -x -eo pipefail {0}
run: |
PATH=$PATH:$GOPATH/bin
GO_LIST=$(go list ./...)
GO_LIST=$(go list ./... | grep -F -e asciigraph -v)
$(exit $(go fmt $GO_LIST | wc -l))
go vet -composites=false $GO_LIST
find . -type f -name "*.go" | xargs misspell -error -locale US
find . -type f -name "*.go" | grep -F -e asciigraph -v | xargs misspell -error -locale US
staticcheck -f stylish $GO_LIST
- name: Run tests
shell: bash --noprofile --norc -x -eo pipefail {0}
run: |
set -e
go test -v --failfast -p=1 ./...
go list ./... | grep -F -e asciigraph -v | xargs go test -v --failfast -p=1
set +e
8 changes: 4 additions & 4 deletions ABTaskFile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ commands:
script: |
set -e

go test ./...
go list ./... | grep -F -e asciigraph -v |xargs go test

- name: lint
type: exec
Expand Down Expand Up @@ -60,17 +60,17 @@ commands:

{{ if .Flags.spell }}
ab_say Checking spelling
find . -type f -name "*.go" | xargs misspell -error -locale US -i flavour
find . -type f -name "*.go" | grep -F -e asciigraph -v | xargs misspell -error -locale US -i flavour
{{ end }}

{{ if .Flags.vet }}
ab_say Performing go vet
go vet ./...
go list ./... | grep -F -e asciigraph -v |xargs go vet
{{ end }}

{{ if .Flags.staticcheck }}
ab_say Running staticcheck
staticcheck ./...
go list ./... | grep -F -e asciigraph -v |xargs staticcheck
{{ end }}

- name: dependencies
Expand Down
3 changes: 2 additions & 1 deletion cli/account_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (c *actCmd) reportServerStats(_ *fisk.ParseContext) error {
}

table := newTableWriter("Server Statistics")
table.AddHeaders("Server", "Cluster", "Version", "Tags", "Connections", "Leafnodes", "Sent Bytes", "Sent Messages", "Received Bytes", "Received Messages", "Slow Consumers")
table.AddHeaders("Server", "Cluster", "Version", "Tags", "Connections", "Subscriptions", "Leafnodes", "Sent Bytes", "Sent Messages", "Received Bytes", "Received Messages", "Slow Consumers")

var (
conn, ln int
Expand Down Expand Up @@ -267,6 +267,7 @@ func (c *actCmd) reportServerStats(_ *fisk.ParseContext) error {
sz.ServerInfo.Version,
f(sz.ServerInfo.Tags),
f(stats.Conns),
f(stats.NumSubs),
f(stats.LeafNodes),
humanize.IBytes(uint64(stats.Sent.Bytes)),
f(stats.Sent.Msgs),
Expand Down
3 changes: 2 additions & 1 deletion cli/audit_gather_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ func (c *auditGatherCmd) gather(_ *fisk.ParseContext) error {
// Discover servers by broadcasting a PING and then collecting responses
func (c *auditGatherCmd) discoverServers(nc *nats.Conn) (map[string]*server.ServerInfo, error) {
var serverInfoMap = make(map[string]*server.ServerInfo)

c.logProgress("Broadcasting PING to discover servers... (this may take a few seconds)")
err := doReqAsync(nil, "$SYS.REQ.SERVER.PING", 0, nc, func(b []byte) {
err := doReqAsync(nil, "$SYS.REQ.SERVER.PING", doReqAsyncWaitFullTimeoutInterval, nc, func(b []byte) {
var apiResponse server.ServerAPIResponse
if err := json.Unmarshal(b, &apiResponse); err != nil {
c.logWarning("Failed to deserialize PING response: %s", err)
Expand Down
9 changes: 8 additions & 1 deletion cli/bench_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type benchCmd struct {
fetchTimeout bool
multiSubject bool
multiSubjectMax int
multisubjectFormat string
deDuplication bool
deDuplicationWindow time.Duration
ack bool
Expand Down Expand Up @@ -453,7 +454,7 @@ func (c *benchCmd) getPublishSubject(number int) string {
if c.multiSubjectMax == 0 {
return c.subject + "." + strconv.Itoa(number)
} else {
return c.subject + "." + strconv.Itoa(number%c.multiSubjectMax)
return c.subject + "." + fmt.Sprintf(c.multisubjectFormat, number%c.multiSubjectMax)
}
} else {
return c.subject
Expand Down Expand Up @@ -1546,6 +1547,8 @@ func (c *benchCmd) coreNATSPublisher(nc *nats.Conn, progress *uiprogress.Bar, ms
})
}

c.multisubjectFormat = fmt.Sprintf("%%0%dd", len(strconv.Itoa(c.multiSubjectMax)))

for i := 0; i < numMsg; i++ {
if progress != nil {
progress.Incr()
Expand Down Expand Up @@ -1575,6 +1578,8 @@ func (c *benchCmd) coreNATSRequester(nc *nats.Conn, progress *uiprogress.Bar, ms
})
}

c.multisubjectFormat = fmt.Sprintf("%%0%dd", len(strconv.Itoa(c.multiSubjectMax)))

for i := 0; i < numMsg; i++ {
if progress != nil {
progress.Incr()
Expand Down Expand Up @@ -1610,6 +1615,8 @@ func (c *benchCmd) jsPublisher(nc *nats.Conn, progress *uiprogress.Bar, msg []by
})
}

c.multisubjectFormat = fmt.Sprintf("%%0%dd", len(strconv.Itoa(c.multiSubjectMax)))

if c.batchSize != 1 {
for i := 0; i < numMsg; {
state = "Publishing"
Expand Down
8 changes: 8 additions & 0 deletions cli/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ func fiBytes(v uint64) string {
func f(v any) string {
return columns.F(v)
}

func fFloat2Int(v any) string {
return columns.F(uint64(v.(float64)))
}

func fiBytesFloat2Int(v any) string {
return fiBytes(uint64(v.(float64)))
}
Loading

0 comments on commit 9286bdd

Please sign in to comment.