Skip to content

Commit

Permalink
cscli metrics: explicit message "no bouncer metrics found" (#3155)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc authored Jul 29, 2024
1 parent 20067a8 commit 6f5d75c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion cmd/crowdsec-cli/climetrics/statbouncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,15 @@ func (s *statBouncer) bouncerTable(out io.Writer, bouncerName string, wantColor
}

// Table displays a table of metrics for each bouncer
func (s *statBouncer) Table(out io.Writer, wantColor string, noUnit bool, _ bool) {
func (s *statBouncer) Table(out io.Writer, wantColor string, noUnit bool, showEmpty bool) {
found := false

for _, bouncerName := range maptools.SortedKeys(s.aggOverOrigin) {
s.bouncerTable(out, bouncerName, wantColor, noUnit)
found = true
}

if !found && showEmpty {
io.WriteString(out, "No bouncer metrics found.\n\n")
}
}
11 changes: 8 additions & 3 deletions test/bats/08_metrics_bouncer.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ teardown() {

#----------

@test "cscli metrics show bouncers" {
# there are no bouncers, so no metrics yet
@test "cscli metrics show bouncers (empty)" {
# this message is given only if we ask explicitly for bouncers
notfound="No bouncer metrics found."

rune -0 cscli metrics show bouncers
refute_output
assert_output "$notfound"

rune -0 cscli metrics list
refute_output "$notfound"
}

@test "rc usage metrics (empty payload)" {
Expand Down

0 comments on commit 6f5d75c

Please sign in to comment.