mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-20 13:30:46 +02:00
* telemetry: sync the server module to go 1.26 The root module moved to go 1.26 but the telemetry server module, which replaces seaweedfs with the repo root, stayed on 1.25.8, so go refuses to build or test it until the directive catches up. * telemetry: confirm a cluster after a week of reports, not two days Two days of history still lets recurring CI and demo clusters into the confirmed fleet: anything torn down and rebuilt across a UTC midnight counts. Requiring seven distinct UTC days keeps the fleet charts and the version/OS distributions to clusters that actually stay up; real clusters qualify after their first week, and the fallback to all active clusters while none is confirmed is unchanged.
78 lines
2.3 KiB
Go
78 lines
2.3 KiB
Go
package storage
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/seaweedfs/seaweedfs/telemetry/proto"
|
|
)
|
|
|
|
func report(id, version string) *proto.TelemetryData {
|
|
return &proto.TelemetryData{
|
|
TopologyId: id,
|
|
Version: version,
|
|
Os: "linux/amd64",
|
|
VolumeServerCount: 1,
|
|
TotalDiskBytes: 100,
|
|
TotalVolumeCount: 1,
|
|
}
|
|
}
|
|
|
|
func statsOf(t *testing.T, s *PrometheusStorage) map[string]interface{} {
|
|
t.Helper()
|
|
stats, err := s.GetStats()
|
|
if err != nil {
|
|
t.Fatalf("stats: %v", err)
|
|
}
|
|
return stats
|
|
}
|
|
|
|
func TestConfirmedClusters(t *testing.T) {
|
|
s := newPrometheusStorage(prometheus.NewRegistry())
|
|
|
|
// A single-day cluster is active but not confirmed; with no confirmed
|
|
// clusters yet, distributions fall back to all active clusters.
|
|
if err := s.StoreTelemetry(report("aaaaaaaa-0000-0000-0000-000000000001", "4.40")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
stats := statsOf(t, s)
|
|
if stats["active_instances"] != 1 || stats["confirmed_instances"] != 0 {
|
|
t.Fatalf("day one: active=%v confirmed=%v, want 1/0", stats["active_instances"], stats["confirmed_instances"])
|
|
}
|
|
if v := stats["versions"].(map[string]int); v["4.40"] != 1 {
|
|
t.Fatalf("fallback distribution missing active cluster: %v", v)
|
|
}
|
|
|
|
// Give cluster A samples from the six previous days: now seen on 7
|
|
// distinct days.
|
|
s.mu.Lock()
|
|
id := "aaaaaaaa-0000-0000-0000-000000000001"
|
|
var older []HistorySample
|
|
for offset := -6; offset < 0; offset++ {
|
|
older = append(older, HistorySample{
|
|
Ts: time.Now().AddDate(0, 0, offset).Unix(),
|
|
TotalDiskBytes: 50,
|
|
})
|
|
}
|
|
s.histories[id] = append(older, s.histories[id]...)
|
|
s.mu.Unlock()
|
|
|
|
// A one-shot cluster B arrives (like an injected report): it counts as
|
|
// active, but the distributions now only reflect confirmed clusters.
|
|
if err := s.StoreTelemetry(report("bbbbbbbb-0000-0000-0000-000000000002", "9.99")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
stats = statsOf(t, s)
|
|
if stats["active_instances"] != 2 || stats["confirmed_instances"] != 1 {
|
|
t.Fatalf("day seven: active=%v confirmed=%v, want 2/1", stats["active_instances"], stats["confirmed_instances"])
|
|
}
|
|
v := stats["versions"].(map[string]int)
|
|
if v["4.40"] != 1 {
|
|
t.Errorf("confirmed cluster missing from distribution: %v", v)
|
|
}
|
|
if _, ok := v["9.99"]; ok {
|
|
t.Errorf("one-shot cluster polluted the distribution: %v", v)
|
|
}
|
|
}
|