mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-22 22:21:27 +00:00
feat(stats): add bounded path and hash-width analytics (#159)
This commit is contained in:
1 parent
6107578c25
commit
8a3fa7e6bf
25 files changed
+1205
-4
No files matched your search
@@ -23,6 +23,7 @@ type viewRefresher interface {
|
||||
RefreshRadioPresets(context.Context) error
|
||||
RefreshObserverActivity(context.Context) error
|
||||
RefreshSignalStats(context.Context) error
|
||||
RefreshPathStats(context.Context) error
|
||||
}
|
||||
|
||||
// ViewRefreshTask returns a Task that refreshes all materialized views.
|
||||
@@ -45,6 +46,7 @@ func ViewRefreshTask(store viewRefresher, interval time.Duration) Task {
|
||||
{"radio presets", store.RefreshRadioPresets},
|
||||
{"observer activity", store.RefreshObserverActivity},
|
||||
{"signal stats", store.RefreshSignalStats},
|
||||
{"path stats", store.RefreshPathStats},
|
||||
} {
|
||||
if err := view.refresh(ctx); err != nil {
|
||||
errs = append(errs, fmt.Errorf("%s: %w", view.name, err))
|
||||
|
||||
@@ -123,6 +123,10 @@ func (s *refreshStub) RefreshSignalStats(ctx context.Context) error {
|
||||
return s.refresh(ctx, "signal stats")
|
||||
}
|
||||
|
||||
func (s *refreshStub) RefreshPathStats(ctx context.Context) error {
|
||||
return s.refresh(ctx, "path stats")
|
||||
}
|
||||
|
||||
func TestViewRefreshTask(t *testing.T) {
|
||||
first, second := errors.New("first failure"), errors.New("second failure")
|
||||
for _, tc := range []struct {
|
||||
@@ -132,13 +136,14 @@ func TestViewRefreshTask(t *testing.T) {
|
||||
{"success", nil},
|
||||
{"partial failure", map[string]error{"hourly stats": first, "top talkers": second}},
|
||||
{"signal failure", map[string]error{"signal stats": first}},
|
||||
{"path failure", map[string]error{"path stats": second}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
store := &refreshStub{errs: tc.errs}
|
||||
task := ViewRefreshTask(store, time.Minute)
|
||||
err := task.Run(context.Background())
|
||||
if len(store.calls) != 9 {
|
||||
t.Fatalf("refreshed %d views, want 9", len(store.calls))
|
||||
if len(store.calls) != 10 {
|
||||
t.Fatalf("refreshed %d views, want 10", len(store.calls))
|
||||
}
|
||||
if len(tc.errs) == 0 && err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in new issue
Block a user