Browse Source

track messages with testStartTime

pull/7329/head
chrislu 4 weeks ago
parent
commit
6c1298b5f7
  1. 16
      test/kafka/kafka-client-loadtest/cmd/loadtest/main.go
  2. 35
      test/kafka/kafka-client-loadtest/internal/tracker/tracker.go

16
test/kafka/kafka-client-loadtest/cmd/loadtest/main.go

@ -144,8 +144,9 @@ func main() {
func runProducerTest(ctx context.Context, cfg *config.Config, collector *metrics.Collector, wg *sync.WaitGroup) error { func runProducerTest(ctx context.Context, cfg *config.Config, collector *metrics.Collector, wg *sync.WaitGroup) error {
log.Printf("Starting producer-only test with %d producers", cfg.Producers.Count) log.Printf("Starting producer-only test with %d producers", cfg.Producers.Count)
// Create record tracker (nil for now as producer-only test doesn't need comparison)
recordTracker := tracker.NewTracker("/test-results/produced.jsonl", "/test-results/consumed.jsonl")
// Create record tracker with current timestamp to filter old messages
testStartTime := time.Now().UnixNano()
recordTracker := tracker.NewTracker("/test-results/produced.jsonl", "/test-results/consumed.jsonl", testStartTime)
errChan := make(chan error, cfg.Producers.Count) errChan := make(chan error, cfg.Producers.Count)
@ -183,8 +184,9 @@ func runProducerTest(ctx context.Context, cfg *config.Config, collector *metrics
func runConsumerTest(ctx context.Context, cfg *config.Config, collector *metrics.Collector, wg *sync.WaitGroup) error { func runConsumerTest(ctx context.Context, cfg *config.Config, collector *metrics.Collector, wg *sync.WaitGroup) error {
log.Printf("Starting consumer-only test with %d consumers", cfg.Consumers.Count) log.Printf("Starting consumer-only test with %d consumers", cfg.Consumers.Count)
// Create record tracker
recordTracker := tracker.NewTracker("/test-results/produced.jsonl", "/test-results/consumed.jsonl")
// Create record tracker with current timestamp to filter old messages
testStartTime := time.Now().UnixNano()
recordTracker := tracker.NewTracker("/test-results/produced.jsonl", "/test-results/consumed.jsonl", testStartTime)
errChan := make(chan error, cfg.Consumers.Count) errChan := make(chan error, cfg.Consumers.Count)
@ -213,8 +215,10 @@ func runComprehensiveTest(ctx context.Context, cancel context.CancelFunc, cfg *c
log.Printf("Starting comprehensive test with %d producers and %d consumers", log.Printf("Starting comprehensive test with %d producers and %d consumers",
cfg.Producers.Count, cfg.Consumers.Count) cfg.Producers.Count, cfg.Consumers.Count)
// Create record tracker
recordTracker := tracker.NewTracker("/test-results/produced.jsonl", "/test-results/consumed.jsonl")
// Create record tracker with current timestamp to filter old messages
testStartTime := time.Now().UnixNano()
log.Printf("Test run starting at %d - only tracking messages from this run", testStartTime)
recordTracker := tracker.NewTracker("/test-results/produced.jsonl", "/test-results/consumed.jsonl", testStartTime)
errChan := make(chan error, cfg.Producers.Count) errChan := make(chan error, cfg.Producers.Count)

35
test/kafka/kafka-client-loadtest/internal/tracker/tracker.go

@ -7,6 +7,7 @@ import (
"sort" "sort"
"strings" "strings"
"sync" "sync"
"time"
) )
// Record represents a tracked message // Record represents a tracked message
@ -27,15 +28,29 @@ type Tracker struct {
consumedRecords []Record consumedRecords []Record
producedFile string producedFile string
consumedFile string consumedFile string
testStartTime int64 // Unix timestamp in nanoseconds - used to filter old messages
testRunPrefix string // Key prefix for this test run (e.g., "run-20251015-170150")
filteredOldCount int // Count of old messages consumed but not tracked
} }
// NewTracker creates a new record tracker // NewTracker creates a new record tracker
func NewTracker(producedFile, consumedFile string) *Tracker {
func NewTracker(producedFile, consumedFile string, testStartTime int64) *Tracker {
// Generate test run prefix from start time using same format as producer
// Producer format: p.startTime.Format("20060102-150405") -> "20251015-170859"
startTime := time.Unix(0, testStartTime)
runID := startTime.Format("20060102-150405")
testRunPrefix := fmt.Sprintf("run-%s", runID)
fmt.Printf("Tracker initialized with prefix: %s (filtering messages not matching this prefix)\n", testRunPrefix)
return &Tracker{ return &Tracker{
producedRecords: make([]Record, 0, 100000), producedRecords: make([]Record, 0, 100000),
consumedRecords: make([]Record, 0, 100000), consumedRecords: make([]Record, 0, 100000),
producedFile: producedFile, producedFile: producedFile,
consumedFile: consumedFile, consumedFile: consumedFile,
testStartTime: testStartTime,
testRunPrefix: testRunPrefix,
filteredOldCount: 0,
} }
} }
@ -47,9 +62,20 @@ func (t *Tracker) TrackProduced(record Record) {
} }
// TrackConsumed records a consumed message // TrackConsumed records a consumed message
// Only tracks messages from the current test run (filters out old messages from previous tests)
func (t *Tracker) TrackConsumed(record Record) { func (t *Tracker) TrackConsumed(record Record) {
t.mu.Lock() t.mu.Lock()
defer t.mu.Unlock() defer t.mu.Unlock()
// Filter: Only track messages from current test run based on key prefix
// Producer keys look like: "run-20251015-170150-key-123"
// We only want messages that match our test run prefix
if !strings.HasPrefix(record.Key, t.testRunPrefix) {
// Count old messages consumed but not tracked
t.filteredOldCount++
return
}
t.consumedRecords = append(t.consumedRecords, record) t.consumedRecords = append(t.consumedRecords, record)
} }
@ -105,6 +131,7 @@ func (t *Tracker) Compare() ComparisonResult {
result := ComparisonResult{ result := ComparisonResult{
TotalProduced: len(t.producedRecords), TotalProduced: len(t.producedRecords),
TotalConsumed: len(t.consumedRecords), TotalConsumed: len(t.consumedRecords),
FilteredOldCount: t.filteredOldCount,
} }
// Build maps for efficient lookup // Build maps for efficient lookup
@ -158,6 +185,7 @@ type ComparisonResult struct {
UniqueConsumed int UniqueConsumed int
MissingCount int MissingCount int
DuplicateCount int DuplicateCount int
FilteredOldCount int // Old messages consumed but filtered out
Missing []Record Missing []Record
Duplicates []DuplicateRecord Duplicates []DuplicateRecord
} }
@ -178,9 +206,12 @@ func (r *ComparisonResult) PrintSummary() {
fmt.Printf(" Total Produced: %d messages\n", r.TotalProduced) fmt.Printf(" Total Produced: %d messages\n", r.TotalProduced)
fmt.Printf("\nConsumption Summary:\n") fmt.Printf("\nConsumption Summary:\n")
fmt.Printf(" Total Consumed: %d messages\n", r.TotalConsumed)
fmt.Printf(" Total Consumed: %d messages (from current test)\n", r.TotalConsumed)
fmt.Printf(" Unique Consumed: %d messages\n", r.UniqueConsumed) fmt.Printf(" Unique Consumed: %d messages\n", r.UniqueConsumed)
fmt.Printf(" Duplicate Reads: %d messages\n", r.TotalConsumed-r.UniqueConsumed) fmt.Printf(" Duplicate Reads: %d messages\n", r.TotalConsumed-r.UniqueConsumed)
if r.FilteredOldCount > 0 {
fmt.Printf(" Filtered Old: %d messages (from previous tests, not tracked)\n", r.FilteredOldCount)
}
fmt.Printf("\nVerification Results:\n") fmt.Printf("\nVerification Results:\n")
if r.MissingCount == 0 { if r.MissingCount == 0 {

Loading…
Cancel
Save