From 06667eedb7a4fcdcb5f8dbf0e59934d377838c07 Mon Sep 17 00:00:00 2001 From: Rohit Nayak Date: Tue, 10 Dec 2024 23:55:42 +0100 Subject: [PATCH] Self-review Signed-off-by: Rohit Nayak --- Makefile | 4 - go/cmd/root.go | 2 +- go/web/templates/summarize.html | 191 ++++++++++++++++++++++++++++--- go/web/templates/summarize2.html | 182 ----------------------------- go/web/web.go | 6 +- 5 files changed, 177 insertions(+), 208 deletions(-) delete mode 100644 go/web/templates/summarize2.html diff --git a/Makefile b/Makefile index ced0d2f..47828e0 100644 --- a/Makefile +++ b/Makefile @@ -26,10 +26,6 @@ check_version: default: check_version build -vt: clean - @echo "Building vt..." - @go build -o vt ./go/vt - build: @echo "Building vt..." @go build -o vt ./go/vt diff --git a/go/cmd/root.go b/go/cmd/root.go index 2909e1d..9cd19d6 100644 --- a/go/cmd/root.go +++ b/go/cmd/root.go @@ -37,7 +37,6 @@ func Execute() { Use: "vt", Short: "Utils tools for testing, running and benchmarking Vitess.", RunE: func(_ *cobra.Command, _ []string) error { - // Do something with port here if port > 0 { if webserverStarted { return nil @@ -64,6 +63,7 @@ func Execute() { } else { ch <- 1 } + // FIXME: add sync b/w webserver and root command, for now just add a wait to make sure webserver is running time.Sleep(2 * time.Second) err := root.Execute() diff --git a/go/web/templates/summarize.html b/go/web/templates/summarize.html index 4dc894b..b31d7e0 100644 --- a/go/web/templates/summarize.html +++ b/go/web/templates/summarize.html @@ -1,27 +1,182 @@ {{define "content"}} -

Query Analysis Report

-

-

Tables

+

Query Analysis Report

- - - - + + - - - {{range .Tables}} - - - - + + - {{end}} - +
Table NameReadsWritesNumber of Rows Date of AnalysisAnalyzed Files
{{.Table}}{{.ReadQueryCount}}{{.WriteQueryCount}}{{.RowCount}}{{.DateOfAnalysis}}{{range .AnalyzedFiles}}{{.}}{{end}}
-{{end}} -` \ No newline at end of file + +
+ + + + + + + + + + + + {{range $index, $query := .HotQueries}} + + + + + + + + {{end}} + +
Query IDUsage CountTotal Query Time (ms)Avg Query Time (ms)Total Rows Examined
{{$index | add 1}} {{$query.UsageCount}}{{$query.QueryTime}}{{divide .QueryTime .UsageCount}}{{$query.RowsExamined}}
+
+ + +
+ + + + + + + + + {{range $index, $query := .HotQueries}} + + + + + {{end}} + +
#Query Structure
{{$index | add 1}}{{.QueryStructure}}
+
+ + +
+ + + + + + + + + + + {{range .Tables}} + + + + + + + {{end}} + +
Table NameReadsWritesNumber of Rows
{{.Table}}{{.ReadQueryCount}}{{.WriteQueryCount}}{{.RowCount}}
+
+ + +
+ {{range .Tables}} +
+

Table: {{.Table}} ({{.ReadQueryCount}} reads and {{.WriteQueryCount}} writes)

+ + + + + + + + + + {{range .GetColumnsSlice}} + + + + + + {{end}} + +
ColumnPositionUsed %
{{.ColInfo.Name}}{{.ColInfo.Pos}}{{.Usage.Percentage}}%
+
+ {{end}} +
+ + +
+ + + + + + + + + + + {{range .Joins}} + + + + + + + {{end}} + +
Table 1Table 2OccurrencesPredicates
{{.Tbl1}}
{{.Tbl2}}
{{.Occurrences}} + {{range .Predicates}} +
{{.}}
+ {{end}} +
+
+ + +
+ + + + + + + + + {{range .Failures}} + + + + + {{end}} + +
ErrorCount
{{.Error}}{{.Count}}
+
+ + +
+ {{range $index, $tx := .Transactions}} +

Pattern {{$index | add 1}} (Observed {{$tx.Count}} times)

+

Tables Involved: TBD

+

Query Patterns

+ {{range $index2, $query := .Queries}} +

{{$index | add 1}} . {{$query.Type}} on {{$query.Table}}

+

Predicates: {{range $query.Predicates}}{{.}} AND {{end}}

+ {{end}} +

Shared Predicate Values

+ {{range $index3, $join := $tx.Joins}} +

Value {{$index | add 1}} applied to:

+
    + {{range .}} +
  • {{$join}}
  • + {{end}} +
+ {{end}} + {{end}} +
+{{end}} \ No newline at end of file diff --git a/go/web/templates/summarize2.html b/go/web/templates/summarize2.html deleted file mode 100644 index b31d7e0..0000000 --- a/go/web/templates/summarize2.html +++ /dev/null @@ -1,182 +0,0 @@ -{{define "content"}} -

Query Analysis Report

- - - - - - - - - - - -
Date of AnalysisAnalyzed Files
{{.DateOfAnalysis}}{{range .AnalyzedFiles}}{{.}}{{end}}
- - -
- - - - - - - - - - - - {{range $index, $query := .HotQueries}} - - - - - - - - {{end}} - -
Query IDUsage CountTotal Query Time (ms)Avg Query Time (ms)Total Rows Examined
{{$index | add 1}} {{$query.UsageCount}}{{$query.QueryTime}}{{divide .QueryTime .UsageCount}}{{$query.RowsExamined}}
-
- - -
- - - - - - - - - {{range $index, $query := .HotQueries}} - - - - - {{end}} - -
#Query Structure
{{$index | add 1}}{{.QueryStructure}}
-
- - -
- - - - - - - - - - - {{range .Tables}} - - - - - - - {{end}} - -
Table NameReadsWritesNumber of Rows
{{.Table}}{{.ReadQueryCount}}{{.WriteQueryCount}}{{.RowCount}}
-
- - -
- {{range .Tables}} -
-

Table: {{.Table}} ({{.ReadQueryCount}} reads and {{.WriteQueryCount}} writes)

- - - - - - - - - - {{range .GetColumnsSlice}} - - - - - - {{end}} - -
ColumnPositionUsed %
{{.ColInfo.Name}}{{.ColInfo.Pos}}{{.Usage.Percentage}}%
-
- {{end}} -
- - -
- - - - - - - - - - - {{range .Joins}} - - - - - - - {{end}} - -
Table 1Table 2OccurrencesPredicates
{{.Tbl1}}
{{.Tbl2}}
{{.Occurrences}} - {{range .Predicates}} -
{{.}}
- {{end}} -
-
- - -
- - - - - - - - - {{range .Failures}} - - - - - {{end}} - -
ErrorCount
{{.Error}}{{.Count}}
-
- - -
- {{range $index, $tx := .Transactions}} -

Pattern {{$index | add 1}} (Observed {{$tx.Count}} times)

-

Tables Involved: TBD

-

Query Patterns

- {{range $index2, $query := .Queries}} -

{{$index | add 1}} . {{$query.Type}} on {{$query.Table}}

-

Predicates: {{range $query.Predicates}}{{.}} AND {{end}}

- {{end}} -

Shared Predicate Values

- {{range $index3, $join := $tx.Joins}} -

Value {{$index | add 1}} applied to:

-
    - {{range .}} -
  • {{$join}}
  • - {{end}} -
- {{end}} - {{end}} -
-{{end}} \ No newline at end of file diff --git a/go/web/web.go b/go/web/web.go index 1fbdf87..00e8746 100644 --- a/go/web/web.go +++ b/go/web/web.go @@ -26,7 +26,7 @@ func RenderFileToGin(fileName string, data any, c *gin.Context) { } func RenderFile(fileName string, data any) (*bytes.Buffer, error) { - tmpl := template.Must(template.New("summarize2.html").Funcs(getFuncMap()).ParseFiles( + tmpl := template.Must(template.New("summarize.html").Funcs(getFuncMap()).ParseFiles( "go/web/templates/layout.html", "go/web/templates/footer.html", "go/web/templates/header.html", @@ -134,13 +134,13 @@ func Run(port int64) { } } - RenderFileToGin("summarize2.html", &summarizeOutput, c) + RenderFileToGin("summarize.html", &summarizeOutput, c) }) if os.WriteFile("/dev/stderr", []byte(fmt.Sprintf("Starting web server on http://localhost:%d\n", port)), 0o600) != nil { panic("Failed to write to /dev/stderr") } - if err := r.Run(":8080"); err != nil { + if err := r.Run(fmt.Sprintf(":%d", port)); err != nil { log.Fatalf("Failed to start server: %v", err) } }