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 {
Services []Service
Running int
Down int
OTelOnly int
TraceCount int
RPS []float64
Latency []float64
Errors []float64
Traces []float64
Labels []string
HealthSVG template.HTML
RPSSVG template.HTML
LatencySVG template.HTML
ErrorSVG template.HTML
TraceSVG template.HTML
SystemName string
Error string
TotalUp int
TotalDown int
Services []Service
Running int
Down int
OTelOnly int
TraceCount int
RPS []float64
Latency []float64
Errors []float64
TraceVolume []float64
TraceList []Trace
Labels []string
HealthSVG template.HTML
RPSSVG template.HTML
LatencySVG template.HTML
ErrorSVG template.HTML
TraceSVG template.HTML
SystemName string
Error string
TotalUp int
TotalDown int
}
// ── State ──
@@ -125,6 +126,7 @@ func fetchServices() []Service {
var raw []struct {
Names []string `json:"Names"`
State string `json:"State"`
Labels map[string]string `json:"Labels"`
NetworkSettings *struct {
Networks map[string]any `json:"Networks"`
} `json:"NetworkSettings"`
@@ -136,7 +138,10 @@ func fetchServices() []Service {
for _, c := range raw {
if c.NetworkSettings != nil {
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{
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,
HealthSVG: template.HTML(svgDonut(running, down, otel)),
RPSSVG: template.HTML(svgLine(rps, "#58a6ff")),
+3 -3
View File
@@ -120,7 +120,7 @@
<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">{{.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>
</div>
@@ -175,9 +175,9 @@
<div class="card" style="grid-column:span 6">
<div class="ch"><h2>Recent Traces</h2><span class="b">{{.TraceCount}}</span></div>
<div class="tl">
{{if .Traces}}
{{if .TraceList}}
<div id="tl">
{{range .Traces}}
{{range .TraceList}}
<div class="ti">
<div>
<div class="ts">{{.Service}}</div>