Skip to content

Commit

Permalink
Update interval selection for brevity
Browse files Browse the repository at this point in the history
  • Loading branch information
zalegrala committed Sep 1, 2021
1 parent 9566898 commit 0e781c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 67 deletions.
42 changes: 12 additions & 30 deletions cmd/tempo-vulture/main.go
Expand Up @@ -132,6 +132,11 @@ func main() {
continue
}

// Don't attempt to read future traces.
if seed.After(now) {
continue
}

r := newRand(seed)
hexID := fmt.Sprintf("%016x%016x", r.Int63(), r.Int63())

Expand All @@ -154,40 +159,17 @@ func main() {
}

func selectPastTimestamp(start, stop time.Time, interval time.Duration, retention time.Duration) (newStart, ts time.Time) {
intervals := intervalsBetween(start, stop, interval, retention)
// pick past interval and re-generate trace
pick := generateRandomInt(0, int64(len(intervals)), newRand(intervals[0]))
return intervals[0], intervals[pick]
}
oldest := stop.Add(-retention)

func intervalsBetween(start, stop time.Time, interval time.Duration, retention time.Duration) []time.Time {
if stop.Before(start) {
return nil
if oldest.After(start) {
newStart = oldest
} else {
newStart = start
}

intervals := []time.Time{start}
next := start.Round(interval)

for next.Before(stop) {
if next.After(start) {
intervals = append(intervals, next)
}
next = next.Add(interval)
}

oldest := intervals[len(intervals)-1].Add(-retention)

for i, t := range intervals {
if t.Before(oldest) {
continue
}

if t.After(oldest) {
return intervals[i:]
}
}
ts = time.Unix(generateRandomInt(newStart.Unix(), stop.Unix(), newRand(start)), 0)

return intervals
return newStart.Round(interval), ts.Round(interval)
}

func newJaegerGRPCClient(endpoint string) (*jaeger_grpc.Reporter, error) {
Expand Down
37 changes: 0 additions & 37 deletions cmd/tempo-vulture/main_test.go
Expand Up @@ -206,43 +206,6 @@ func TestGenerateRandomLogs(t *testing.T) {
require.Equal(t, expected, result)
}

func TestIntervalsBetween(t *testing.T) {
nowish := time.Unix(1630010049, 0)

cases := []struct {
start time.Time
stop time.Time
interval time.Duration
retention time.Duration
count int
}{
{
start: nowish.Add(-1 * time.Minute),
stop: nowish,
interval: 11 * time.Second,
retention: 1 * time.Hour,
count: 6,
},
{
start: nowish.Add(-1 * time.Hour),
stop: nowish,
interval: 33 * time.Second,
retention: 1 * time.Hour,
count: 110,
},
}

for _, tc := range cases {
result := intervalsBetween(tc.start, tc.stop, tc.interval, tc.retention)
require.Equal(t, tc.count, len(result))

if tc.count > 0 {
require.Equal(t, tc.start, result[0])
require.True(t, result[len(result)-1].Before(tc.stop))
}
}
}

func TestNewRand(t *testing.T) {
now := time.Now()

Expand Down

0 comments on commit 0e781c1

Please sign in to comment.