forked from openservicemesh/osm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxds.go
50 lines (39 loc) · 1.15 KB
/
xds.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package debugger
import (
"fmt"
"net/http"
"sort"
"time"
"github.com/openservicemesh/osm/pkg/envoy"
)
func (ds DebugConfig) getXDSHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
xdsLog := ds.xdsDebugger.GetXDSLog()
var proxies []string
for proxyID := range xdsLog {
proxies = append(proxies, proxyID)
}
sort.Strings(proxies)
for _, proxyName := range proxies {
xdsTypeWithTimestamps := xdsLog[proxyName]
_, _ = fmt.Fprintf(w, "---[ %s\n", proxyName)
var xdsTypes []string
for xdsType := range xdsTypeWithTimestamps {
xdsTypes = append(xdsTypes, xdsType.String())
}
sort.Strings(xdsTypes)
for _, xdsType := range xdsTypes {
timeStamps := xdsTypeWithTimestamps[envoy.TypeURI(xdsType)]
_, _ = fmt.Fprintf(w, "\t %s (%d):\n", xdsType, len(timeStamps))
sort.Slice(timeStamps, func(i, j int) bool {
return timeStamps[i].After(timeStamps[j])
})
for _, timeStamp := range timeStamps {
_, _ = fmt.Fprintf(w, "\t\t%+v (%+v ago)\n", timeStamp, time.Since(timeStamp))
}
_, _ = fmt.Fprint(w, "\n")
}
_, _ = fmt.Fprint(w, "\n")
}
})
}