mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 21:27:31 +00:00
sockstats: switch label to enum
Makes it cheaper/simpler to persist values, and encourages reuse of labels as opposed to generating an arbitrary number. Updates tailscale/corp#9230 Updates #3363 Signed-off-by: Mihai Parparita <mihai@tailscale.com>
This commit is contained in:

committed by
Mihai Parparita

parent
9687f3700d
commit
6ac6ddbb47
@@ -879,11 +879,13 @@ func (h *peerAPIHandler) handleServeSockStats(w http.ResponseWriter, r *http.Req
|
||||
fmt.Fprintln(w, "</thead>")
|
||||
|
||||
fmt.Fprintln(w, "<tbody>")
|
||||
labels := make([]string, 0, len(stats.Stats))
|
||||
labels := make([]sockstats.Label, 0, len(stats.Stats))
|
||||
for label := range stats.Stats {
|
||||
labels = append(labels, label)
|
||||
}
|
||||
sort.Strings(labels)
|
||||
slices.SortFunc(labels, func(a, b sockstats.Label) bool {
|
||||
return a.String() < b.String()
|
||||
})
|
||||
|
||||
txTotal := int64(0)
|
||||
rxTotal := int64(0)
|
||||
@@ -893,7 +895,7 @@ func (h *peerAPIHandler) handleServeSockStats(w http.ResponseWriter, r *http.Req
|
||||
for _, label := range labels {
|
||||
stat := stats.Stats[label]
|
||||
fmt.Fprintln(w, "<tr>")
|
||||
fmt.Fprintf(w, "<td>%s</td>", html.EscapeString(label))
|
||||
fmt.Fprintf(w, "<td>%s</td>", html.EscapeString(label.String()))
|
||||
fmt.Fprintf(w, "<td align=right>%d</td>", stat.TxBytes)
|
||||
fmt.Fprintf(w, "<td align=right>%d</td>", stat.RxBytes)
|
||||
|
||||
|
Reference in New Issue
Block a user