c/b/b/webug: add tag count table
Change-Id: I9662f00629335a656c401f66c798575f7db57842
Reviewed-on: https://review.monogon.dev/c/monogon/+/1583
Tested-by: Jenkins CI
Reviewed-by: Serge Bazanski <serge@monogon.tech>
diff --git a/cloud/bmaas/bmdb/webug/templates/machines.html b/cloud/bmaas/bmdb/webug/templates/machines.html
index d8658a1..4650512 100644
--- a/cloud/bmaas/bmdb/webug/templates/machines.html
+++ b/cloud/bmaas/bmdb/webug/templates/machines.html
@@ -31,6 +31,18 @@
</tr>
{{ end -}}
</table>
+<table>
+ <tr>
+ {{ range $name, $count := .TagCount -}}
+ <th>{{ $name }}</th>
+ {{ end -}}
+ </tr>
+ <tr>
+ {{ range $name, $count := .TagCount -}}
+ <td>{{ $count }}</td>
+ {{ end -}}
+ </tr>
+</table>
<p class="small faint mono">
{{ .NMachines }} rows, rendered in {{ .RenderTime }}. Query: {{ .Query }}
</p>
\ No newline at end of file
diff --git a/cloud/bmaas/bmdb/webug/views.go b/cloud/bmaas/bmdb/webug/views.go
index 7e6d91f..f47ece7 100644
--- a/cloud/bmaas/bmdb/webug/views.go
+++ b/cloud/bmaas/bmdb/webug/views.go
@@ -45,12 +45,20 @@
}
duration := time.Since(start)
+ tagCount := make(map[string]int)
+ for _, d := range res.Data {
+ for _, t := range d.Tags {
+ tagCount[t.Type.Name()]++
+ }
+ }
+
type params struct {
Base baseParams
Query string
Machines []*reflection.Machine
NMachines int
RenderTime time.Duration
+ TagCount map[string]int
}
err = templates.ExecuteTemplate(w, "machines.html", ¶ms{
Base: s.makeBase(),
@@ -58,6 +66,7 @@
Machines: res.Data,
NMachines: len(res.Data),
RenderTime: duration,
+ TagCount: tagCount,
})
if err != nil {
klog.Errorf("Template rendering failed: %v", err)