@@ -21,6 +21,8 @@ import (
21
21
"html"
22
22
"math/rand"
23
23
"net/http"
24
+ "sort"
25
+ "strings"
24
26
"time"
25
27
26
28
"k8s.io/component-base/compatibility"
@@ -29,7 +31,14 @@ import (
29
31
)
30
32
31
33
var (
32
- delimiters = []string {":" , ": " , "=" , " " }
34
+ delimiters = []string {":" , ": " , "=" , " " }
35
+ nonDebuggingEndpoints = map [string ]bool {
36
+ "/apis" : true ,
37
+ "/api" : true ,
38
+ "/openid" : true ,
39
+ "/openapi" : true ,
40
+ "/.well-known" : true ,
41
+ }
33
42
)
34
43
35
44
const DefaultStatuszPath = "/statusz"
@@ -43,8 +52,15 @@ type mux interface {
43
52
Handle (path string , handler http.Handler )
44
53
}
45
54
46
- func NewRegistry (effectiveVersion compatibility.EffectiveVersion ) statuszRegistry {
47
- return & registry {effectiveVersion : effectiveVersion }
55
+ type ListedPathsOption []string
56
+
57
+ func NewRegistry (effectiveVersion compatibility.EffectiveVersion , opts ... func (* registry )) statuszRegistry {
58
+ r := & registry {effectiveVersion : effectiveVersion }
59
+ for _ , opt := range opts {
60
+ opt (r )
61
+ }
62
+
63
+ return r
48
64
}
49
65
50
66
func Install (m mux , componentName string , reg statuszRegistry ) {
@@ -59,7 +75,7 @@ func handleStatusz(componentName string, reg statuszRegistry) http.HandlerFunc {
59
75
}
60
76
61
77
fmt .Fprintf (w , headerFmt , componentName )
62
- data , err := populateStatuszData (reg )
78
+ data , err := populateStatuszData (reg , componentName )
63
79
if err != nil {
64
80
klog .Errorf ("error while populating statusz data: %v" , err )
65
81
http .Error (w , "error while populating statusz data" , http .StatusInternalServerError )
@@ -71,7 +87,7 @@ func handleStatusz(componentName string, reg statuszRegistry) http.HandlerFunc {
71
87
}
72
88
}
73
89
74
- func populateStatuszData (reg statuszRegistry ) (string , error ) {
90
+ func populateStatuszData (reg statuszRegistry , componentName string ) (string , error ) {
75
91
randomIndex := rand .Intn (len (delimiters ))
76
92
delim := html .EscapeString (delimiters [randomIndex ])
77
93
startTime := html .EscapeString (reg .processStartTime ().Format (time .UnixDate ))
@@ -83,14 +99,19 @@ func populateStatuszData(reg statuszRegistry) (string, error) {
83
99
if reg .emulationVersion () != nil {
84
100
emulationVersion = fmt .Sprintf (`Emulation version%s %s` , delim , html .EscapeString (reg .emulationVersion ().String ()))
85
101
}
102
+ paths := aggregatePaths (reg .paths ())
103
+ if paths != "" {
104
+ paths = fmt .Sprintf (`Paths%s %s` , delim , html .EscapeString (paths ))
105
+ }
86
106
87
107
status := fmt .Sprintf (`
88
108
Started%[1]s %[2]s
89
109
Up%[1]s %[3]s
90
110
Go version%[1]s %[4]s
91
111
Binary version%[1]s %[5]s
92
112
%[6]s
93
- ` , delim , startTime , uptime , goVersion , binaryVersion , emulationVersion )
113
+ %[7]s
114
+ ` , delim , startTime , uptime , goVersion , binaryVersion , emulationVersion , paths )
94
115
95
116
return status , nil
96
117
}
@@ -100,3 +121,26 @@ func uptime(t time.Time) string {
100
121
return fmt .Sprintf ("%d hr %02d min %02d sec" ,
101
122
upSince / 3600 , (upSince / 60 )% 60 , upSince % 60 )
102
123
}
124
+
125
+ func aggregatePaths (listedPaths []string ) string {
126
+ paths := make (map [string ]bool )
127
+ for _ , listedPath := range listedPaths {
128
+ folder := "/" + strings .Split (listedPath , "/" )[1 ]
129
+ if ! paths [folder ] && ! nonDebuggingEndpoints [folder ] {
130
+ paths [folder ] = true
131
+ }
132
+ }
133
+
134
+ var sortedPaths []string
135
+ for p := range paths {
136
+ sortedPaths = append (sortedPaths , p )
137
+ }
138
+ sort .Strings (sortedPaths )
139
+
140
+ var path string
141
+ for _ , p := range sortedPaths {
142
+ path += " " + p
143
+ }
144
+
145
+ return path
146
+ }
0 commit comments