@@ -21,6 +21,8 @@ import (
2121 "html"
2222 "math/rand"
2323 "net/http"
24+ "sort"
25+ "strings"
2426 "time"
2527
2628 "k8s.io/component-base/compatibility"
@@ -29,7 +31,14 @@ import (
2931)
3032
3133var (
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+ }
3342)
3443
3544const DefaultStatuszPath = "/statusz"
@@ -43,8 +52,15 @@ type mux interface {
4352 Handle (path string , handler http.Handler )
4453}
4554
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
4864}
4965
5066func Install (m mux , componentName string , reg statuszRegistry ) {
@@ -59,7 +75,7 @@ func handleStatusz(componentName string, reg statuszRegistry) http.HandlerFunc {
5975 }
6076
6177 fmt .Fprintf (w , headerFmt , componentName )
62- data , err := populateStatuszData (reg )
78+ data , err := populateStatuszData (reg , componentName )
6379 if err != nil {
6480 klog .Errorf ("error while populating statusz data: %v" , err )
6581 http .Error (w , "error while populating statusz data" , http .StatusInternalServerError )
@@ -71,7 +87,7 @@ func handleStatusz(componentName string, reg statuszRegistry) http.HandlerFunc {
7187 }
7288}
7389
74- func populateStatuszData (reg statuszRegistry ) (string , error ) {
90+ func populateStatuszData (reg statuszRegistry , componentName string ) (string , error ) {
7591 randomIndex := rand .Intn (len (delimiters ))
7692 delim := html .EscapeString (delimiters [randomIndex ])
7793 startTime := html .EscapeString (reg .processStartTime ().Format (time .UnixDate ))
@@ -83,14 +99,19 @@ func populateStatuszData(reg statuszRegistry) (string, error) {
8399 if reg .emulationVersion () != nil {
84100 emulationVersion = fmt .Sprintf (`Emulation version%s %s` , delim , html .EscapeString (reg .emulationVersion ().String ()))
85101 }
102+ paths := aggregatePaths (reg .paths ())
103+ if paths != "" {
104+ paths = fmt .Sprintf (`Paths%s %s` , delim , html .EscapeString (paths ))
105+ }
86106
87107 status := fmt .Sprintf (`
88108Started%[1]s %[2]s
89109Up%[1]s %[3]s
90110Go version%[1]s %[4]s
91111Binary version%[1]s %[5]s
92112%[6]s
93- ` , delim , startTime , uptime , goVersion , binaryVersion , emulationVersion )
113+ %[7]s
114+ ` , delim , startTime , uptime , goVersion , binaryVersion , emulationVersion , paths )
94115
95116 return status , nil
96117}
@@ -100,3 +121,26 @@ func uptime(t time.Time) string {
100121 return fmt .Sprintf ("%d hr %02d min %02d sec" ,
101122 upSince / 3600 , (upSince / 60 )% 60 , upSince % 60 )
102123}
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