-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
168 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package admin | ||
|
||
import ( | ||
"net/http" | ||
|
||
"istio.io/istio/pkg/kube/krt" | ||
) | ||
|
||
func addKrtSnapshotHandler(path string, mux *http.ServeMux, profiles map[string]dynamicProfileDescription, dbg *krt.DebugHandler) { | ||
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { | ||
writeJSON(w, dbg, r) | ||
}) | ||
profiles[path] = func() string { return "KRT Snapshot" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package admin | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/solo-io/go-utils/contextutils" | ||
) | ||
|
||
// The logging handler is an AtomicLevel that supports dynamically changing the log level at runtime. | ||
func addLoggingHandler(path string, mux *http.ServeMux, profiles map[string]dynamicProfileDescription) { | ||
mux.Handle(path, contextutils.GetLogHandler()) | ||
profiles[path] = getLoggingDescription | ||
} | ||
|
||
// Gets a string representation of the current log level. | ||
func getLogLevel() string { | ||
return contextutils.GetLogLevel().String() | ||
} | ||
|
||
// Gets the html/js to display in the UI for the logging endpoint. | ||
func getLoggingDescription() string { | ||
currentLogLevel := getLogLevel() | ||
|
||
// build the options selector, with the current log level selected by default | ||
selectorText := `<select id="loglevelselector">` | ||
supportedLogLevels := []string{"debug", "info", "warn", "error"} | ||
for _, level := range supportedLogLevels { | ||
if level == currentLogLevel { | ||
selectorText += fmt.Sprintf(`<option value="%s" selected>%s</option>`, level, level) | ||
} else { | ||
selectorText += fmt.Sprintf(`<option value="%s">%s</option>`, level, level) | ||
} | ||
} | ||
selectorText += `</select>` | ||
|
||
return `View or change the log level of the program. Note: does not persist across pod restarts.<br/> | ||
Log level: | ||
` + selectorText + ` | ||
<button onclick="setlevel(document.getElementById('loglevelselector').value)">Submit</button> | ||
<script> | ||
function setlevel(l) { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('PUT', '/logging', true); | ||
xhr.setRequestHeader("Content-Type", "application/json"); | ||
xhr.onreadystatechange = function() { | ||
if (this.readyState == 4 && this.status == 200) { | ||
var resp = JSON.parse(this.responseText); | ||
alert("log level set to: " + resp["level"]); | ||
} | ||
}; | ||
xhr.send('{"level":"' + l + '"}'); | ||
} | ||
</script> | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package admin | ||
|
||
import ( | ||
"net/http" | ||
"net/http/pprof" | ||
) | ||
|
||
func addPprofHandler(path string, mux *http.ServeMux, profiles map[string]dynamicProfileDescription) { | ||
mux.HandleFunc(path, pprof.Index) | ||
mux.HandleFunc(path+"cmdline", pprof.Cmdline) | ||
mux.HandleFunc(path+"profile", pprof.Profile) | ||
mux.HandleFunc(path+"symbol", pprof.Symbol) | ||
mux.HandleFunc(path+"trace", pprof.Trace) | ||
|
||
profiles[path] = func() string { | ||
return `PProf related things:<br/> | ||
<a href="` + path + `goroutine?debug=2">full goroutine stack dump</a> | ||
` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package admin | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/envoyproxy/go-control-plane/pkg/cache/v3" | ||
envoycache "github.com/envoyproxy/go-control-plane/pkg/cache/v3" | ||
"github.com/rotisserie/eris" | ||
) | ||
|
||
// The xDS Snapshot is intended to return the full in-memory xDS cache that the Control Plane manages | ||
// and serves up to running proxies. | ||
func addXdsSnapshotHandler(path string, mux *http.ServeMux, profiles map[string]dynamicProfileDescription, cache envoycache.SnapshotCache) { | ||
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { | ||
response := getXdsSnapshotDataFromCache(cache) | ||
writeJSON(w, response, r) | ||
}) | ||
profiles[path] = func() string { return "XDS Snapshot" } | ||
} | ||
|
||
func getXdsSnapshotDataFromCache(xdsCache cache.SnapshotCache) SnapshotResponseData { | ||
cacheKeys := xdsCache.GetStatusKeys() | ||
cacheEntries := make(map[string]interface{}, len(cacheKeys)) | ||
|
||
for _, k := range cacheKeys { | ||
xdsSnapshot, err := getXdsSnapshot(xdsCache, k) | ||
if err != nil { | ||
cacheEntries[k] = err.Error() | ||
} else { | ||
cacheEntries[k] = xdsSnapshot | ||
} | ||
} | ||
|
||
return completeSnapshotResponse(cacheEntries) | ||
} | ||
|
||
func getXdsSnapshot(xdsCache cache.SnapshotCache, k string) (cache cache.ResourceSnapshot, err error) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
err = eris.New(fmt.Sprintf("panic occurred while getting xds snapshot: %v", r)) | ||
} | ||
}() | ||
return xdsCache.GetSnapshot(k) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters