Execute PLAN_AGGREGATOR.md
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
pb "git.ipng.ch/ipng/nginx-logtail/proto/logtailpb"
|
||||
st "git.ipng.ch/ipng/nginx-logtail/internal/store"
|
||||
)
|
||||
|
||||
func makeStore() *Store {
|
||||
@@ -30,7 +31,7 @@ func TestIngestAndRotate(t *testing.T) {
|
||||
if s.fineFilled != 1 {
|
||||
t.Fatalf("fineFilled = %d, want 1", s.fineFilled)
|
||||
}
|
||||
snap := s.fineRing[(s.fineHead-1+fineRingSize)%fineRingSize]
|
||||
snap := s.fineRing[(s.fineHead-1+st.FineRingSize)%st.FineRingSize]
|
||||
if len(snap.Entries) != 2 {
|
||||
t.Fatalf("snapshot has %d entries, want 2", len(snap.Entries))
|
||||
}
|
||||
@@ -41,13 +42,12 @@ func TestIngestAndRotate(t *testing.T) {
|
||||
|
||||
func TestLiveMapCap(t *testing.T) {
|
||||
s := makeStore()
|
||||
// Ingest liveMapCap+100 distinct keys; only liveMapCap should be tracked
|
||||
for i := 0; i < liveMapCap+100; i++ {
|
||||
s.ingest(LogRecord{
|
||||
Website: fmt.Sprintf("site%d.com", i),
|
||||
Website: fmt.Sprintf("site%d.com", i),
|
||||
ClientPrefix: "1.2.3.0/24",
|
||||
URI: "/",
|
||||
Status: "200",
|
||||
URI: "/",
|
||||
Status: "200",
|
||||
})
|
||||
}
|
||||
if s.liveLen != liveMapCap {
|
||||
@@ -86,7 +86,6 @@ func TestQueryTopNWithFilter(t *testing.T) {
|
||||
if len(entries) != 2 {
|
||||
t.Fatalf("got %d entries, want 2", len(entries))
|
||||
}
|
||||
// example.com has 200 × 429, other.com has 100 × 429
|
||||
if entries[0].Label != "example.com" || entries[0].Count != 200 {
|
||||
t.Errorf("unexpected top: %+v", entries[0])
|
||||
}
|
||||
@@ -96,13 +95,10 @@ func TestQueryTrend(t *testing.T) {
|
||||
s := makeStore()
|
||||
now := time.Now()
|
||||
|
||||
// Rotate 3 buckets with different counts
|
||||
ingestN(s, "x.com", "1.0.0.0/24", "/", "200", 10)
|
||||
s.rotate(now.Add(-2 * time.Minute))
|
||||
|
||||
ingestN(s, "x.com", "1.0.0.0/24", "/", "200", 20)
|
||||
s.rotate(now.Add(-1 * time.Minute))
|
||||
|
||||
ingestN(s, "x.com", "1.0.0.0/24", "/", "200", 30)
|
||||
s.rotate(now)
|
||||
|
||||
@@ -110,7 +106,6 @@ func TestQueryTrend(t *testing.T) {
|
||||
if len(points) != 3 {
|
||||
t.Fatalf("got %d points, want 3", len(points))
|
||||
}
|
||||
// Points are oldest-first; counts should be 10, 20, 30
|
||||
if points[0].Count != 10 || points[1].Count != 20 || points[2].Count != 30 {
|
||||
t.Errorf("unexpected counts: %v", points)
|
||||
}
|
||||
@@ -120,8 +115,7 @@ func TestCoarseRingPopulated(t *testing.T) {
|
||||
s := makeStore()
|
||||
now := time.Now()
|
||||
|
||||
// Rotate coarseEvery fine buckets to trigger one coarse bucket
|
||||
for i := 0; i < coarseEvery; i++ {
|
||||
for i := 0; i < st.CoarseEvery; i++ {
|
||||
ingestN(s, "x.com", "1.0.0.0/24", "/", "200", 10)
|
||||
s.rotate(now.Add(time.Duration(i) * time.Minute))
|
||||
}
|
||||
@@ -131,11 +125,10 @@ func TestCoarseRingPopulated(t *testing.T) {
|
||||
if s.coarseFilled != 1 {
|
||||
t.Fatalf("coarseFilled = %d, want 1", s.coarseFilled)
|
||||
}
|
||||
coarse := s.coarseRing[(s.coarseHead-1+coarseRingSize)%coarseRingSize]
|
||||
coarse := s.coarseRing[(s.coarseHead-1+st.CoarseRingSize)%st.CoarseRingSize]
|
||||
if len(coarse.Entries) == 0 {
|
||||
t.Fatal("coarse snapshot is empty")
|
||||
}
|
||||
// 5 fine buckets × 10 counts = 50
|
||||
if coarse.Entries[0].Count != 50 {
|
||||
t.Errorf("coarse count = %d, want 50", coarse.Entries[0].Count)
|
||||
}
|
||||
@@ -160,13 +153,8 @@ func TestSubscribeBroadcast(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTopKOrdering(t *testing.T) {
|
||||
m := map[string]int64{
|
||||
"a": 5,
|
||||
"b": 100,
|
||||
"c": 1,
|
||||
"d": 50,
|
||||
}
|
||||
entries := topKFromMap(m, 3)
|
||||
m := map[string]int64{"a": 5, "b": 100, "c": 1, "d": 50}
|
||||
entries := st.TopKFromMap(m, 3)
|
||||
if len(entries) != 3 {
|
||||
t.Fatalf("got %d entries, want 3", len(entries))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user