diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-16 10:22:48 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-16 10:22:48 +0300 |
| commit | 4371aa94b0793c70a3e146fad6398f0dcb540048 (patch) | |
| tree | c7a4e1fd6726927d3344dace8d38cda7efef706d /internal/daemon/metrics_test.go | |
| parent | ee8221e6c88640dba31c69c59c19e65a8dc54a3e (diff) | |
Release 0.5.1: auto-unexclude, merge excluded_host into auth DB0.5.1
- /metrics: auto-remove exclusion when records mtime > excluded_at so
hosts that resume uploading unexclude themselves on next scrape
- Consolidate excluded_host table into the auth DB (goprecords-auth.db)
instead of a separate file — removes -db daemon flag and GOPRECORDS_DB env
- README: add host exclusion section with kubectl exec examples
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/daemon/metrics_test.go')
| -rw-r--r-- | internal/daemon/metrics_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/internal/daemon/metrics_test.go b/internal/daemon/metrics_test.go index 536f72c..3c390f8 100644 --- a/internal/daemon/metrics_test.go +++ b/internal/daemon/metrics_test.go @@ -109,6 +109,57 @@ func TestMetricsMethodNotAllowed(t *testing.T) { } } +func TestMetricsAutoUnexclude(t *testing.T) { + statsDir := t.TempDir() + dbPath := filepath.Join(t.TempDir(), "test.db") + recordsFile := filepath.Join(statsDir, "comeback.records") + if err := os.WriteFile(recordsFile, []byte("1:1:Linux 5.0\n"), 0o644); err != nil { + t.Fatal(err) + } + ctx := context.Background() + db, err := storage.Open(ctx, dbPath) + if err != nil { + t.Fatal(err) + } + if err := storage.CreateSchema(ctx, db); err != nil { + t.Fatal(err) + } + fi, err := os.Stat(recordsFile) + if err != nil { + t.Fatal(err) + } + pastTime := fi.ModTime().Unix() - 3600 + _, err = db.ExecContext(ctx, + "INSERT OR REPLACE INTO excluded_host (host, reason, excluded_at) VALUES (?, ?, ?)", + "comeback", "old exclusion", pastTime) + if err != nil { + t.Fatal(err) + } + db.Close() + body, err := buildMetrics(ctx, statsDir, dbPath) + if err != nil { + t.Fatal(err) + } + s := string(body) + if !strings.Contains(s, `excluded="false"`) { + t.Fatalf("expected auto-unexclude (excluded=false) but got: %q", s) + } + db2, err := storage.Open(ctx, dbPath) + if err != nil { + t.Fatal(err) + } + defer db2.Close() + hosts, err := storage.LoadExcludedHosts(ctx, db2) + if err != nil { + t.Fatal(err) + } + for _, h := range hosts { + if h.Host == "comeback" { + t.Fatalf("expected comeback to be removed from exclusion list after auto-unexclude") + } + } +} + func TestBuildMetricsNoDBPath(t *testing.T) { statsDir := t.TempDir() if err := os.WriteFile(filepath.Join(statsDir, "h1.records"), []byte("1:1:Linux 5.0\n"), 0o644); err != nil { |
