Sfoglia il codice sorgente

fix(traffic): render the 7d axis label without weekday

The 7d x-axis label used a hardcoded Spanish weekday slice, so an English UI showed "Lun 06h" and friends. It now uses the day of the month, which is language-neutral and matches the 30d range.

Closes #2062
Nacho 2 settimane fa
parent
commit
d9f41ba019

+ 4 - 3
server-go/internal/adapters/live.go

@@ -1093,8 +1093,6 @@ type histPoint struct {
 	cpu, ram, temp int
 }
 
-var weekdayES = []string{"Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb"}
-
 // metricsHistory consulta las métricas históricas (index.js:122-147).
 // metricsHistoryBuckets lee el histórico largo desde la escalera de retención
 // (metrics_buckets, 5 min → 1 año). Usado para el rango 30d, cuyo raw ya se
@@ -1164,8 +1162,11 @@ func (l *Live) metricsHistory(routerID, rang string) []histPoint {
 	case "7d":
 		// #2046: 6 h en vez de un día, 28 puntos. La etiqueta lleva el día y
 		// la hora porque con cuatro puntos por día solo el día no distingue.
+		// #2062: el día de la semana dependía del idioma (weekdayES lo
+		// pintaba en español también en una UI en inglés). El día del mes es
+		// neutro y coincide con el formato del rango 30d.
 		span, bucket = 7*86400e3, 6*3600e3
-		fmtLabel = func(d time.Time) string { return fmt.Sprintf("%s %02dh", weekdayES[d.Weekday()], d.Hour()) }
+		fmtLabel = func(d time.Time) string { return fmt.Sprintf("%02d %02dh", d.Day(), d.Hour()) }
 	case "30d":
 		span, bucket = 30*86400e3, 6*3600e3
 		fmtLabel = func(d time.Time) string { return fmt.Sprintf("%d", d.Day()) }

+ 32 - 0
server-go/internal/adapters/live_traffic_history_test.go

@@ -1,6 +1,7 @@
 package adapters
 
 import (
+	"strings"
 	"testing"
 	"time"
 )
@@ -116,3 +117,34 @@ func TestMetricsHistoryResolution(t *testing.T) {
 		t.Fatalf("7d tiene %d puntos; want ~28 (buckets de 6 h)", len(week))
 	}
 }
+
+// #2062: la etiqueta del eje 7d debe ser neutra en idioma. El día de la
+// semana dependía del idioma (weekdayES lo pintaba en español también en una
+// UI en inglés). El día del mes no tiene ese problema y coincide con el rango
+// 30d. Este test fija que ninguna etiqueta de 7d lleva un nombre de día de la
+// semana, en español ni en inglés.
+func TestMetricsHistorySevenDayLabelIsLocaleNeutral(t *testing.T) {
+	d := openLiveTestDB(t)
+	l := &Live{db: d}
+	now := time.Now()
+	for i := 0; i < 28; i++ {
+		if _, err := d.Exec(`INSERT OR REPLACE INTO metrics
+			(router_id, ts, cpu, ram, temp, latency_ms, rx_bps, tx_bps)
+			VALUES ('gw', ?, 10, 20, 40, 0, 1e6, 1e6)`,
+			now.Add(-time.Duration(i)*6*time.Hour).UnixMilli()); err != nil {
+			t.Fatalf("insert metric: %v", err)
+		}
+	}
+	got := l.metricsHistory("gw", "7d")
+	if len(got) == 0 {
+		t.Fatal("sin puntos en 7d")
+	}
+	weekdays := []string{"Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}
+	for _, p := range got {
+		for _, w := range weekdays {
+			if strings.Contains(p.t, w) {
+				t.Fatalf("etiqueta %q lleva un día de la semana (%s): debe ser neutra", p.t, w)
+			}
+		}
+	}
+}