Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/ingestor/stats_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package main

import (
"encoding/json"
"errors"
"os"
"path/filepath"
"runtime"
"syscall"
"testing"
"time"
)
Expand Down Expand Up @@ -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)
}

Expand Down
32 changes: 27 additions & 5 deletions cmd/server/config_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"os"
"path/filepath"
"runtime"
"testing"
)

Expand All @@ -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)
Expand All @@ -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)
}
}
4 changes: 3 additions & 1 deletion cmd/server/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
43 changes: 43 additions & 0 deletions cmd/server/store_obs_memory_test.go
Original file line number Diff line number Diff line change
@@ -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()
}
}
2 changes: 1 addition & 1 deletion tests/unit/test-issue-1956-release-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down