fix(infra): filter hub services by compose project label, fix TraceList field name collision

This commit is contained in:
asepharyana
2026-07-22 18:46:16 +07:00
parent 0bc61d8b1c
commit ffe07ddef0
2 changed files with 30 additions and 24 deletions
+27 -21
View File
@@ -52,25 +52,26 @@ type Trace struct {
} }
type DashboardData struct { type DashboardData struct {
Services []Service Services []Service
Running int Running int
Down int Down int
OTelOnly int OTelOnly int
TraceCount int TraceCount int
RPS []float64 RPS []float64
Latency []float64 Latency []float64
Errors []float64 Errors []float64
Traces []float64 TraceVolume []float64
Labels []string TraceList []Trace
HealthSVG template.HTML Labels []string
RPSSVG template.HTML HealthSVG template.HTML
LatencySVG template.HTML RPSSVG template.HTML
ErrorSVG template.HTML LatencySVG template.HTML
TraceSVG template.HTML ErrorSVG template.HTML
SystemName string TraceSVG template.HTML
Error string SystemName string
TotalUp int Error string
TotalDown int TotalUp int
TotalDown int
} }
// ── State ── // ── State ──
@@ -125,6 +126,7 @@ func fetchServices() []Service {
var raw []struct { var raw []struct {
Names []string `json:"Names"` Names []string `json:"Names"`
State string `json:"State"` State string `json:"State"`
Labels map[string]string `json:"Labels"`
NetworkSettings *struct { NetworkSettings *struct {
Networks map[string]any `json:"Networks"` Networks map[string]any `json:"Networks"`
} `json:"NetworkSettings"` } `json:"NetworkSettings"`
@@ -136,7 +138,10 @@ func fetchServices() []Service {
for _, c := range raw { for _, c := range raw {
if c.NetworkSettings != nil { if c.NetworkSettings != nil {
if _, ok := c.NetworkSettings.Networks["app-shared-net"]; ok { if _, ok := c.NetworkSettings.Networks["app-shared-net"]; ok {
svcs = append(svcs, Service{Name: strings.TrimPrefix(c.Names[0], "/"), State: c.State}) // Only include containers from the hub compose project
if c.Labels["com.docker.compose.project"] == "compose" {
svcs = append(svcs, Service{Name: strings.TrimPrefix(c.Names[0], "/"), State: c.State})
}
} }
} }
} }
@@ -456,7 +461,8 @@ func dashboard(w http.ResponseWriter, _ *http.Request) {
data := DashboardData{ data := DashboardData{
Services: svcs, Running: running, Down: down, OTelOnly: otel, Services: svcs, Running: running, Down: down, OTelOnly: otel,
TraceCount: len(tr), RPS: rps, Latency: lat, Errors: ers, Traces: trc, Labels: labels, TraceCount: len(tr), RPS: rps, Latency: lat, Errors: ers,
TraceVolume: trc, TraceList: tr, Labels: labels,
SystemName: "asepharyana-hub", TotalUp: running, TotalDown: down + otel, SystemName: "asepharyana-hub", TotalUp: running, TotalDown: down + otel,
HealthSVG: template.HTML(svgDonut(running, down, otel)), HealthSVG: template.HTML(svgDonut(running, down, otel)),
RPSSVG: template.HTML(svgLine(rps, "#58a6ff")), RPSSVG: template.HTML(svgLine(rps, "#58a6ff")),
+3 -3
View File
@@ -120,7 +120,7 @@
<div class="sg2"> <div class="sg2">
<div class="sb"><div class="sv a">{{len .Services}}</div><div class="sl">Total</div></div> <div class="sb"><div class="sv a">{{len .Services}}</div><div class="sl">Total</div></div>
<div class="sb"><div class="sv a">{{.Running}}</div><div class="sl">Healthy</div></div> <div class="sb"><div class="sv a">{{.Running}}</div><div class="sl">Healthy</div></div>
<div class="sb"><div class="sv g">{{if .Traces}}{{printf "%.0f" (index .Traces (sub (len .Traces) 1))}}{{else}}0{{end}}</div><div class="sl">Traces</div></div> <div class="sb"><div class="sv g">{{if .TraceVolume}}{{printf "%.0f" (index .TraceVolume (sub (len .TraceVolume) 1))}}{{else}}0{{end}}</div><div class="sl">Traces</div></div>
<div class="sb"><div class="sv r">{{if .Errors}}{{printf "%.0f" (index .Errors (sub (len .Errors) 1))}}{{else}}0{{end}}</div><div class="sl">Errors</div></div> <div class="sb"><div class="sv r">{{if .Errors}}{{printf "%.0f" (index .Errors (sub (len .Errors) 1))}}{{else}}0{{end}}</div><div class="sl">Errors</div></div>
</div> </div>
</div> </div>
@@ -175,9 +175,9 @@
<div class="card" style="grid-column:span 6"> <div class="card" style="grid-column:span 6">
<div class="ch"><h2>Recent Traces</h2><span class="b">{{.TraceCount}}</span></div> <div class="ch"><h2>Recent Traces</h2><span class="b">{{.TraceCount}}</span></div>
<div class="tl"> <div class="tl">
{{if .Traces}} {{if .TraceList}}
<div id="tl"> <div id="tl">
{{range .Traces}} {{range .TraceList}}
<div class="ti"> <div class="ti">
<div> <div>
<div class="ts">{{.Service}}</div> <div class="ts">{{.Service}}</div>