Skip to content

Commit 9201117

Browse files
committed
Update test_helpers.go
1 parent 4738aa3 commit 9201117

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

pkg/server/errorshandler/test_helpers.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ func (handler *Handler) GenerateTestTimeSeriesData(projectId string) error {
2929
minuteStart := now.Add(-24 * time.Hour)
3030
for t := minuteStart; t.Before(now); t = t.Add(1 * time.Minute) {
3131
// Hash-based pseudo-random: 0-10 events per minute with realistic peaks/valleys
32-
// Using multiplicative hash (2654435761 is a prime close to 2^32/phi) XOR with constant
33-
// to generate deterministic but pseudo-random event counts based on timestamp
3432
hash := (t.Unix() * 2654435761) ^ 0xdeadbeef
3533
eventsCount := int64((hash % 11))
36-
37-
// Use TSIncrBy to increment counter for this minute
38-
timestamp := t.UnixNano() / int64(time.Millisecond)
39-
if err := handler.RedisClient.TSIncrBy(minutelyKey, eventsCount, timestamp, labels); err != nil {
40-
return fmt.Errorf("failed to add minutely test data: %w", err)
34+
for i := int64(0); i < eventsCount; i++ {
35+
timestamp := t.UnixNano()/int64(time.Millisecond) + i*100
36+
if err := handler.RedisClient.TSAdd(minutelyKey, 1, timestamp, labels); err != nil {
37+
return fmt.Errorf("failed to add minutely test data: %w", err)
38+
}
4139
}
4240
}
4341

@@ -48,10 +46,11 @@ func (handler *Handler) GenerateTestTimeSeriesData(projectId string) error {
4846
// Hash-based pseudo-random: 5-95 events per hour
4947
hash := (t.Unix() * 2654435761) ^ 0xcafebabe
5048
eventsCount := int64(5 + (hash % 90))
51-
52-
timestamp := t.UnixNano() / int64(time.Millisecond)
53-
if err := handler.RedisClient.TSIncrBy(hourlyKey, eventsCount, timestamp, labels); err != nil {
54-
return fmt.Errorf("failed to add hourly test data: %w", err)
49+
for i := int64(0); i < eventsCount; i++ {
50+
timestamp := t.UnixNano()/int64(time.Millisecond) + i*1000
51+
if err := handler.RedisClient.TSAdd(hourlyKey, 1, timestamp, labels); err != nil {
52+
return fmt.Errorf("failed to add hourly test data: %w", err)
53+
}
5554
}
5655
}
5756

@@ -62,10 +61,11 @@ func (handler *Handler) GenerateTestTimeSeriesData(projectId string) error {
6261
// Hash-based pseudo-random: 100-1900 events per day
6362
hash := (t.Unix() * 2654435761) ^ 0xbaadf00d
6463
eventsCount := int64(100 + (hash % 1800))
65-
66-
timestamp := t.UnixNano() / int64(time.Millisecond)
67-
if err := handler.RedisClient.TSIncrBy(dailyKey, eventsCount, timestamp, labels); err != nil {
68-
return fmt.Errorf("failed to add daily test data: %w", err)
64+
for i := int64(0); i < eventsCount; i++ {
65+
timestamp := t.UnixNano()/int64(time.Millisecond) + i*10000
66+
if err := handler.RedisClient.TSAdd(dailyKey, 1, timestamp, labels); err != nil {
67+
return fmt.Errorf("failed to add daily test data: %w", err)
68+
}
6969
}
7070
}
7171

0 commit comments

Comments
 (0)