-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Admin server - part 2 #10482
Merged
Merged
Admin server - part 2 #10482
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is definitely a good reminder that we should pull contextutils into this repo to work towards not needing the go-utils dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i noticed we use it everywhere for logging. do we no longer want the go-utils dep, even for logging stuff?
if so, i can work on removing it completely from the repo (in a separate PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so but its definitely a different pr.
I wonder if we also just fork it from go-utils and put it in a smaller kgateway-dev repo? Thats the hard question: where should it live.
Lets bring it to the community meeting today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should remove the contextutils/go-utils dep entirely but i dont think it should factor into this work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed. This is more of an interesting point that we still want something that allows this toggle to change logging holistically from a single end point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree that this is out of scope for this change, but for context, we probably want to change they way we do logging - having them attached to the context is annoying: