From 2403d28f41cf0d61e4caa6d880d53def1d7b90ad Mon Sep 17 00:00:00 2001 From: n30nex Date: Fri, 9 Oct 2026 12:33:39 -0400 Subject: [PATCH 1/2] test: respect native permissions and fixture release context --- cmd/ingestor/stats_file_test.go | 7 ++++ cmd/server/config_mode_test.go | 32 ++++++++++++++++--- tests/unit/test-issue-1956-release-routing.js | 2 +- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/cmd/ingestor/stats_file_test.go b/cmd/ingestor/stats_file_test.go index e96d56bd1..a41924828 100644 --- a/cmd/ingestor/stats_file_test.go +++ b/cmd/ingestor/stats_file_test.go @@ -2,8 +2,11 @@ package main import ( "encoding/json" + "errors" "os" "path/filepath" + "runtime" + "syscall" "testing" "time" ) @@ -129,6 +132,10 @@ func TestWriteStatsAtomic_SymlinkAtDestIsReplaced(t *testing.T) { // Pre-plant a symlink at the destination path. path := filepath.Join(dir, "stats.json") if err := os.Symlink(target, path); err != nil { + // ERROR_PRIVILEGE_NOT_HELD: Windows requires symlink privileges or Developer Mode. + if runtime.GOOS == "windows" && errors.Is(err, syscall.Errno(1314)) { + t.Skipf("symlink privilege unavailable: %v", err) + } t.Fatalf("symlink: %v", err) } diff --git a/cmd/server/config_mode_test.go b/cmd/server/config_mode_test.go index 601ef7656..d3b7e6bc1 100644 --- a/cmd/server/config_mode_test.go +++ b/cmd/server/config_mode_test.go @@ -3,6 +3,7 @@ package main import ( "os" "path/filepath" + "runtime" "testing" ) @@ -15,6 +16,16 @@ func TestSaveGeoFilterPreservesFileMode(t *testing.T) { if err := os.WriteFile(path, []byte(`{"apiKey":"secret-key-that-is-long-enough"}`+"\n"), 0600); err != nil { t.Fatal(err) } + before, err := os.Stat(path) + if err != nil { + t.Fatal(err) + } + want := before.Mode().Perm() + // Windows does not implement POSIX permissions. Compare its reported + // mode before and after saving; this is not an assertion about ACLs. + if runtime.GOOS != "windows" && want != 0600 { + t.Fatalf("config.json mode before save = %o, want 0600", want) + } gf := &GeoFilterConfig{Polygon: [][2]float64{{0, 0}, {0, 1}, {1, 1}, {1, 0}}} if err := SaveGeoFilter(dir, gf); err != nil { t.Fatalf("SaveGeoFilter: %v", err) @@ -23,18 +34,29 @@ func TestSaveGeoFilterPreservesFileMode(t *testing.T) { if err != nil { t.Fatal(err) } - if got := fi.Mode().Perm(); got != 0600 { - t.Fatalf("config.json mode after save = %o, want 0600", got) + if got := fi.Mode().Perm(); got != want { + t.Fatalf("config.json mode after save = %o, want %o", got, want) } // Default stays 0644 for a file that was 0644. if err := os.Chmod(path, 0644); err != nil { t.Fatal(err) } + before, err = os.Stat(path) + if err != nil { + t.Fatal(err) + } + want = before.Mode().Perm() + if runtime.GOOS != "windows" && want != 0644 { + t.Fatalf("config.json mode before save = %o, want 0644", want) + } if err := SaveGeoFilter(dir, nil); err != nil { t.Fatalf("SaveGeoFilter(nil): %v", err) } - fi, _ = os.Stat(path) - if got := fi.Mode().Perm(); got != 0644 { - t.Fatalf("config.json mode after save = %o, want 0644", got) + fi, err = os.Stat(path) + if err != nil { + t.Fatal(err) + } + if got := fi.Mode().Perm(); got != want { + t.Fatalf("config.json mode after save = %o, want %o", got, want) } } diff --git a/tests/unit/test-issue-1956-release-routing.js b/tests/unit/test-issue-1956-release-routing.js index 89ee1738c..12c2aebc6 100644 --- a/tests/unit/test-issue-1956-release-routing.js +++ b/tests/unit/test-issue-1956-release-routing.js @@ -130,7 +130,7 @@ function runSteps(source, context, edge, mutateFails = false) { const result = spawnSync(bash, ['--noprofile', '--norc', '-e', '-o', 'pipefail'], { input: stubs + '\n' + expand(script, context), cwd: dir, encoding: 'utf8', timeout: 15000, env: { - ...process.env, GITHUB_REF: context.github.ref, GITHUB_SHA: context.github.sha, + ...process.env, GITHUB_REF: context.github.ref, GITHUB_REF_NAME: context.github.ref_name, GITHUB_SHA: context.github.sha, CC: '', GITHUB_OUTPUT: bashPath(output), COMMAND_LOG: bashPath(log), TMPDIR: bashPath(dir), EDGE_CONFIG: edge === null ? 'missing' : JSON.stringify({ config: { Labels: { 'org.opencontainers.image.revision': edge } } }), // :edge is a two-platform index plus the two buildx attestation From 1b66d3885cb10e429074ed7a14b7a96a22bcab81 Mon Sep 17 00:00:00 2001 From: n30nex Date: Fri, 9 Oct 2026 12:33:39 -0400 Subject: [PATCH 2/2] perf(server): reduce retained observation allocation size (#2148) --- cmd/server/store.go | 4 ++- cmd/server/store_obs_memory_test.go | 43 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 cmd/server/store_obs_memory_test.go diff --git a/cmd/server/store.go b/cmd/server/store.go index e59194188..edbd55245 100644 --- a/cmd/server/store.go +++ b/cmd/server/store.go @@ -92,8 +92,10 @@ type StoreObs struct { // fallback chain on every read; for /api/observers/{id}/analytics // that fires 60k+ times per request under RLock. ParsedTime returns // the parsed value once, caching for the lifetime of the StoreObs. - tsParseOnce sync.Once + // Keep time.Time before sync.Once and the bool to avoid padding that + // pushes each observation into a larger allocation class on 64-bit Go. tsParsed time.Time + tsParseOnce sync.Once tsParsedOK bool } diff --git a/cmd/server/store_obs_memory_test.go b/cmd/server/store_obs_memory_test.go new file mode 100644 index 000000000..effa63523 --- /dev/null +++ b/cmd/server/store_obs_memory_test.go @@ -0,0 +1,43 @@ +package main + +import ( + "runtime" + "testing" + "unsafe" +) + +// Observations outnumber transmissions at high-fanout receivers. Keep the +// timestamp cache packed so each retained observation fits the 192-byte +// allocation class on the supported 64-bit deployment targets. +func TestStoreObsMemoryFootprint(t *testing.T) { + if unsafe.Sizeof(uintptr(0)) != 8 { + t.Skip("allocation budget applies to 64-bit targets") + } + if size := unsafe.Sizeof(StoreObs{}); size > 192 { + t.Fatalf("StoreObs is %d bytes; want <=192 to avoid the 208-byte allocation class", size) + } +} + +// Measure live objects after GC; a heap profile taken after this benchmark +// returns would otherwise lose the observation set being compared. +func BenchmarkStoreObsRetainedMemory(b *testing.B) { + const count = 100000 + for i := 0; i < b.N; i++ { + b.StopTimer() + observations := make([]*StoreObs, count) + runtime.GC() + var before, after runtime.MemStats + runtime.ReadMemStats(&before) + b.StartTimer() + for j := range observations { + observations[j] = &StoreObs{ID: j + 1, TransmissionID: j/16 + 1, Timestamp: "2026-01-01T00:00:00Z"} + observations[j].ParsedTime() + } + b.StopTimer() + runtime.GC() + runtime.ReadMemStats(&after) + b.ReportMetric(float64(int64(after.HeapAlloc)-int64(before.HeapAlloc))/count, "retained-B/obs") + runtime.KeepAlive(observations) + b.StartTimer() + } +}