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 minor UI #22

Merged
merged 6 commits into from
May 2, 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
36 changes: 26 additions & 10 deletions quesma/quesma/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,16 @@ func (q *QueryRunner) handleSearchCommon(ctx context.Context, cfg config.QuesmaC

startTime := time.Now()
id := ctx.Value(tracing.RequestIdCtxKey).(string)
path := ""
if value := ctx.Value(tracing.RequestPath); value != nil {
if str, ok := value.(string); ok {
path = str
}
}
pushSecondaryInfoToManagementConsole := func() {
qmc.PushSecondaryInfo(&ui.QueryDebugSecondarySource{
Id: id,
Path: path,
IncomingQueryBody: body,
QueryBodyTranslated: translatedQueryBody,
QueryTranslatedResults: responseBody,
Expand Down Expand Up @@ -299,11 +306,11 @@ func (q *QueryRunner) handleSearchCommon(ctx context.Context, cfg config.QuesmaC
go func() { // Async search takes longer. Return partial results and wait for
recovery.LogPanicWithCtx(ctx)
res := <-optAsync.doneCh
q.storeAsyncSearch(qmc, id, optAsync.asyncRequestIdStr, optAsync.startTime, body, res, true)
q.storeAsyncSearch(qmc, id, optAsync.asyncRequestIdStr, optAsync.startTime, path, body, res, true)
}()
return q.handlePartialAsyncSearch(ctx, optAsync.asyncRequestIdStr)
case res := <-optAsync.doneCh:
responseBody, err = q.storeAsyncSearch(qmc, id, optAsync.asyncRequestIdStr, optAsync.startTime, body, res,
responseBody, err = q.storeAsyncSearch(qmc, id, optAsync.asyncRequestIdStr, optAsync.startTime, path, body, res,
optAsync.keepOnCompletion)

return responseBody, err
Expand All @@ -312,26 +319,35 @@ func (q *QueryRunner) handleSearchCommon(ctx context.Context, cfg config.QuesmaC
}

func (q *QueryRunner) storeAsyncSearch(qmc *ui.QuesmaManagementConsole, id, asyncRequestIdStr string,
startTime time.Time, body []byte, result AsyncSearchWithError, keep bool) (responseBody []byte, err error) {
startTime time.Time, path string, body []byte, result AsyncSearchWithError, keep bool) (responseBody []byte, err error) {
took := time.Since(startTime)
defer qmc.PushSecondaryInfo(&ui.QueryDebugSecondarySource{
Id: id,
IncomingQueryBody: body,
QueryBodyTranslated: result.translatedQueryBody,
QueryTranslatedResults: responseBody,
SecondaryTook: took,
})
if result.err != nil {
if keep {
q.AsyncRequestStorage.Store(asyncRequestIdStr, AsyncRequestResult{err: result.err, added: time.Now(),
isCompressed: false})
}
responseBody, _ = queryparser.EmptyAsyncSearchResponse(asyncRequestIdStr, false, 503)
err = result.err
qmc.PushSecondaryInfo(&ui.QueryDebugSecondarySource{
Id: id,
Path: path,
IncomingQueryBody: body,
QueryBodyTranslated: result.translatedQueryBody,
QueryTranslatedResults: responseBody,
SecondaryTook: took,
})
return
}
asyncResponse := queryparser.SearchToAsyncSearchResponse(result.response, asyncRequestIdStr, false, 200)
responseBody, err = asyncResponse.Marshal()
qmc.PushSecondaryInfo(&ui.QueryDebugSecondarySource{
Id: id,
Path: path,
IncomingQueryBody: body,
QueryBodyTranslated: result.translatedQueryBody,
QueryTranslatedResults: responseBody,
SecondaryTook: took,
})
if keep {
compressedBody := responseBody
isCompressed := false
Expand Down
8 changes: 7 additions & 1 deletion quesma/quesma/termsenum/terms_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ func handleTermsEnumRequest(ctx context.Context, table string, reqBody []byte, q
} else {
result, err = json.Marshal(makeTermsEnumResponse(rows))
}

path := ""
if value := ctx.Value(tracing.RequestPath); value != nil {
if str, ok := value.(string); ok {
path = str
}
}
qmc.PushSecondaryInfo(&ui.QueryDebugSecondarySource{
Id: ctx.Value(tracing.RequestIdCtxKey).(string),
Path: path,
IncomingQueryBody: reqBody,
QueryBodyTranslated: []byte(selectQuery.String()),
QueryTranslatedResults: result,
Expand Down
26 changes: 16 additions & 10 deletions quesma/quesma/ui/html_pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (qmc *QuesmaManagementConsole) generateDatasources() []byte {
buffer.Html(`<div class="menu">`)
buffer.Html("\n<h2>Menu</h2>")

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

buffer.Html("\n</div>")

Expand All @@ -461,7 +461,7 @@ func (qmc *QuesmaManagementConsole) generateRouterStatisticsLiveTail() []byte {
buffer.Html(`<div class="menu">`)
buffer.Html("\n<h2>Menu</h2>")

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

buffer.Html("\n</div>")

Expand All @@ -481,7 +481,7 @@ func (qmc *QuesmaManagementConsole) generateStatisticsLiveTail() []byte {
buffer.Html(`<div class="menu">`)
buffer.Html("\n<h2>Menu</h2>")

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

buffer.Html("\n</div>")

Expand Down Expand Up @@ -632,7 +632,6 @@ func (qmc *QuesmaManagementConsole) generateDashboard() []byte {
buffer.Html(`<li><a href="http://localhost:5601/app/observability-log-explorer/">Kibana Log Explorer</a></li>`)
buffer.Html(`<li><a href="http://localhost:8081">mitmproxy</a></li>`)
buffer.Html(`<li><a href="http://localhost:8123/play">Clickhouse</a></li>`)
buffer.Html(`<li><a href="/ingest-statistics">Ingest statistics</a></li>`)
buffer.Html(`</ul>`)

buffer.Html("\n</div>")
Expand Down Expand Up @@ -668,7 +667,7 @@ func (qmc *QuesmaManagementConsole) generateReportForRequestId(requestId string)
buffer.Html(`<div class="menu">`)
buffer.Html("\n<h2>Menu</h2>")

buffer.Html(`<form action="/">&nbsp;<input class="btn" type="submit" value="Back to live tail" /></form>`)
buffer.Html(`<form action="/live">&nbsp;<input class="btn" type="submit" value="Back to live tail" /></form>`)
if requestFound {
buffer.Html(`<ul>`)
if request.errorLogCount > 0 {
Expand Down Expand Up @@ -723,9 +722,9 @@ func (qmc *QuesmaManagementConsole) generateLogForRequestId(requestId string) []
buffer.Html(`<div class="menu">`)
buffer.Html("\n<h2>Menu</h2>")

buffer.Html(`<form action="/">&nbsp;<input class="btn" type="submit" value="Back to live tail" /></form>`)
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(`<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 Expand Up @@ -781,7 +780,14 @@ func generateLogMessages(logMessages []string) ([]byte, *string) {
// level
buffer.Html(`<td class="level">`)
if level, ok := fields["level"].(string); ok {
buffer.Text(level).Html("</td>")
if level == "error" {
buffer.Html(`<span class="debug-error-log">`)
} else if level == "warn" {
buffer.Html(`<span class="debug-warn-log">`)
} else {
buffer.Html(`<span>`)
}
buffer.Text(level).Html("</span></td>")
delete(fields, "level")
} else {
buffer.Html("missing level</td>")
Expand Down Expand Up @@ -876,7 +882,7 @@ func (qmc *QuesmaManagementConsole) generateReportForRequests(title string, requ
buffer.Html(`<div class="menu">`)
buffer.Html("\n<h2>Menu</h2>")

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

buffer.Html("\n</div>")
buffer.Html("\n</body>")
Expand All @@ -903,7 +909,7 @@ func (qmc *QuesmaManagementConsole) generateErrorForReason(reason string) []byte
buffer.Html(`<div class="menu">`)
buffer.Html("\n<h2>Menu</h2>")

buffer.Html(`<form action="/dashboard">&nbsp;<input class="btn" type="submit" value="Back to dashboard" /></form>`)
buffer.Html(`<form action="/">&nbsp;<input class="btn" type="submit" value="Back to dashboard" /></form>`)
// TODO: implement
// buffer.Html(`<form action="/dashboard">&nbsp;<input class="btn" type="submit" value="See requests with errors" /></form>`)
buffer.Html("\n</div>")
Expand Down
1 change: 1 addition & 0 deletions quesma/quesma/ui/html_pages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestHtmlPages(t *testing.T) {
qmc := NewQuesmaManagementConsole(config.QuesmaConfiguration{}, nil, nil, logChan, telemetry.NewPhoneHomeEmptyAgent())
qmc.PushPrimaryInfo(&QueryDebugPrimarySource{Id: id, QueryResp: xssBytes})
qmc.PushSecondaryInfo(&QueryDebugSecondarySource{Id: id,
Path: xss,
IncomingQueryBody: xssBytes,
QueryBodyTranslated: xssBytes,
QueryTranslatedResults: xssBytes,
Expand Down
2 changes: 1 addition & 1 deletion quesma/quesma/ui/html_panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func generateQueries(debugKeyValueSlice []DebugKeyValue, withLinks bool) []byte
if withLinks {
buffer.Html(`<a href="/request-Id/`).Text(v.Key).Html(`">`)
}
buffer.Html("<p>RequestID:").Text(v.Key).Html("</p>\n")
buffer.Html("<p>RequestID:").Text(v.Key).Html(" Path: ").Text(v.Value.Path).Html("</p>\n")
buffer.Html(`<pre Id="query`).Text(v.Key).Html(`">`)
buffer.Text(string(v.Value.IncomingQueryBody))
buffer.Html("\n</pre>")
Expand Down
16 changes: 8 additions & 8 deletions quesma/quesma/ui/management_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type QueryDebugPrimarySource struct {
type QueryDebugSecondarySource struct {
Id string

Path string
IncomingQueryBody []byte

QueryBodyTranslated []byte
Expand Down Expand Up @@ -90,8 +91,8 @@ type QuesmaManagementConsole struct {

func NewQuesmaManagementConsole(config config.QuesmaConfiguration, logManager *clickhouse.LogManager, indexManager elasticsearch.IndexManagement, logChan <-chan tracing.LogWithLevel, phoneHomeAgent telemetry.PhoneHomeAgent) *QuesmaManagementConsole {
return &QuesmaManagementConsole{
queryDebugPrimarySource: make(chan *QueryDebugPrimarySource, 5),
queryDebugSecondarySource: make(chan *QueryDebugSecondarySource, 5),
queryDebugPrimarySource: make(chan *QueryDebugPrimarySource, 10),
queryDebugSecondarySource: make(chan *QueryDebugSecondarySource, 10),
queryDebugLogs: logChan,
debugInfoMessages: make(map[string]QueryDebugInfo),
debugLastMessages: make([]string, 0),
Expand All @@ -109,13 +110,10 @@ func NewQuesmaManagementConsole(config config.QuesmaConfiguration, logManager *c
}

func (qmc *QuesmaManagementConsole) PushPrimaryInfo(qdebugInfo *QueryDebugPrimarySource) {
qdebugInfo.QueryResp = []byte(util.JsonPrettify(string(qdebugInfo.QueryResp), true))
qmc.queryDebugPrimarySource <- qdebugInfo
}

func (qmc *QuesmaManagementConsole) PushSecondaryInfo(qdebugInfo *QueryDebugSecondarySource) {
qdebugInfo.QueryTranslatedResults = []byte(util.JsonPrettify(string(qdebugInfo.QueryTranslatedResults), true))
qdebugInfo.IncomingQueryBody = []byte(util.JsonPrettify(string(qdebugInfo.IncomingQueryBody), true))
qmc.queryDebugSecondarySource <- qdebugInfo
}

Expand Down Expand Up @@ -219,7 +217,8 @@ func (qmc *QuesmaManagementConsole) processChannelMessage() {
select {
case msg := <-qmc.queryDebugPrimarySource:
logger.Debug().Msg("Received debug info from primary source: " + msg.Id)
debugPrimaryInfo := QueryDebugPrimarySource{msg.Id, msg.QueryResp, msg.PrimaryTook}
debugPrimaryInfo := QueryDebugPrimarySource{msg.Id,
[]byte(util.JsonPrettify(string(msg.QueryResp), true)), msg.PrimaryTook}
qmc.mutex.Lock()
if value, ok := qmc.debugInfoMessages[msg.Id]; !ok {
qmc.debugInfoMessages[msg.Id] = QueryDebugInfo{
Expand All @@ -240,9 +239,10 @@ func (qmc *QuesmaManagementConsole) processChannelMessage() {
logger.Debug().Msg("Received debug info from secondary source: " + msg.Id)
secondaryDebugInfo := QueryDebugSecondarySource{
msg.Id,
msg.IncomingQueryBody,
msg.Path,
[]byte(util.JsonPrettify(string(msg.IncomingQueryBody), true)),
msg.QueryBodyTranslated,
msg.QueryTranslatedResults,
[]byte(util.JsonPrettify(string(msg.QueryTranslatedResults), true)),
msg.SecondaryTook,
}
qmc.mutex.Lock()
Expand Down
Loading