Skip to content

Commit

Permalink
Add viz stat-inbound and viz stat-outbound commands (#12994)
Browse files Browse the repository at this point in the history
We add two new commands to the linkerd viz extension: `linkerd viz stat-inbound` and `linkerd viz stat-outbound`.  These commands are meant as replacements for the `linkerd viz stat`.  The `linkerd viz stat` command provides stats when ServiceProfiles are used whereas the new commands provide stats when xRoute resources are used.  Either command can be used when no xRoute or ServiceProfile is used but the new commands include several improvements:

* Inbound and outbound stats are clearly separated into different commands rather than being contextual based on flag combinations
* Route level and backend level stats are displayed together in a tree-view in `linkerd viz stat-outbound` to easily see the effects of retries, timeouts, and traffic splitting

```
> linkerd viz stat-outbound -n schlep deploy                  
NAME         SERVICE      ROUTE           TYPE       BACKEND    SUCCESS   RPS  LATENCY_P50  LATENCY_P95  LATENCY_P99  TIMEOUTS  RETRIES  
client-http  schlep:80    schlep-default  HTTPRoute             100.00%  1.00         31ms        387ms        478ms     0.00%    6.25%  
                          └───────────────────────►  schlep:80   93.75%  1.07         16ms         88ms         98ms     1.56%           
client-grpc  schlep:8080  schlep-default  GRPCRoute              98.31%  0.98         36ms        425ms        485ms     0.00%    0.00%  
                          ├───────────────────────►  fail:8080   96.88%  0.53         12ms         24ms         25ms     0.00%           
                          └───────────────────────►  good:8080  100.00%  0.45         25ms         95ms         99ms     0.00%
```

```
> linkerd viz stat-inbound -n schlep deploy
NAME         SERVER          ROUTE      TYPE  SUCCESS   RPS  LATENCY_P50  LATENCY_P95  LATENCY_P99  
client-grpc  [default]:4191  [default]        100.00%  0.10          2ms          3ms          3ms  
client-grpc  [default]:4191  probe            100.00%  0.20          0ms          1ms          1ms  
client-http  [default]:4191  [default]        100.00%  0.10          2ms          2ms          2ms  
client-http  [default]:4191  probe            100.00%  0.20          0ms          1ms          1ms  
server-fail  [default]:4191  probe            100.00%  0.20          0ms          1ms          1ms  
server-fail  [default]:4191  [default]        100.00%  0.10          2ms          2ms          2ms  
server-fail  [default]:8080  [default]         94.87%  1.30          0ms          1ms          1ms  
server-good  [default]:4191  [default]        100.00%  0.10          0ms          1ms          1ms  
server-good  [default]:4191  probe            100.00%  0.20          0ms          1ms          1ms  
server-good  [default]:8080  [default]        100.00%  0.73          8ms         92ms         98ms  
server-slow  [default]:4191  [default]        100.00%  0.10          0ms          1ms          1ms  
server-slow  [default]:4191  probe            100.00%  0.20          0ms          1ms          1ms
```

Unlike the `linkerd viz stat` command, these commands query prometheus directly rather than going through the intermediary of the metrics-api.  If prometheus is enabled in linkerd-viz, these commands will use a port-forward to connect to that prometheus instance.  If an external prometheus is configured, these commands will attempt to use that prometheus URL; however note that the prometheus URL must be reachable from where the CLI is executed for this to work.  This can be overridden by a `--prometheusURL` flag.

Json and table output are both supported.

Signed-off-by: Alex Leong <[email protected]>
  • Loading branch information
adleong committed Aug 29, 2024
1 parent 4a7c705 commit 366ab94
Show file tree
Hide file tree
Showing 15 changed files with 1,240 additions and 161 deletions.
27 changes: 19 additions & 8 deletions cli/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"sort"
"strings"
"unicode/utf8"
)

type (
Expand Down Expand Up @@ -48,7 +49,7 @@ func NewColumn(header string) Column {
return Column{
Header: header,
Flexible: true,
Width: len(header),
Width: utf8.RuneCountInString(header),
}
}

Expand All @@ -74,8 +75,8 @@ func (t *Table) columnWidths() []int {
width := col.Width
if col.Flexible {
for _, row := range t.Data {
if len(row[c]) > width {
width = len(row[c])
if utf8.RuneCountInString(row[c]) > width {
width = utf8.RuneCountInString(row[c])
}
}
}
Expand Down Expand Up @@ -106,14 +107,24 @@ func (t *Table) renderRow(w io.Writer, row Row, columnWidths []int) {
continue
}
value := row[c]
if len(value) > columnWidths[c] {
if utf8.RuneCountInString(value) > columnWidths[c] {
value = value[:columnWidths[c]]
}
padding := strings.Repeat(" ", columnWidths[c]-len(value))
if col.LeftAlign {
fmt.Fprintf(w, "%s%s%s", value, padding, t.ColumnSpacing)
padding := strings.Repeat(" ", columnWidths[c]-utf8.RuneCountInString(value))
spacing := t.ColumnSpacing
if strings.HasSuffix(value, "─") && c < len(t.Columns)-1 && strings.HasPrefix(row[c+1], "─") {
spacing = "──"
}
if strings.HasPrefix(value, "─") {
padding = strings.Repeat("─", columnWidths[c]-utf8.RuneCountInString(value))
fmt.Fprintf(w, "%s%s%s", padding, value, spacing)
} else if strings.HasSuffix(value, "─") {
padding = strings.Repeat("─", columnWidths[c]-utf8.RuneCountInString(value))
fmt.Fprintf(w, "%s%s%s", value, padding, spacing)
} else if col.LeftAlign {
fmt.Fprintf(w, "%s%s%s", value, padding, spacing)
} else {
fmt.Fprintf(w, "%s%s%s", padding, value, t.ColumnSpacing)
fmt.Fprintf(w, "%s%s%s", padding, value, spacing)
}
}
fmt.Fprint(w, "\n")
Expand Down
2 changes: 2 additions & 0 deletions viz/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func NewCmdViz() *cobra.Command {
vizCmd.AddCommand(newCmdProfile())
vizCmd.AddCommand(NewCmdRoutes())
vizCmd.AddCommand(NewCmdStat())
vizCmd.AddCommand(NewCmdStatInbound())
vizCmd.AddCommand(NewCmdStatOutbound())
vizCmd.AddCommand(NewCmdTap())
vizCmd.AddCommand(NewCmdTop())
vizCmd.AddCommand(newCmdUninstall())
Expand Down
Loading

0 comments on commit 366ab94

Please sign in to comment.