Skip to content

Commit

Permalink
UI refactor (#40)
Browse files Browse the repository at this point in the history
1. Data sources were causing bugs, due to not implemented panel
endpoint.
2. Fix collision.
  • Loading branch information
jakozaur authored May 6, 2024
1 parent d54389f commit 9931a0c
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 39 deletions.
7 changes: 6 additions & 1 deletion quesma/quesma/ui/console_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (qmc *QuesmaManagementConsole) createRouting() *mux.Router {
})

router.HandleFunc("/data-sources", func(writer http.ResponseWriter, req *http.Request) {
buf := qmc.generateDatasources()
buf := qmc.generateDatasourcesPage()
_, _ = writer.Write(buf)
})

Expand Down Expand Up @@ -107,6 +107,11 @@ func (qmc *QuesmaManagementConsole) createRouting() *mux.Router {
_, _ = writer.Write(buf)
})

router.HandleFunc("/panel/data-sources", func(writer http.ResponseWriter, req *http.Request) {
buf := qmc.generateDatasources()
_, _ = writer.Write(buf)
})

router.PathPrefix("/request-Id/{requestId}").HandlerFunc(func(writer http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
buf := qmc.generateReportForRequestId(vars["requestId"])
Expand Down
6 changes: 3 additions & 3 deletions quesma/quesma/ui/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/mem"
"mitmproxy/quesma/buildinfo"
"mitmproxy/quesma/quesma/ui/internal/buffer"
"mitmproxy/quesma/quesma/ui/internal/builder"
"mitmproxy/quesma/stats/errorstats"
"net/url"
"runtime"
Expand Down Expand Up @@ -90,7 +90,7 @@ func (qmc *QuesmaManagementConsole) generateDashboardTrafficElement(typeName str
}

func (qmc *QuesmaManagementConsole) generateDashboardTrafficPanel() []byte {
var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer

// Clickhouse -> Kibana
if qmc.config.ReadsFromClickhouse() {
Expand Down Expand Up @@ -124,7 +124,7 @@ func statusToDiv(s healthCheckStatus) string {
}

func (qmc *QuesmaManagementConsole) generateDashboardPanel() []byte {
var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer

dashboardName := "<h3>Kibana</h3>"
storeName := "<h3>Elasticsearch</h3>"
Expand Down
37 changes: 22 additions & 15 deletions quesma/quesma/ui/data_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@ package ui

import (
"fmt"
"mitmproxy/quesma/quesma/ui/internal/builder"
"slices"
"strings"
)

func (qmc *QuesmaManagementConsole) generateDatasources() []byte {
func (qmc *QuesmaManagementConsole) generateDatasourcesPage() []byte {
buffer := newBufferWithHead()
buffer.Write(generateTopNavigation("datasources"))
buffer.Write(generateTopNavigation("data-sources"))

buffer.Html(`<main id="data-sources">`)
buffer.Write(qmc.generateDatasources())

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

buffer.Html(`<main id="datasources">`)
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("\n</div>")

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

func (qmc *QuesmaManagementConsole) generateDatasources() []byte {
var buffer builder.HtmlBuffer
buffer.Html(`<h2>Data sources</h2>`)

buffer.Html(`<h3>Clickhouse</h3>`)
Expand Down Expand Up @@ -64,17 +83,5 @@ func (qmc *QuesmaManagementConsole) generateDatasources() []byte {
}

buffer.Html(`</ul>`)

buffer.Html("\n</main>\n\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("\n</div>")

buffer.Html("\n</body>")
buffer.Html("\n</html>")
return buffer.Bytes()
}
12 changes: 6 additions & 6 deletions quesma/quesma/ui/html_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package ui

import (
"fmt"
"mitmproxy/quesma/quesma/ui/internal/buffer"
"mitmproxy/quesma/quesma/ui/internal/builder"
"net/url"
)

func generateSimpleTop(title string) []byte {
var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer
buffer.Html(`<div class="topnav">` + "\n")
buffer.Html(`<div class="topnav-menu">` + "\n")
buffer.Html(`<img src="/static/asset/quesma-logo-white-full.svg" alt="Quesma logo" class="quesma-logo" />` + "\n")
Expand All @@ -17,7 +17,7 @@ func generateSimpleTop(title string) []byte {
}

func generateTopNavigation(target string) []byte {
var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer
buffer.Html(`<div class="topnav">` + "\n")
buffer.Html(`<div class="topnav-menu">` + "\n")
buffer.Html(`<img src="/static/asset/quesma-logo-white-full.svg" alt="Quesma logo" class="quesma-logo" />` + "\n")
Expand Down Expand Up @@ -58,7 +58,7 @@ func generateTopNavigation(target string) []byte {
buffer.Html(`><a href="/telemetry">Telemetry</a></li>`)

buffer.Html("<li")
if target == "datasources" {
if target == "data-sources" {
buffer.Html(` class="active"`)
}
buffer.Html(`><a href="/data-sources">Data sources</a></li>`)
Expand All @@ -81,9 +81,9 @@ func generateTopNavigation(target string) []byte {
return buffer.Bytes()
}

func newBufferWithHead() buffer.HtmlBuffer {
func newBufferWithHead() builder.HtmlBuffer {
const bufferSize = 4 * 1024 // size of ui/head.html
var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer
buffer.Grow(bufferSize)
head, err := uiFs.ReadFile("asset/head.html")
buffer.Write(head)
Expand Down
4 changes: 2 additions & 2 deletions quesma/quesma/ui/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ui

import (
"fmt"
"mitmproxy/quesma/quesma/ui/internal/buffer"
"mitmproxy/quesma/quesma/ui/internal/builder"
"mitmproxy/quesma/stats"
"strings"
)
Expand All @@ -28,7 +28,7 @@ func (qmc *QuesmaManagementConsole) generateIngestStatistics() []byte {
}

func (qmc *QuesmaManagementConsole) generateStatistics() []byte {
var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer
const maxTopValues = 5

if !qmc.config.IngestStatistics {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package buffer
package builder

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package buffer
package builder

import (
"github.com/stretchr/testify/assert"
Expand Down
8 changes: 4 additions & 4 deletions quesma/quesma/ui/live_tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ui
import (
"fmt"
"mitmproxy/quesma/buildinfo"
"mitmproxy/quesma/quesma/ui/internal/buffer"
"mitmproxy/quesma/quesma/ui/internal/builder"
"mitmproxy/quesma/quesma/ui/internal/sqlfmt"
)

Expand Down Expand Up @@ -126,7 +126,7 @@ func (qmc *QuesmaManagementConsole) generateUnsupportedQuerySidePanel() []byte {
unknownTypeCount = value
}

var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer
linkToMainView := `<li><a href="/unsupported-requests"`
buffer.Html(`<ul id="unsupported-queries-stats" hx-swap-oob="true">`)
if totalErrorsCount > 0 {
Expand Down Expand Up @@ -162,7 +162,7 @@ func (qmc *QuesmaManagementConsole) generateQueriesStatsPanel() []byte {
}
qmc.mutex.Unlock()

var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer

buffer.Html(`<ul id="queries-stats" hx-swap-oob="true">`)
buffer.Html(`<li><a href="/requests-with-error/"`)
Expand All @@ -183,7 +183,7 @@ func (qmc *QuesmaManagementConsole) generateQueriesStatsPanel() []byte {
}

func generateQueries(debugKeyValueSlice []queryDebugInfoWithId, withLinks bool) []byte {
var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer

buffer.Html("\n" + `<div class="left" id="query-left">` + "\n")
buffer.Html(`<div class="title-bar">Query`)
Expand Down
4 changes: 2 additions & 2 deletions quesma/quesma/ui/live_tail_drilldown.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
"mitmproxy/quesma/quesma/ui/internal/buffer"
"mitmproxy/quesma/quesma/ui/internal/builder"
"strings"
)

Expand Down Expand Up @@ -117,7 +117,7 @@ func generateLogMessages(logMessages []string, links []string) ([]byte, *string)
return ""
}

var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer
buffer.Html("<table>\n")
buffer.Html("<thead>\n")
buffer.Html("<tr>\n")
Expand Down
4 changes: 2 additions & 2 deletions quesma/quesma/ui/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ui

import (
"mitmproxy/quesma/quesma/mux"
"mitmproxy/quesma/quesma/ui/internal/buffer"
"mitmproxy/quesma/quesma/ui/internal/builder"
"strings"
)

Expand Down Expand Up @@ -35,7 +35,7 @@ func dropFirstSegment(path string) string {
}

func (qmc *QuesmaManagementConsole) generateRouterStatistics() []byte {
var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer

matchedKeys, matched, unmatchedKeys, unmatched := mux.MatchStatistics().GroupByFirstSegment()

Expand Down
4 changes: 2 additions & 2 deletions quesma/quesma/ui/unsupported_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/rs/zerolog"
"mitmproxy/quesma/logger"
"mitmproxy/quesma/model"
"mitmproxy/quesma/quesma/ui/internal/buffer"
"mitmproxy/quesma/quesma/ui/internal/builder"
"mitmproxy/quesma/tracing"
"regexp"
"sort"
Expand Down Expand Up @@ -69,7 +69,7 @@ func (qmc *QuesmaManagementConsole) generateReportForUnsupportedRequests() []byt
return slice[i].count > slice[j].count
})

var buffer buffer.HtmlBuffer
var buffer builder.HtmlBuffer
buffer.Html("<br />")
buffer.Html(`<h3>Unsupported queries by type</h3>`)
buffer.Html(`<ul id="unsupported-queries-stats">`)
Expand Down

0 comments on commit 9931a0c

Please sign in to comment.