Skip to content
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

Jacek request UI #61

Merged
merged 8 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions quesma/quesma/ui/asset/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -480,34 +480,74 @@
background-color: #dddddd;
}

#request-log-messages table, #errors table {
#request-info {
background-color: rgb(0, 0, 0);
color: white;
}

#request-info .title {
margin-top: 0;
background-color: #333;
color: white;
padding: 0 5px;
}

#request-info pre {
padding: 0 5px;
}

#request-info .title-logs {
margin-top: 1em;
}

#request-info .two-columns {
display: flex;
height: 48%;
}

#request-info .elastic-response, #request-info .quesma-response, #request-info .query-body, #request-info .query-body-translated {
flex: 1;
overflow: auto;
}

#request-info .query-body, #request-info .quesma-response {
background-color: rgb(221, 226, 235);
color: black;
}

#request-info .query-body, #request-info .elastic-response {
border-right: white 5px solid;
}

#request-info table, #errors table {
border-collapse: collapse;
table-layout: fixed;
width: 98%;
word-wrap: break-word;
margin-bottom: 1em;
}

#request-log-messages th, #request-log-messages td, #errors table th, #errors table td {
#request-info th, #request-info td, #errors table th, #errors table td {
border: 1px solid rgb(221, 226, 235);
font-family: Courier;
font-size: small;
padding: 0 3px;
}

#request-log-messages .time {
#request-info .time {
width: 10%;
}

#request-log-messages .level {
#request-info .level {
width: 5%;
}

#request-log-messages .message {
#request-info .message {
width: 55%;
white-space: pre-wrap;
}

#request-log-messages .fields {
#request-info .fields {
width: 28%;
white-space: pre-wrap;
}
Expand Down
5 changes: 0 additions & 5 deletions quesma/quesma/ui/console_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ func (qmc *QuesmaManagementConsole) createRouting() *mux.Router {
buf := qmc.generateReportForRequestId(vars["requestId"])
_, _ = writer.Write(buf)
})
router.PathPrefix("/log/{requestId}").HandlerFunc(func(writer http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
buf := qmc.generateLogForRequestId(vars["requestId"])
_, _ = writer.Write(buf)
})
router.PathPrefix("/error/{reason}").HandlerFunc(func(writer http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
buf := qmc.generateErrorForReason(vars["reason"])
Expand Down
2 changes: 1 addition & 1 deletion quesma/quesma/ui/html_pages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestHtmlPages(t *testing.T) {
})

t.Run("logs got no XSS", func(t *testing.T) {
response := string(qmc.generateLogForRequestId(id))
response := string(qmc.generateReportForRequestId(id))
assert.NotContains(t, response, xss)
})

Expand Down
128 changes: 83 additions & 45 deletions quesma/quesma/ui/live_tail_drilldown.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"gopkg.in/yaml.v3"
"mitmproxy/quesma/quesma/ui/internal/builder"
"mitmproxy/quesma/quesma/ui/internal/sqlfmt"
"strings"
)

Expand All @@ -13,27 +14,104 @@ func (qmc *QuesmaManagementConsole) generateReportForRequestId(requestId string)
request, requestFound := qmc.debugInfoMessages[requestId]
qmc.mutex.Unlock()

logMessages, optAsyncId := generateLogMessages(request.logMessages, []string{})

buffer := newBufferWithHead()
if requestFound {
buffer.Write(generateSimpleTop("Report for request UUID " + requestId))
if optAsyncId != nil {
buffer.Write(generateSimpleTop("Report for request id " + requestId + " and async id " + *optAsyncId))
} else {
buffer.Write(generateSimpleTop("Report for request id " + requestId))
}
} else {
buffer.Write(generateSimpleTop("Report not found for request UUID " + requestId))
}

buffer.Html(`<main id="queries">`)
buffer.Html(`<main id="request-info">` + "\n")

// Show Request and SQL
if requestFound {
buffer.Html(`<div class="two-columns">` + "\n")
buffer.Html(`<div class="query-body">` + "\n")
buffer.Html("<p class=\"title\">Original query:</p>\n")
buffer.Html(`<pre>`)
buffer.Text(string(request.IncomingQueryBody))
buffer.Html("\n</pre>")
buffer.Html(`</div>` + "\n")

buffer.Html(`<div class="query-body-translated">` + "\n")
buffer.Html("<p class=\"title\">Translated SQL:</p>\n")
buffer.Html(`<pre>`)
buffer.Text(sqlfmt.SqlPrettyPrint(request.QueryBodyTranslated))
buffer.Html("\n</pre>")
buffer.Html(`</div>` + "\n")
buffer.Html(`</div>` + "\n")
}

buffer.Html("\n\n")
buffer.Html(`<div class="debug-body">`)

buffer.Html(`<p class="title title-logs">`)
if requestFound && len(request.logMessages) > 0 {
buffer.Html("Logs:</p>\n")
buffer.Write(logMessages)
} else {
buffer.Html("No logs for this request</p>\n")
}

debugKeyValueSlice := []queryDebugInfoWithId{}
// Show ElasticSearch and Quesma Response
if requestFound {
debugKeyValueSlice = append(debugKeyValueSlice, queryDebugInfoWithId{requestId, request})
buffer.Html(`<div class="two-columns">` + "\n")
buffer.Html(`<div class="elastic-response">` + "\n")
if len(request.QueryDebugPrimarySource.QueryResp) > 0 {
tookStr := fmt.Sprintf(" took %d ms:", request.PrimaryTook.Milliseconds())
buffer.Html("<p class=\"title\">Elastic response").Text(tookStr).Html("</p>\n")
buffer.Html(`<pre>`)
buffer.Text(string(request.QueryDebugPrimarySource.QueryResp))
buffer.Html("\n</pre>")
} else {
buffer.Html("<p class=\"title\">No Elastic response for this request</p>\n")
}
buffer.Html(`</div>` + "\n")

buffer.Html(`<div class="quesma-response">` + "\n")
if len(request.QueryDebugSecondarySource.QueryTranslatedResults) > 0 {
tookStr := fmt.Sprintf(" took %d ms:", request.SecondaryTook.Milliseconds())
buffer.Html("<p class=\"title\">Quesma response").Text(tookStr).Html("</p>\n")
buffer.Html(`<pre>`)
buffer.Text(string(request.QueryDebugSecondarySource.QueryTranslatedResults))
buffer.Html("\n</pre>")
} else {
buffer.Html("<p class=\"title\">No Quesma response for this request</p>\n")
}
buffer.Html(`</div>` + "\n")
buffer.Html(`</div>` + "\n")
}

buffer.Write(generateQueries(debugKeyValueSlice, false))
buffer.Html("\n</div>\n")

buffer.Html("\n</main>\n")
buffer.Html(`<div class="menu">`)
buffer.Html("\n<h2>Menu</h2>")

buffer.Html(`<form action="/live">&nbsp;<input class="btn" type="submit" value="Back to live tail" /></form>`)
buffer.Html(`<br>`)

if requestFound {
buffer.Html("\n<h2>Request info</h2>")
buffer.Html("<ul>\n")
buffer.Html("<li>").Text("Request id: ").Text(requestId).Html("</li>\n")
buffer.Html("<li>").Text("Path: ").Text(request.Path).Html("</li>\n")
if optAsyncId != nil {
buffer.Html("<li>").Text("Async id: ").Text(*optAsyncId).Html("</li>\n")
}
if request.unsupported != nil {
buffer.Html("<li>").Text("Unsupported: ").Text(*request.unsupported).Html("</li>\n")
}
buffer.Html("</ul>\n")
}

buffer.Html("\n<h2>Log types</h2>")
if requestFound {
buffer.Html(`<ul>`)
if request.errorLogCount > 0 {
Expand All @@ -49,46 +127,6 @@ func (qmc *QuesmaManagementConsole) generateReportForRequestId(requestId string)

buffer.Html(`</ul>`)
}
buffer.Html(`<form action="/log/`).Text(requestId).Html(`">&nbsp;<input class="btn" type="submit" value="Go to log" /></form>`)

buffer.Html("\n</div>")
buffer.Html("\n</body>")
buffer.Html("\n</html>")
return buffer.Bytes()
}

func (qmc *QuesmaManagementConsole) generateLogForRequestId(requestId string) []byte {
qmc.mutex.Lock()
request, requestFound := qmc.debugInfoMessages[requestId]
qmc.mutex.Unlock()

logMessages, optAsyncId := generateLogMessages(request.logMessages, []string{})

buffer := newBufferWithHead()
if requestFound {
if optAsyncId != nil {
buffer.Write(generateSimpleTop("Log for request id " + requestId + " and async id " + *optAsyncId))
} else {
buffer.Write(generateSimpleTop("Log for request id " + requestId))
}
} else {
buffer.Write(generateSimpleTop("Log not found for request id " + requestId))
}

buffer.Html(`<main class="center" id="request-log-messages">`)
buffer.Html("\n\n")
buffer.Html(`<div class="debug-body">`)

buffer.Write(logMessages)

buffer.Html("\n</div>\n")
buffer.Html("\n</main>\n")
buffer.Html(`<div class="menu">`)
buffer.Html("\n<h2>Menu</h2>")

buffer.Html(`<form action="/live">&nbsp;<input class="btn" type="submit" value="Back to live tail" /></form>`)
buffer.Html(`<br>`)
buffer.Html(`<form action="/request-id/`).Text(requestId).Html(`">&nbsp;<input class="btn" type="submit" value="Back to request info" /></form>`)

buffer.Html("\n</div>")
buffer.Html("\n</body>")
Expand Down
Loading