From ff2bae4f02a0e7ad3e7e3eb15d6e719cb99b02a3 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Thu, 12 Dec 2024 15:03:44 -0600 Subject: [PATCH] Enhance HTML with new hotqueries and query plan general info Signed-off-by: Florent Poinsard --- go/summarize/markdown.go | 5 ++-- go/summarize/summarize-planalyze.go | 7 +++-- go/summarize/summarize.go | 14 ++++----- go/summarize/summary.go | 10 +++---- go/web/templates/summarize.html | 44 +++++++++++++++++++++++++---- 5 files changed, 57 insertions(+), 23 deletions(-) diff --git a/go/summarize/markdown.go b/go/summarize/markdown.go index 6b44f5d..ca8e557 100644 --- a/go/summarize/markdown.go +++ b/go/summarize/markdown.go @@ -228,8 +228,7 @@ func renderTransactions(md *markdown.MarkDown, transactions []TransactionSummary } func renderPlansSection(md *markdown.MarkDown, analysis PlanAnalysis) error { - sum := analysis.PassThrough + analysis.SimpleRouted + analysis.Complex + analysis.Unplannable - if sum == 0 { + if analysis.Total == 0 { return nil } @@ -241,7 +240,7 @@ func renderPlansSection(md *markdown.MarkDown, analysis PlanAnalysis) error { {planalyze.SimpleRouted.String(), strconv.Itoa(analysis.SimpleRouted)}, {planalyze.Complex.String(), strconv.Itoa(analysis.Complex)}, {planalyze.Unplannable.String(), strconv.Itoa(analysis.Unplannable)}, - {"Total", strconv.Itoa(sum)}, + {"Total", strconv.Itoa(analysis.Total)}, } md.PrintTable(headers, rows) md.NewLine() diff --git a/go/summarize/summarize-planalyze.go b/go/summarize/summarize-planalyze.go index 0e8f26f..ebf79a2 100644 --- a/go/summarize/summarize-planalyze.go +++ b/go/summarize/summarize-planalyze.go @@ -21,17 +21,18 @@ import ( ) func summarizePlanAnalyze(s *Summary, data planalyze.Output) (err error) { - s.planAnalysis = PlanAnalysis{ + s.PlanAnalysis = PlanAnalysis{ PassThrough: len(data.PassThrough), SimpleRouted: len(data.SimpleRouted), Complex: len(data.Complex), Unplannable: len(data.Unplannable), } + s.PlanAnalysis.Total = s.PlanAnalysis.PassThrough + s.PlanAnalysis.SimpleRouted + s.PlanAnalysis.Complex + s.PlanAnalysis.Unplannable s.addPlanResult(data.SimpleRouted) s.addPlanResult(data.Complex) - s.planAnalysis.simpleRouted = append(s.planAnalysis.simpleRouted, data.SimpleRouted...) - s.planAnalysis.complex = append(s.planAnalysis.complex, data.Complex...) + s.PlanAnalysis.simpleRouted = append(s.PlanAnalysis.simpleRouted, data.SimpleRouted...) + s.PlanAnalysis.complex = append(s.PlanAnalysis.complex, data.Complex...) return nil } diff --git a/go/summarize/summarize.go b/go/summarize/summarize.go index 1f7cdcd..1ef90a8 100644 --- a/go/summarize/summarize.go +++ b/go/summarize/summarize.go @@ -179,26 +179,26 @@ func compileSummary(s *Summary) error { func compileHotQueries(s *Summary) error { for _, result := range s.queries { - checkQueryForHotness(&s.hotQueries, result, s.hotQueryFn) + checkQueryForHotness(&s.HotQueries, result, s.hotQueryFn) } var hasTime bool - sort.Slice(s.hotQueries, func(i, j int) bool { - if s.hotQueries[i].QueryAnalysisResult.QueryTime != 0 { + sort.Slice(s.HotQueries, func(i, j int) bool { + if s.HotQueries[i].QueryAnalysisResult.QueryTime != 0 { hasTime = true } - fnI := s.hotQueryFn(s.hotQueries[i].QueryAnalysisResult) - fnJ := s.hotQueryFn(s.hotQueries[j].QueryAnalysisResult) + fnI := s.hotQueryFn(s.HotQueries[i].QueryAnalysisResult) + fnJ := s.hotQueryFn(s.HotQueries[j].QueryAnalysisResult) // if the two metrics are equal, sort them by alphabetical order if fnI == fnJ { - return s.hotQueries[i].QueryAnalysisResult.QueryStructure > s.hotQueries[j].QueryAnalysisResult.QueryStructure + return s.HotQueries[i].QueryAnalysisResult.QueryStructure > s.HotQueries[j].QueryAnalysisResult.QueryStructure } return fnI > fnJ }) // If we did not record any time, there is no hotness to record, so removing the field so it does not get rendered. if !hasTime { - s.hotQueries = nil + s.HotQueries = nil } return nil } diff --git a/go/summarize/summary.go b/go/summarize/summary.go index e718a0f..a4cd613 100644 --- a/go/summarize/summary.go +++ b/go/summarize/summary.go @@ -35,9 +35,8 @@ type ( Tables []*TableSummary Failures []FailuresSummary Transactions []TransactionSummary - HotQueries []keys.QueryAnalysisResult - planAnalysis PlanAnalysis - hotQueries []HotQueryResult + PlanAnalysis PlanAnalysis + HotQueries []HotQueryResult hotQueryFn getMetric AnalyzedFiles []string queryGraph queryGraph @@ -88,6 +87,7 @@ type ( SimpleRouted int Complex int Unplannable int + Total int simpleRouted []planalyze.AnalyzedQuery complex []planalyze.AnalyzedQuery @@ -137,11 +137,11 @@ func (s *Summary) PrintMarkdown(out io.Writer, now time.Time) error { s.AnalyzedFiles[i] = "`" + file + "`" } md.Printf(msg, now.Format(time.DateTime), filePlural, strings.Join(s.AnalyzedFiles, ", ")) - err := renderPlansSection(md, s.planAnalysis) + err := renderPlansSection(md, s.PlanAnalysis) if err != nil { return err } - renderHotQueries(md, s.hotQueries) + renderHotQueries(md, s.HotQueries) renderTableUsage(md, s.Tables, s.HasRowCount) renderTablesJoined(md, s) renderTransactions(md, s.Transactions) diff --git a/go/web/templates/summarize.html b/go/web/templates/summarize.html index b31d7e0..8d86e97 100644 --- a/go/web/templates/summarize.html +++ b/go/web/templates/summarize.html @@ -13,6 +13,40 @@

Query Analysis Report

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Plan ComplexityCount
Pass-through{{.PlanAnalysis.PassThrough}}
Simple routed{{.PlanAnalysis.SimpleRouted}}
Complex routed{{.PlanAnalysis.Complex}}
Unplannable{{.PlanAnalysis.Unplannable}}
Total{{.PlanAnalysis.Total}}
+
+
@@ -29,10 +63,10 @@

Query Analysis Report

{{range $index, $query := .HotQueries}} - - - - + + + + {{end}} @@ -52,7 +86,7 @@

Query Analysis Report

{{range $index, $query := .HotQueries}} - + {{end}}
{{$index | add 1}} {{$query.UsageCount}}{{$query.QueryTime}}{{divide .QueryTime .UsageCount}}{{$query.RowsExamined}}{{$query.QueryAnalysisResult.UsageCount}}{{$query.QueryAnalysisResult.QueryTime}}{{divide $query.QueryAnalysisResult.QueryTime $query.QueryAnalysisResult.UsageCount}}{{$query.QueryAnalysisResult.RowsExamined}}
{{$index | add 1}}{{.QueryStructure}}{{$query.QueryAnalysisResult.QueryStructure}}